001: package com.kirkk.analyzer.framework.bcelbundle.test;
002:
003: import junit.framework.*;
004: import com.kirkk.analyzer.framework.bcel.*;
005: import com.kirkk.analyzer.framework.*;
006: import com.kirkk.analyzer.framework.bcelbundle.*;
007: import java.util.*;
008: import java.math.*;
009:
010: public class TestJarMetricsImpl extends TestCase {
011:
012: private Jar jar;
013: private Jar emptyJar;
014:
015: public void setUp() {
016: this .jar = new Jar() {
017: public int getPackageCount() {
018: return 5;
019: }
020:
021: public int getAbstractClassCount() {
022: return 2;
023: }
024:
025: public int getClassCount() {
026: return 10;
027: }
028:
029: //public int getLevel() { return 1; }
030: public String getJarFileName() {
031: return "THIS IS A TEST JAR INNER CLASS IN TestJarMetricsImpl";
032: }
033:
034: public void addPackage(JarPackage jarPackage) {
035: ;
036: }
037:
038: public boolean containsPackage(String packageName) {
039: return false;
040: }
041:
042: public JarPackage getPackage(String packageName) {
043: return null;
044: }
045:
046: public List getAllUnidentifiableExternallyReferencedPackages() {
047: return null;
048: }
049:
050: public List getAllContainedPackages() {
051: return null;
052: }
053:
054: public List getAllExternallyReferencedPackages() {
055: return null;
056: }
057:
058: public List getOutgoingDependencies() {
059: ArrayList list = new ArrayList();
060: list.add("1");
061: list.add("2");
062: return list;
063: }
064:
065: public List getIncomingDependencies() {
066: ArrayList list = new ArrayList();
067: return list;
068: }
069:
070: public void addIncomingDependency(Jar jar) {
071: ;
072: }
073:
074: public void addOutgoingDependency(Jar jar) {
075: ;
076: }
077:
078: public boolean hasCycles() {
079: return false;
080: }
081:
082: public List getCyclicJars() {
083: return null;
084: }
085:
086: public void addCyclicJar(Jar jar) {
087: ;
088: }
089:
090: public JarMetrics calculateMetrics() {
091: return null;
092: }
093: };
094:
095: this .emptyJar = new Jar() {
096: public int getPackageCount() {
097: return 0;
098: }
099:
100: public int getAbstractClassCount() {
101: return 0;
102: }
103:
104: public int getClassCount() {
105: return 0;
106: }
107:
108: //public int getLevel() { return 0; }
109: public String getJarFileName() {
110: return "THIS IS AN EMPTY TEST JAR INNER CLASS IN TestJarMetricsImpl";
111: }
112:
113: public void addPackage(JarPackage jarPackage) {
114: ;
115: }
116:
117: public boolean containsPackage(String packageName) {
118: return false;
119: }
120:
121: public JarPackage getPackage(String packageName) {
122: return null;
123: }
124:
125: public List getAllUnidentifiableExternallyReferencedPackages() {
126: return null;
127: }
128:
129: public List getAllContainedPackages() {
130: return null;
131: }
132:
133: public List getAllExternallyReferencedPackages() {
134: return null;
135: }
136:
137: public List getOutgoingDependencies() {
138: ArrayList list = new ArrayList();
139: return list;
140: }
141:
142: public List getIncomingDependencies() {
143: ArrayList list = new ArrayList();
144: return list;
145: }
146:
147: public void addIncomingDependency(Jar jar) {
148: ;
149: }
150:
151: public void addOutgoingDependency(Jar jar) {
152: ;
153: }
154:
155: public boolean hasCycles() {
156: return false;
157: }
158:
159: public List getCyclicJars() {
160: return null;
161: }
162:
163: public void addCyclicJar(Jar jar) {
164: ;
165: }
166:
167: public JarMetrics calculateMetrics() {
168: return null;
169: }
170: };
171: }
172:
173: public void testAbstractness() {
174: JarMetrics jarMetrics = new JarMetricsImpl(this .jar);
175: assertEquals("Abstractness should be 0.20", new BigDecimal(
176: "0.20"), jarMetrics.calculateAbstractness());
177: }
178:
179: //Incoming
180: public void testInstability() throws Exception {
181: JarMetrics jarMetrics = new JarMetricsImpl(this .jar);
182: assertEquals("Instability should be 1", new BigDecimal("1.00"),
183: jarMetrics.calculateInstability());
184: }
185:
186: public void testEfferent() {
187: JarMetrics jarMetrics = new JarMetricsImpl(this .jar);
188: assertEquals("Efferent coupling should be 2", 2, jarMetrics
189: .calculateEfferentCoupling());
190:
191: }
192:
193: public void testAfferent() {
194: JarMetrics jarMetrics = new JarMetricsImpl(this .jar);
195: assertEquals("Afferent coupling should be 0", 0, jarMetrics
196: .calculateAfferentCoupling());
197: }
198:
199: public void testDistance() {
200: JarMetrics jarMetrics = new JarMetricsImpl(this .jar);
201: assertEquals("Distance from main sequence should be 0.20",
202: new BigDecimal("0.20"), jarMetrics.calculateDistance());
203: }
204:
205: public void testAllZeros() {
206: JarMetrics jarMetrics = new JarMetricsImpl(this .emptyJar);
207: assertEquals("Efferent coupling should be 0", 0, jarMetrics
208: .calculateEfferentCoupling());
209: assertEquals("Afferent coupling should be 0", 0, jarMetrics
210: .calculateAfferentCoupling());
211: assertEquals("Abstractness should be -1 (undefined)",
212: new BigDecimal("-1.0"), jarMetrics
213: .calculateAbstractness());
214: assertEquals("Instability should be -1.0 (undefined)",
215: new BigDecimal("-1.0"), jarMetrics
216: .calculateInstability());
217: assertEquals("Distance should be -1.0 (undefined)",
218: new BigDecimal("-1.0"), jarMetrics.calculateDistance());
219:
220: }
221:
222: }
|