1 32 33 package com.jeantessier.dependency; 34 35 import java.io.*; 36 import java.util.*; 37 38 import junit.framework.*; 39 40 import com.jeantessier.classreader.*; 41 42 public class TestCodeDependencyCollector extends TestCase { 43 public static final String TEST_CLASS = "test"; 44 public static final String TEST_FILENAME = "classes" + File.separator + "test.class"; 45 46 private NodeFactory factory; 47 48 protected void setUp() throws Exception { 49 factory = new NodeFactory(); 50 51 ClassfileLoader loader = new AggregatingClassfileLoader(); 52 loader.addLoadListener(new LoadListenerVisitorAdapter(new CodeDependencyCollector(factory))); 53 loader.load(Collections.singleton(TEST_FILENAME)); 54 } 55 56 public void testPackages() { 57 assertEquals("nb packages", 4, factory.getPackages().size()); 58 59 Node node; 60 61 node = (Node) factory.getPackages().get(""); 62 assertNotNull("default package missing", node); 63 assertTrue("default package not concrete", node.isConfirmed()); 64 65 node = (Node) factory.getPackages().get("java.io"); 66 assertNotNull("package java.io missing", node); 67 assertFalse("package java.io is concrete", node.isConfirmed()); 68 69 node = (Node) factory.getPackages().get("java.lang"); 70 assertNotNull("package java.lang missing", node); 71 assertFalse("package java.lang is concrete", node.isConfirmed()); 72 73 node = (Node) factory.getPackages().get("java.util"); 74 assertNotNull("package java.util missing", node); 75 assertFalse("package java.util is concrete", node.isConfirmed()); 76 } 77 78 public void testClasses() { 79 assertEquals("nb classes", 8, factory.getClasses().size()); 80 81 Node node; 82 83 node = (Node) factory.getClasses().get("test"); 84 assertNotNull("class test missing", node); 85 assertTrue("class test not concrete", node.isConfirmed()); 86 87 node = (Node) factory.getClasses().get("java.io.PrintStream"); 88 assertNotNull("class java.io.PrintStream missing", node); 89 assertFalse("class java.io.PrintStream is concrete", node.isConfirmed()); 90 91 node = (Node) factory.getClasses().get("java.lang.NullPointerException"); 92 assertNotNull("class java.lang.NullPointerException missing", node); 93 assertFalse("class java.lang.NullPointerException is concrete", node.isConfirmed()); 94 95 node = (Node) factory.getClasses().get("java.lang.Object"); 96 assertNotNull("class java.lang.Object missing", node); 97 assertFalse("class java.lang.Object is concrete", node.isConfirmed()); 98 99 node = (Node) factory.getClasses().get("java.lang.String"); 100 assertNotNull("class java.lang.String missing", node); 101 assertFalse("class java.lang.String is concrete", node.isConfirmed()); 102 103 node = (Node) factory.getClasses().get("java.lang.System"); 104 assertNotNull("class java.lang.System missing", node); 105 assertFalse("class java.lang.System is concrete", node.isConfirmed()); 106 107 node = (Node) factory.getClasses().get("java.util.Collections"); 108 assertNotNull("class java.util.Collections missing", node); 109 assertFalse("class java.util.Collections is concrete", node.isConfirmed()); 110 111 node = (Node) factory.getClasses().get("java.util.Set"); 112 assertNotNull("class java.util.Set missing", node); 113 assertFalse("class java.util.Set is concrete", node.isConfirmed()); 114 } 115 116 public void testFeatures() { 117 assertEquals("nb features", 6, factory.getFeatures().size()); 118 119 Node node; 120 121 node = (Node) factory.getFeatures().get("test.main(java.lang.String[])"); 122 assertNotNull("feature test.main(java.lang.String[]) missing", node); 123 assertTrue("feature test.main(java.lang.String[]) not concrete", node.isConfirmed()); 124 125 node = (Node) factory.getFeatures().get("test.test()"); 126 assertNotNull("feature test.test() missing", node); 127 assertTrue("feature test.test() not concrete", node.isConfirmed()); 128 129 node = (Node) factory.getFeatures().get("java.io.PrintStream.println(java.lang.Object)"); 130 assertNotNull("feature java.io.PrintStream.println(java.lang.Object) missing", node); 131 assertFalse("feature java.io.PrintStream.println(java.lang.Object) is concrete", node.isConfirmed()); 132 133 node = (Node) factory.getFeatures().get("java.lang.Object.Object()"); 134 assertNotNull("feature java.lang.Object.Object() missing", node); 135 assertFalse("feature java.lang.Object.Object() is concrete", node.isConfirmed()); 136 137 node = (Node) factory.getFeatures().get("java.lang.System.out"); 138 assertNotNull("feature java.lang.System.out missing", node); 139 assertFalse("feature java.lang.System.out is concrete", node.isConfirmed()); 140 141 node = (Node) factory.getFeatures().get("java.util.Collections.singleton(java.lang.Object)"); 142 assertNotNull("feature java.util.Collections.singleton(java.lang.Object) missing", node); 143 assertFalse("feature java.util.Collections.singleton(java.lang.Object) is concrete", node.isConfirmed()); 144 } 145 } 146 | Popular Tags |