1 32 33 package com.jeantessier.dependency; 34 35 import java.io.*; 36 37 import junit.framework.*; 38 39 public class TestMetricsGatherer extends TestCase { 40 private NodeFactory factory; 41 42 private Node _package; 43 private Node test_class; 44 private Node test_main_method; 45 private Node test_test_method; 46 47 private Node java_lang_package; 48 private Node java_lang_Object_class; 49 private Node java_lang_Object_Object_method; 50 private Node java_lang_String_class; 51 52 private Node java_io_package; 53 private Node java_io_Writer_class; 54 private Node java_io_Writer_write_method; 55 56 private Node java_util_package; 57 private Node java_util_Collections_class; 58 private Node java_util_Collections_singleton_method; 59 private Node java_util_Set_class; 60 61 private MetricsGatherer metrics; 62 63 protected void setUp() throws Exception { 64 factory = new NodeFactory(); 65 66 _package = factory.createPackage(""); 67 test_class = factory.createClass("test"); 68 test_main_method = factory.createFeature("test.main(java.lang.String[])"); 69 test_test_method = factory.createFeature("test.test()"); 70 71 java_lang_package = factory.createPackage("java.lang"); 72 java_lang_Object_class = factory.createClass("java.lang.Object"); 73 java_lang_Object_Object_method = factory.createFeature("java.lang.Object.Object()"); 74 java_lang_String_class = factory.createClass("java.lang.String"); 75 76 java_io_package = factory.createPackage("java.io"); 77 java_io_Writer_class = factory.createClass("java.io.Writer"); 78 java_io_Writer_write_method = factory.createFeature("java.io.Writer.write(int)"); 79 80 java_util_package = factory.createPackage("java.util"); 81 java_util_Collections_class = factory.createClass("java.util.Collections"); 82 java_util_Collections_singleton_method = factory.createFeature("java.util.Collections.singleton(java.lang.Object)"); 83 java_util_Set_class = factory.createClass("java.util.Set"); 84 85 test_class.addDependency(java_lang_Object_class); 86 test_main_method.addDependency(java_lang_Object_class); 87 test_main_method.addDependency(java_lang_Object_Object_method); 88 test_main_method.addDependency(java_lang_String_class); 89 test_main_method.addDependency(java_util_Collections_singleton_method); 90 test_main_method.addDependency(java_util_Set_class); 91 test_test_method.addDependency(java_lang_Object_Object_method); 92 93 metrics = new MetricsGatherer(); 94 } 95 96 public void testEverything() throws IOException { 97 metrics.traverseNodes(factory.getPackages().values()); 98 99 assertEquals("Number of packages", 4, metrics.getPackages().size()); 100 assertEquals("Number of classes", 6, metrics.getClasses().size()); 101 assertEquals("Number of features", 5, metrics.getFeatures().size()); 102 103 assertEquals("Number of inbounds", 7, metrics.getNbInbound()); 104 assertEquals("Number of inbounds to packages", 0, metrics.getNbInboundPackages()); 105 assertEquals("Number of inbounds to classes", 4, metrics.getNbInboundClasses()); 106 assertEquals("Number of inbounds to features", 3, metrics.getNbInboundFeatures()); 107 108 assertEquals("Number of outbounds", 7, metrics.getNbOutbound()); 109 assertEquals("Number of outbounds from packages", 0, metrics.getNbOutboundPackages()); 110 assertEquals("Number of outbounds from classes", 1, metrics.getNbOutboundClasses()); 111 assertEquals("Number of outbounds from features", 6, metrics.getNbOutboundFeatures()); 112 } 113 } 114 | Popular Tags |