1 32 33 package com.jeantessier.dependency; 34 35 import java.util.*; 36 37 import junit.framework.*; 38 39 public class TestNode extends TestCase { 40 Node a; 41 Node a_A; 42 Node a_A_a; 43 Node a_A_b; 44 Node a_B; 45 Node a_B_a; 46 Node a_B_b; 47 48 Node b; 49 Node b_B; 50 Node b_B_b; 51 52 protected void setUp() throws Exception { 53 NodeFactory factory = new NodeFactory(); 54 55 a = factory.createPackage("a"); 56 a_A = factory.createClass("a.A"); 57 a_A_a = factory.createFeature("a.A.a"); 58 a_A_b = factory.createFeature("a.A.b"); 59 a_B = factory.createClass("a.B"); 60 a_B_a = factory.createFeature("a.B.a"); 61 a_B_b = factory.createFeature("a.B.b"); 62 63 b = factory.createPackage("b"); 64 b_B = factory.createClass("b.B"); 65 b_B_b = factory.createFeature("b.B.b"); 66 } 67 68 public void testPackageCanAddDependency() { 69 assertFalse(a.canAddDependencyTo(a)); 70 assertTrue(a.canAddDependencyTo(a_A)); 71 assertTrue(a.canAddDependencyTo(a_A_a)); 72 assertTrue(a.canAddDependencyTo(a_A_b)); 73 assertTrue(a.canAddDependencyTo(a_B)); 74 assertTrue(a.canAddDependencyTo(a_B_a)); 75 assertTrue(a.canAddDependencyTo(a_B_b)); 76 77 assertTrue(a.canAddDependencyTo(b)); 78 assertTrue(a.canAddDependencyTo(b_B)); 79 assertTrue(a.canAddDependencyTo(b_B_b)); 80 } 81 82 public void testClassCanAddDependency() { 83 assertFalse(a_A.canAddDependencyTo(a)); 84 assertFalse(a_A.canAddDependencyTo(a_A)); 85 assertTrue(a_A.canAddDependencyTo(a_A_a)); 86 assertTrue(a_A.canAddDependencyTo(a_A_b)); 87 assertTrue(a_A.canAddDependencyTo(a_B)); 88 assertTrue(a_A.canAddDependencyTo(a_B_a)); 89 assertTrue(a_A.canAddDependencyTo(a_B_b)); 90 91 assertTrue(a_A.canAddDependencyTo(b)); 92 assertTrue(a_A.canAddDependencyTo(b_B)); 93 assertTrue(a_A.canAddDependencyTo(b_B_b)); 94 } 95 96 public void testFeatureCanAddDependency() { 97 assertFalse(a_A_a.canAddDependencyTo(a)); 98 assertFalse(a_A_a.canAddDependencyTo(a_A)); 99 assertFalse(a_A_a.canAddDependencyTo(a_A_a)); 100 assertTrue(a_A_a.canAddDependencyTo(a_A_b)); 101 assertTrue(a_A_a.canAddDependencyTo(a_B)); 102 assertTrue(a_A_a.canAddDependencyTo(a_B_a)); 103 assertTrue(a_A_a.canAddDependencyTo(a_B_b)); 104 105 assertTrue(a_A_a.canAddDependencyTo(b)); 106 assertTrue(a_A_a.canAddDependencyTo(b_B)); 107 assertTrue(a_A_a.canAddDependencyTo(b_B_b)); 108 } 109 110 public void testRemoveOneDependency() { 111 a_A_a.addDependency(b_B_b); 112 assertTrue("Missing a.A.a --> b.B.b", a_A_a.getOutboundDependencies().contains(b_B_b)); 113 assertTrue("Missing b.B.b <-- a.A.a", b_B_b.getInboundDependencies().contains(a_A_a)); 114 115 a_A_a.removeDependency(b_B_b); 116 assertFalse("Did not remove a.A.a --> b.B.b", a_A_a.getOutboundDependencies().contains(b_B_b)); 117 assertFalse("Did not remove b.B.b <-- a.A.a", b_B_b.getInboundDependencies().contains(a_A_a)); 118 } 119 120 public void testRemoveOneDependencyButNotAnother() { 121 a_A_a.addDependency(a_A_b); 122 assertTrue("Missing a.A.a --> a.A.b", a_A_a.getOutboundDependencies().contains(a_A_b)); 123 assertTrue("Missing a.A.b <-- a.A.a", a_A_b.getInboundDependencies().contains(a_A_a)); 124 125 a_A_a.addDependency(b_B_b); 126 assertTrue("Missing a.A.a --> b.B.b", a_A_a.getOutboundDependencies().contains(b_B_b)); 127 assertTrue("Missing b.B.b <-- a.A.a", b_B_b.getInboundDependencies().contains(a_A_a)); 128 129 a_A_a.removeDependency(b_B_b); 130 assertTrue("Missing a.A.a --> a.A.b", a_A_a.getOutboundDependencies().contains(a_A_b)); 131 assertTrue("Missing a.A.b <-- a.A.a", a_A_b.getInboundDependencies().contains(a_A_a)); 132 assertFalse("Did not remove a.A.a --> b.B.b", a_A_a.getOutboundDependencies().contains(b_B_b)); 133 assertFalse("Did not remove b.B.b <-- a.A.a", b_B_b.getInboundDependencies().contains(a_A_a)); 134 } 135 136 public void testRemoveDependencies() { 137 a_A_a.addDependency(a_A_b); 138 a_A_a.addDependency(b_B_b); 139 assertTrue("Missing a.A.a --> a.A.b", a_A_a.getOutboundDependencies().contains(a_A_b)); 140 assertTrue("Missing a.A.b <-- a.A.a", a_A_b.getInboundDependencies().contains(a_A_a)); 141 assertTrue("Missing a.A.a --> b.B.b", a_A_a.getOutboundDependencies().contains(b_B_b)); 142 assertTrue("Missing b.B.b <-- a.A.a", b_B_b.getInboundDependencies().contains(a_A_a)); 143 144 Collection dependencies = new ArrayList(2); 145 dependencies.add(a_A_b); 146 dependencies.add(b_B_b); 147 148 a_A_a.removeDependencies(dependencies); 149 assertFalse("Did not remove a.A.a --> a.A.b", a_A_a.getOutboundDependencies().contains(a_A_b)); 150 assertFalse("Did not remove a.A.b <-- a.A.a", a_A_b.getInboundDependencies().contains(a_A_a)); 151 assertFalse("Did not remove a.A.a --> b.B.b", a_A_a.getOutboundDependencies().contains(b_B_b)); 152 assertFalse("Did not remove b.B.b <-- a.A.a", b_B_b.getInboundDependencies().contains(a_A_a)); 153 } 154 } 155 | Popular Tags |