KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > kirkk > analyzer > framework > bcelbundle > test > TestJarMetricsImpl


1 package com.kirkk.analyzer.framework.bcelbundle.test;
2
3 import junit.framework.*;
4 import com.kirkk.analyzer.framework.bcel.*;
5 import com.kirkk.analyzer.framework.*;
6 import com.kirkk.analyzer.framework.bcelbundle.*;
7 import java.util.*;
8 import java.math.*;
9
10
11 public class TestJarMetricsImpl extends TestCase {
12
13     private Jar jar;
14     private Jar emptyJar;
15
16     public void setUp() {
17         this.jar = new Jar() {
18             public int getPackageCount() { return 5; }
19             public int getAbstractClassCount() {return 2; }
20             public int getClassCount() { return 10; }
21             //public int getLevel() { return 1; }
22
public String JavaDoc getJarFileName() { return "THIS IS A TEST JAR INNER CLASS IN TestJarMetricsImpl"; }
23
24             public void addPackage(JarPackage jarPackage) { ; }
25             public boolean containsPackage(String JavaDoc packageName) {return false; }
26             public JarPackage getPackage(String JavaDoc packageName) { return null; }
27             public List getAllUnidentifiableExternallyReferencedPackages() { return null; }
28             public List getAllContainedPackages() { return null; }
29             public List getAllExternallyReferencedPackages() { return null; }
30
31
32             public List getOutgoingDependencies() {
33                 ArrayList list = new ArrayList();
34                 list.add("1");
35                 list.add("2");
36                 return list;
37             }
38
39             public List getIncomingDependencies() {
40                 ArrayList list = new ArrayList();
41                 return list;
42             }
43
44             public void addIncomingDependency(Jar jar) { ; }
45             public void addOutgoingDependency(Jar jar) { ; }
46
47             public boolean hasCycles() { return false; }
48             public List getCyclicJars() { return null; }
49             public void addCyclicJar(Jar jar) { ; }
50             public JarMetrics calculateMetrics() { return null; }
51         };
52
53         this.emptyJar = new Jar() {
54             public int getPackageCount() { return 0; }
55             public int getAbstractClassCount() {return 0; }
56             public int getClassCount() { return 0; }
57             //public int getLevel() { return 0; }
58
public String JavaDoc getJarFileName() { return "THIS IS AN EMPTY TEST JAR INNER CLASS IN TestJarMetricsImpl"; }
59
60             public void addPackage(JarPackage jarPackage) { ; }
61             public boolean containsPackage(String JavaDoc packageName) {return false; }
62             public JarPackage getPackage(String JavaDoc packageName) { return null; }
63             public List getAllUnidentifiableExternallyReferencedPackages() { return null; }
64             public List getAllContainedPackages() { return null; }
65             public List getAllExternallyReferencedPackages() { return null; }
66
67
68             public List getOutgoingDependencies() {
69                 ArrayList list = new ArrayList();
70                 return list;
71             }
72
73             public List getIncomingDependencies() {
74                 ArrayList list = new ArrayList();
75                 return list;
76             }
77
78             public void addIncomingDependency(Jar jar) { ; }
79             public void addOutgoingDependency(Jar jar) { ; }
80
81             public boolean hasCycles() { return false; }
82             public List getCyclicJars() { return null; }
83             public void addCyclicJar(Jar jar) { ; }
84             public JarMetrics calculateMetrics() { return null; }
85         };
86     }
87
88     public void testAbstractness() {
89         JarMetrics jarMetrics = new JarMetricsImpl(this.jar);
90         assertEquals("Abstractness should be 0.20", new BigDecimal("0.20"), jarMetrics.calculateAbstractness());
91     }
92
93     //Incoming
94
public void testInstability() throws Exception JavaDoc {
95         JarMetrics jarMetrics = new JarMetricsImpl(this.jar);
96         assertEquals("Instability should be 1", new BigDecimal("1.00"), jarMetrics.calculateInstability());
97     }
98
99     public void testEfferent() {
100         JarMetrics jarMetrics = new JarMetricsImpl(this.jar);
101         assertEquals("Efferent coupling should be 2", 2, jarMetrics.calculateEfferentCoupling());
102
103     }
104
105     public void testAfferent() {
106         JarMetrics jarMetrics = new JarMetricsImpl(this.jar);
107         assertEquals("Afferent coupling should be 0", 0, jarMetrics.calculateAfferentCoupling());
108     }
109
110     public void testDistance() {
111         JarMetrics jarMetrics = new JarMetricsImpl(this.jar);
112         assertEquals("Distance from main sequence should be 0.20", new BigDecimal("0.20"), jarMetrics.calculateDistance());
113     }
114
115     public void testAllZeros() {
116         JarMetrics jarMetrics = new JarMetricsImpl(this.emptyJar);
117         assertEquals("Efferent coupling should be 0", 0, jarMetrics.calculateEfferentCoupling());
118         assertEquals("Afferent coupling should be 0", 0, jarMetrics.calculateAfferentCoupling());
119         assertEquals("Abstractness should be -1 (undefined)", new BigDecimal("-1.0"), jarMetrics.calculateAbstractness());
120         assertEquals("Instability should be -1.0 (undefined)", new BigDecimal("-1.0"), jarMetrics.calculateInstability());
121         assertEquals("Distance should be -1.0 (undefined)", new BigDecimal("-1.0"), jarMetrics.calculateDistance());
122
123     }
124
125 }
Popular Tags