001: package jdepend.framework;
002:
003: import java.io.IOException;
004: import java.text.NumberFormat;
005: import java.util.Collection;
006:
007: /**
008: * @author <b>Mike Clark</b>
009: * @author Clarkware Consulting, Inc.
010: */
011:
012: public class ComponentTest extends JDependTestCase {
013:
014: private JDepend jdepend;
015: private static NumberFormat formatter;
016:
017: static {
018: formatter = NumberFormat.getInstance();
019: formatter.setMaximumFractionDigits(2);
020: }
021:
022: public ComponentTest(String name) {
023: super (name);
024: }
025:
026: protected void setUp() {
027: super .setUp();
028: jdepend = new JDepend();
029: jdepend.analyzeInnerClasses(false);
030: }
031:
032: protected void tearDown() {
033: super .tearDown();
034: }
035:
036: public void testJDependComponents() throws IOException {
037:
038: jdepend.setComponents("jdepend,junit,java,javax");
039:
040: jdepend.addDirectory(getBuildDir());
041:
042: jdepend.analyze();
043:
044: Collection packages = jdepend.getPackages();
045: assertEquals(4, packages.size());
046:
047: assertJDependPackage();
048: assertJUnitPackage();
049: assertJavaPackage();
050: assertJavaxPackage();
051: }
052:
053: private void assertJDependPackage() {
054: JavaPackage p = jdepend.getPackage("jdepend");
055: assertEquals("jdepend", p.getName());
056: assertEquals(34, p.getConcreteClassCount());
057: assertEquals(5, p.getAbstractClassCount());
058: assertEquals(0, p.afferentCoupling());
059: assertEquals(3, p.efferentCoupling());
060: assertEquals(format(0.13f), format(p.abstractness()));
061: assertEquals("1", format(p.instability()));
062: assertEquals(format(0.13f), format(p.distance()));
063: assertEquals(1, p.getVolatility());
064:
065: Collection efferents = p.getEfferents();
066: assertEquals(3, efferents.size());
067: assertTrue(efferents.contains(new JavaPackage("java")));
068: assertTrue(efferents.contains(new JavaPackage("javax")));
069: assertTrue(efferents.contains(new JavaPackage("junit")));
070:
071: Collection afferents = p.getAfferents();
072: assertEquals(0, afferents.size());
073: }
074:
075: private void assertJUnitPackage() {
076: JavaPackage p = jdepend.getPackage("junit");
077: assertEquals("junit", p.getName());
078:
079: Collection afferents = p.getAfferents();
080: assertEquals(1, afferents.size());
081: assertTrue(afferents.contains(new JavaPackage("jdepend")));
082:
083: Collection efferents = p.getEfferents();
084: assertEquals(0, efferents.size());
085: }
086:
087: private void assertJavaPackage() {
088: JavaPackage p = jdepend.getPackage("java");
089: assertEquals("java", p.getName());
090:
091: Collection afferents = p.getAfferents();
092: assertEquals(1, afferents.size());
093: assertTrue(afferents.contains(new JavaPackage("jdepend")));
094:
095: Collection efferents = p.getEfferents();
096: assertEquals(0, efferents.size());
097: }
098:
099: private void assertJavaxPackage() {
100: JavaPackage p = jdepend.getPackage("javax");
101: assertEquals("javax", p.getName());
102:
103: Collection afferents = p.getAfferents();
104: assertEquals(1, afferents.size());
105: assertTrue(afferents.contains(new JavaPackage("jdepend")));
106:
107: Collection efferents = p.getEfferents();
108: assertEquals(0, efferents.size());
109: }
110:
111: private String format(float f) {
112: return formatter.format(f);
113: }
114: }
|