KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > jeantessier > dependency > TestOrCompositeSelectionCriteria


1 /*
2  * Copyright (c) 2001-2005, Jean Tessier
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  *
9  * * Redistributions of source code must retain the above copyright
10  * notice, this list of conditions and the following disclaimer.
11  *
12  * * Redistributions in binary form must reproduce the above copyright
13  * notice, this list of conditions and the following disclaimer in the
14  * documentation and/or other materials provided with the distribution.
15  *
16  * * Neither the name of Jean Tessier nor the names of his contributors
17  * may be used to endorse or promote products derived from this software
18  * without specific prior written permission.
19  *
20  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
23  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR
24  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
25  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
26  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
27  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
28  * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
29  * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
30  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31  */

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 JavaDoc {
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