1 32 33 package com.jeantessier.dependency; 34 35 import java.util.*; 36 37 import junit.framework.*; 38 39 public class TestCollectionSelectionCriteria extends TestCase { 40 private Collection include; 41 private Collection exclude; 42 private CollectionSelectionCriteria criteria; 43 44 private PackageNode a; 45 private ClassNode a_A; 46 private FeatureNode a_A_a; 47 48 private PackageNode b; 49 private ClassNode b_B; 50 private FeatureNode b_B_b; 51 52 protected void setUp() throws Exception { 53 include = new HashSet(); 54 exclude = new HashSet(); 55 criteria = new CollectionSelectionCriteria(include, exclude); 56 57 NodeFactory factory = new NodeFactory(); 58 59 a = factory.createPackage("a"); 60 a_A = factory.createClass("a.A"); 61 a_A_a = factory.createFeature("a.A.a"); 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 testEmptyInclude() { 69 assertFalse("a", criteria.matches(a)); 70 assertFalse("a.A", criteria.matches(a_A)); 71 assertFalse("a.A.a", criteria.matches(a_A_a)); 72 73 assertFalse("b", criteria.matches(b)); 74 assertFalse("b.B", criteria.matches(b_B)); 75 assertFalse("b.B.b", criteria.matches(b_B_b)); 76 } 77 78 public void testNullInclude() { 79 criteria = new CollectionSelectionCriteria(null, exclude); 80 81 assertTrue("a", criteria.matches(a)); 82 assertTrue("a.A", criteria.matches(a_A)); 83 assertTrue("a.A.a", criteria.matches(a_A_a)); 84 85 assertTrue("b", criteria.matches(b)); 86 assertTrue("b.B", criteria.matches(b_B)); 87 assertTrue("b.B.b", criteria.matches(b_B_b)); 88 } 89 90 public void testMatchPackageNode() { 91 include.add("a"); 92 93 assertTrue("a", criteria.matches(a)); 94 assertFalse("a.A", criteria.matches(a_A)); 95 assertFalse("a.A.a", criteria.matches(a_A_a)); 96 97 assertFalse("b", criteria.matches(b)); 98 assertFalse("b.B", criteria.matches(b_B)); 99 assertFalse("b.B.b", criteria.matches(b_B_b)); 100 } 101 102 public void testMatchClassNode() { 103 include.add("a.A"); 104 105 assertFalse("a", criteria.matches(a)); 106 assertTrue("a.A", criteria.matches(a_A)); 107 assertFalse("a.A.a", criteria.matches(a_A_a)); 108 109 assertFalse("b", criteria.matches(b)); 110 assertFalse("b.B", criteria.matches(b_B)); 111 assertFalse("b.B.b", criteria.matches(b_B_b)); 112 } 113 114 public void testMatchFeatureNode() { 115 include.add("a.A.a"); 116 117 assertFalse("a", criteria.matches(a)); 118 assertFalse("a.A", criteria.matches(a_A)); 119 assertTrue("a.A.a", criteria.matches(a_A_a)); 120 121 assertFalse("b", criteria.matches(b)); 122 assertFalse("b.B", criteria.matches(b_B)); 123 assertFalse("b.B.b", criteria.matches(b_B_b)); 124 } 125 126 public void testMatchPackageName() { 127 include.add("a"); 128 129 assertTrue("a", criteria.matchesPackageName("a")); 130 assertFalse("a.A", criteria.matchesClassName("a.A")); 131 assertFalse("a.A.a", criteria.matchesFeatureName("a.A.a")); 132 133 assertFalse("b", criteria.matchesPackageName("b")); 134 assertFalse("b.B", criteria.matchesClassName("b.B")); 135 assertFalse("b.B.b", criteria.matchesFeatureName("b.B.b")); 136 } 137 138 public void testMatchClassName() { 139 include.add("a.A"); 140 141 assertFalse("a", criteria.matchesPackageName("a")); 142 assertTrue("a.A", criteria.matchesClassName("a.A")); 143 assertFalse("a.A.a", criteria.matchesFeatureName("a.A.a")); 144 145 assertFalse("b", criteria.matchesPackageName("b")); 146 assertFalse("b.B", criteria.matchesClassName("b.B")); 147 assertFalse("b.B.b", criteria.matchesFeatureName("b.B.b")); 148 } 149 150 public void testMatchFeatureName() { 151 include.add("a.A.a"); 152 153 assertFalse("a", criteria.matchesPackageName("a")); 154 assertFalse("a.A", criteria.matchesClassName("a.A")); 155 assertTrue("a.A.a", criteria.matchesFeatureName("a.A.a")); 156 157 assertFalse("b", criteria.matchesPackageName("b")); 158 assertFalse("b.B", criteria.matchesClassName("b.B")); 159 assertFalse("b.B.b", criteria.matchesFeatureName("b.B.b")); 160 } 161 162 public void testExclude() { 163 include.add("a"); 164 include.add("a.A"); 165 include.add("a.A.a"); 166 exclude.add("a.A.a"); 167 168 assertTrue("a", criteria.matches(a)); 169 assertTrue("a.A", criteria.matches(a_A)); 170 assertFalse("a.A.a", criteria.matches(a_A_a)); 171 } 172 173 public void testExcludeOnly() { 174 exclude.add("a.A.a"); 175 176 criteria = new CollectionSelectionCriteria(null, exclude); 177 178 assertTrue("a", criteria.matches(a)); 179 assertTrue("a.A", criteria.matches(a_A)); 180 assertFalse("a.A.a", criteria.matches(a_A_a)); 181 } 182 } 183 | Popular Tags |