Adding JUnit tests for the type resolution facility.

This is just a start - more to come


git-svn-id: https://pmd.svn.sourceforge.net/svnroot/pmd/trunk@4873 51baf565-9d33-0410-a72c-fc3788e3496d
This commit is contained in:
Allan Caplan
2006-12-14 01:22:19 +00:00
parent fe18d61b70
commit 6fff435614
3 changed files with 66 additions and 0 deletions

View File

@ -0,0 +1,10 @@
package test.net.sourceforge.pmd.typeresolution;
import java.util.*;
public class ClassWithImportInnerOnDemand {
public void foo(Map m) {
Map.Entry e = (Map.Entry) m.entrySet().iterator().next();
}
}

View File

@ -0,0 +1,10 @@
package test.net.sourceforge.pmd.typeresolution;
import java.util.*;
public class ClassWithImportOnDemand {
public List foo() {
return new ArrayList();
}
}

View File

@ -0,0 +1,46 @@
package test.net.sourceforge.pmd.typeresolution;
import net.sourceforge.pmd.typeresolution.PMDASMClassLoader;
import java.util.Map;
import junit.framework.TestCase;
public class PMDASMClassLoaderTest extends TestCase {
private PMDASMClassLoader cl;
protected void setUp() throws Exception {
cl = new PMDASMClassLoader();
super.setUp();
}
public void testLoadClassWithImportOnDemand() throws Exception {
String className = "test.net.sourceforge.pmd.typeresolution.ClassWithImportOnDemand";
Class clazz = cl.loadClass(className);
assertNotNull(clazz);
Map imports = cl.getImportedClasses(className);
assertNotNull(imports);
assertEquals(4, imports.size());
assertEquals("java.util.List", imports.get("List"));
assertEquals("java.util.ArrayList", imports.get("ArrayList"));
assertEquals("java.lang.Object", imports.get("Object"));
assertEquals("test.net.sourceforge.pmd.typeresolution.ClassWithImportOnDemand", imports.get("ClassWithImportOnDemand"));
}
public void testClassWithImportInnerOnDemand() throws Exception {
String className = "test.net.sourceforge.pmd.typeresolution.ClassWithImportInnerOnDemand";
Class clazz = cl.loadClass(className);
assertNotNull(clazz);
Map imports = cl.getImportedClasses(className);
System.err.println(imports);
assertNotNull(imports);
assertEquals(7, imports.size());
assertEquals("java.util.Iterator", imports.get("Iterator"));
assertEquals("java.util.Map", imports.get("Map"));
assertEquals("java.util.Set", imports.get("Set"));
assertEquals("java.util.Map$Entry", imports.get("Entry"));
assertEquals("java.util.Map$Entry", imports.get("Map$Entry"));
assertEquals("java.lang.Object", imports.get("Object"));
assertEquals("test.net.sourceforge.pmd.typeresolution.ClassWithImportInnerOnDemand", imports.get("ClassWithImportInnerOnDemand"));
}
}