1 32 33 package com.jeantessier.dependency; 34 35 import java.util.*; 36 37 import junit.framework.*; 38 39 public class TestOrCompositeSelectionCriteria extends TestCase { 40 private PackageNode a; 41 private ClassNode a_A; 42 private FeatureNode a_A_a; 43 44 private Collection subcriteria; 45 private OrCompositeSelectionCriteria criteria; 46 47 protected void setUp() throws Exception { 48 NodeFactory factory = new NodeFactory(); 49 50 a = factory.createPackage("a"); 51 a_A = factory.createClass("a.A"); 52 a_A_a = factory.createFeature("a.A.a"); 53 54 subcriteria = new ArrayList(); 55 criteria = new OrCompositeSelectionCriteria(subcriteria); 56 } 57 58 public void testMatchWithEmptyList() { 59 assertEquals("a", true, criteria.matches(a)); 60 assertEquals("a.A", true, criteria.matches(a_A)); 61 assertEquals("a.A.a", true, criteria.matches(a_A_a)); 62 } 63 64 public void testMatchWithOneFalseSubcriteria() { 65 MockSelectionCriteria mock = new MockSelectionCriteria(); 66 mock.setValue(false); 67 subcriteria.add(mock); 68 69 assertEquals("a", mock.getValue(), criteria.matches(a)); 70 assertEquals("a.A", mock.getValue(), criteria.matches(a_A)); 71 assertEquals("a.A.a", mock.getValue(), criteria.matches(a_A_a)); 72 } 73 74 public void testMatchWithOneTrueSubcriteria() { 75 MockSelectionCriteria mock = new MockSelectionCriteria(); 76 mock.setValue(true); 77 subcriteria.add(mock); 78 79 assertEquals("a", mock.getValue(), criteria.matches(a)); 80 assertEquals("a.A", mock.getValue(), criteria.matches(a_A)); 81 assertEquals("a.A.a", mock.getValue(), criteria.matches(a_A_a)); 82 } 83 84 public void testMatchWithTwoSubcriteriaFalseFalse() { 85 MockSelectionCriteria mock1 = new MockSelectionCriteria(); 86 mock1.setValue(false); 87 subcriteria.add(mock1); 88 89 MockSelectionCriteria mock2 = new MockSelectionCriteria(); 90 mock2.setValue(false); 91 subcriteria.add(mock2); 92 93 assertEquals("a", mock1.getValue() || mock2.getValue(), criteria.matches(a)); 94 assertEquals("a.A", mock1.getValue() || mock2.getValue(), criteria.matches(a_A)); 95 assertEquals("a.A.a", mock1.getValue() || mock2.getValue(), criteria.matches(a_A_a)); 96 } 97 98 public void testMatchWithTwoSubcriteriaFalseTrue() { 99 MockSelectionCriteria mock1 = new MockSelectionCriteria(); 100 mock1.setValue(false); 101 subcriteria.add(mock1); 102 103 MockSelectionCriteria mock2 = new MockSelectionCriteria(); 104 mock2.setValue(true); 105 subcriteria.add(mock2); 106 107 assertEquals("a", mock1.getValue() || mock2.getValue(), criteria.matches(a)); 108 assertEquals("a.A", mock1.getValue() || mock2.getValue(), criteria.matches(a_A)); 109 assertEquals("a.A.a", mock1.getValue() || mock2.getValue(), criteria.matches(a_A_a)); 110 } 111 112 public void testMatchWithTwoSubcriteriaTrueFalse() { 113 MockSelectionCriteria mock1 = new MockSelectionCriteria(); 114 mock1.setValue(true); 115 subcriteria.add(mock1); 116 117 MockSelectionCriteria mock2 = new MockSelectionCriteria(); 118 mock2.setValue(false); 119 subcriteria.add(mock2); 120 121 assertEquals("a", mock1.getValue() || mock2.getValue(), criteria.matches(a)); 122 assertEquals("a.A", mock1.getValue() || mock2.getValue(), criteria.matches(a_A)); 123 assertEquals("a.A.a", mock1.getValue() || mock2.getValue(), criteria.matches(a_A_a)); 124 } 125 126 public void testMatchWithTwoSubcriteriaTrueTrue() { 127 MockSelectionCriteria mock1 = new MockSelectionCriteria(); 128 mock1.setValue(true); 129 subcriteria.add(mock1); 130 131 MockSelectionCriteria mock2 = new MockSelectionCriteria(); 132 mock2.setValue(true); 133 subcriteria.add(mock2); 134 135 assertEquals("a", mock1.getValue() || mock2.getValue(), criteria.matches(a)); 136 assertEquals("a.A", mock1.getValue() || mock2.getValue(), criteria.matches(a_A)); 137 assertEquals("a.A.a", mock1.getValue() || mock2.getValue(), criteria.matches(a_A_a)); 138 } 139 } 140 | Popular Tags |