View Javadoc
1 package test.net.sourceforge.pmd.symboltable; 2 3 import junit.framework.TestCase; 4 import net.sourceforge.pmd.ast.ASTBlock; 5 import net.sourceforge.pmd.ast.ASTClassBody; 6 import net.sourceforge.pmd.ast.ASTCompilationUnit; 7 import net.sourceforge.pmd.ast.ASTConstructorDeclaration; 8 import net.sourceforge.pmd.ast.ASTForStatement; 9 import net.sourceforge.pmd.ast.ASTIfStatement; 10 import net.sourceforge.pmd.ast.ASTMethodDeclaration; 11 import net.sourceforge.pmd.ast.ASTTryStatement; 12 import net.sourceforge.pmd.ast.ASTUnmodifiedClassDeclaration; 13 import net.sourceforge.pmd.ast.ASTUnmodifiedInterfaceDeclaration; 14 import net.sourceforge.pmd.symboltable.ClassScope; 15 import net.sourceforge.pmd.symboltable.GlobalScope; 16 import net.sourceforge.pmd.symboltable.LocalScope; 17 import net.sourceforge.pmd.symboltable.MethodScope; 18 import net.sourceforge.pmd.symboltable.ScopeFactory; 19 20 public class ScopeFactoryTest extends TestCase { 21 22 public void testGlobalScope() { 23 ScopeFactory sf = new ScopeFactory(); 24 assertTrue(sf.createScope(new ASTCompilationUnit(1)) instanceof GlobalScope); 25 } 26 27 public void testClassScope() { 28 ScopeFactory sf = new ScopeFactory(); 29 assertTrue(sf.createScope(new ASTUnmodifiedClassDeclaration(1)) instanceof ClassScope); 30 assertTrue(sf.createScope(new ASTUnmodifiedInterfaceDeclaration(1)) instanceof ClassScope); 31 } 32 33 public void testfunctionScope() { 34 ScopeFactory sf = new ScopeFactory(); 35 assertTrue(sf.createScope(new ASTMethodDeclaration(1)) instanceof MethodScope); 36 assertTrue(sf.createScope(new ASTConstructorDeclaration(1)) instanceof MethodScope); 37 } 38 39 public void testLocalScope() { 40 ScopeFactory sf = new ScopeFactory(); 41 assertTrue(sf.createScope(new ASTBlock(1)) instanceof LocalScope); 42 assertTrue(sf.createScope(new ASTTryStatement(1)) instanceof LocalScope); 43 assertTrue(sf.createScope(new ASTForStatement(1)) instanceof LocalScope); 44 assertTrue(sf.createScope(new ASTIfStatement(1)) instanceof LocalScope); 45 } 46 47 public void testUnknownScope_ThisShouldNeverHappen() throws Throwable { 48 ScopeFactory sf = new ScopeFactory(); 49 try { 50 sf.createScope(new ASTClassBody(1)); 51 throw new Throwable("Should have failed!"); 52 } catch (RuntimeException re) { 53 // cool 54 } 55 } 56 }

This page was automatically generated by Maven