KickJava   Java API By Example, From Geeks To Geeks.

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


1 package com.kirkk.analyzer.framework.bcelbundle.test;
2
3 import junit.framework.*;
4 import java.io.*;
5 import com.kirkk.analyzer.framework.bcelbundle.*;
6 import com.kirkk.analyzer.framework.*;
7 import com.kirkk.analyzer.framework.JarCollection;
8 import java.util.*;
9
10 public class TestJarRelationshipDecorator extends TestCase {
11     public void testOutgoingJarRelationships() throws Exception JavaDoc {
12         JarCollection jarCollection = new JarRelationshipDecorator(new JarCollectionImpl(new File("testdata/acyclictestproject/dist"), new ArrayList()));
13         assertEquals(jarCollection.getJarCount(),2);
14         jarCollection.first();
15
16         Jar jar1 = jarCollection.getJar("Test1.jar");
17         Jar jar2 = jarCollection.getJar("Test2.jar");
18         assertNotNull("Jar1 is null", jar1);
19         assertNotNull("Jar2 is null", jar2);
20
21         List jar2OutgoingDependencies = jar2.getOutgoingDependencies();
22         List jar1OutgoingDependencis = jar1.getOutgoingDependencies();
23         assertTrue("jar2 should be dependent on jar1", jar2OutgoingDependencies.contains(jar1));
24         assertTrue("jar1 should not be dependent on jar2", !jar1OutgoingDependencis.contains(jar2));
25
26     }
27
28     public void testIncomingJarRelationships() throws Exception JavaDoc {
29         JarCollection jarCollection = new JarRelationshipDecorator(new JarCollectionImpl(new File("testdata/acyclictestproject/dist"), new ArrayList()));
30         assertEquals(jarCollection.getJarCount(),2);
31         jarCollection.first();
32
33         Jar jar1 = jarCollection.getJar("Test1.jar");
34         Jar jar2 = jarCollection.getJar("Test2.jar");
35         assertNotNull("Jar1 is null", jar1);
36         assertNotNull("Jar2 is null", jar2);
37
38         List jar2IncomingDependencies = jar2.getIncomingDependencies();
39         List jar1IncomingDependencis = jar1.getIncomingDependencies();
40         assertTrue("jar2 should not have any incoming dependncies", !jar2IncomingDependencies.contains(jar1));
41         assertTrue("jar1 should have jar2 as an incoming dependency", jar1IncomingDependencis.contains(jar2));
42
43     }
44
45     public void testCylicJars() throws Exception JavaDoc {
46         JarCollection jarCollection = new JarRelationshipDecorator(new JarCollectionImpl(new File("testdata/cyclictestproject/dist"), new ArrayList()));
47         assertEquals(jarCollection.getJarCount(),2);
48         jarCollection.first();
49
50         Jar jar1 = jarCollection.getJar("Test1.jar");
51         Jar jar2 = jarCollection.getJar("Test2.jar");
52         assertNotNull("Jar1 is null", jar1);
53         assertNotNull("Jar2 is null", jar2);
54
55         assertTrue("Jar1 should have a cycle", jar1.hasCycles());
56         assertTrue("Jar2 should have a cycle", jar2.hasCycles());
57
58         List jar1Cycles = jar1.getCyclicJars();
59         assertTrue("Jar1 should have a cycle with Jar2", jar1Cycles.contains(jar2));
60
61         List jar2Cycles = jar2.getCyclicJars();
62         assertTrue("Jar2 should have a cycle with Jar1", jar2Cycles.contains(jar1));
63     }
64
65     public void testDecoratorToArray() throws Exception JavaDoc {
66         JarCollection jarCollection = new JarRelationshipDecorator(new JarCollectionImpl(new File("testdata/acyclictestproject/dist")));
67         Jar[] jar = jarCollection.toArray();
68         assertEquals("Array size should be 2", 2, jar.length);
69
70         assertTrue( (jar[0].getJarFileName().equals("Test1.jar")) || (jar[0].getJarFileName().equals("Test2.jar")));
71     }
72
73     /*public void testDupPackageSpanningJars() throws Exception {
74         JarCollection jarCollection = new JarRelationshipDecorator(new JarCollectionImpl(new File("testdata/samepackagespansjars/dist")));
75
76         Jar jar1 = jarCollection.getJar("Test1.jar");
77         Jar jar2 = jarCollection.getJar("Test2.jar");
78
79         System.out.println(jar1.hasCycles());
80         System.out.println(jar2.hasCycles());
81     }*/

82 }
Popular Tags