001: /*
002: * Copyright (c) 2001-2007, Jean Tessier
003: * All rights reserved.
004: *
005: * Redistribution and use in source and binary forms, with or without
006: * modification, are permitted provided that the following conditions
007: * are met:
008: *
009: * * Redistributions of source code must retain the above copyright
010: * notice, this list of conditions and the following disclaimer.
011: *
012: * * Redistributions in binary form must reproduce the above copyright
013: * notice, this list of conditions and the following disclaimer in the
014: * documentation and/or other materials provided with the distribution.
015: *
016: * * Neither the name of Jean Tessier nor the names of his contributors
017: * may be used to endorse or promote products derived from this software
018: * without specific prior written permission.
019: *
020: * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
021: * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
022: * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
023: * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR
024: * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
025: * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
026: * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
027: * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
028: * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
029: * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
030: * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
031: */
032:
033: package com.jeantessier.dependency;
034:
035: import java.util.*;
036:
037: import junit.framework.*;
038:
039: public class TestOrCompositeSelectionCriteria extends TestCase {
040: private PackageNode a;
041: private ClassNode a_A;
042: private FeatureNode a_A_a;
043:
044: private Collection subcriteria;
045: private OrCompositeSelectionCriteria criteria;
046:
047: protected void setUp() throws Exception {
048: NodeFactory factory = new NodeFactory();
049:
050: a = factory.createPackage("a");
051: a_A = factory.createClass("a.A");
052: a_A_a = factory.createFeature("a.A.a");
053:
054: subcriteria = new ArrayList();
055: criteria = new OrCompositeSelectionCriteria(subcriteria);
056: }
057:
058: public void testMatchWithEmptyList() {
059: assertEquals("a", true, criteria.matches(a));
060: assertEquals("a.A", true, criteria.matches(a_A));
061: assertEquals("a.A.a", true, criteria.matches(a_A_a));
062: }
063:
064: public void testMatchWithOneFalseSubcriteria() {
065: MockSelectionCriteria mock = new MockSelectionCriteria();
066: mock.setValue(false);
067: subcriteria.add(mock);
068:
069: assertEquals("a", mock.getValue(), criteria.matches(a));
070: assertEquals("a.A", mock.getValue(), criteria.matches(a_A));
071: assertEquals("a.A.a", mock.getValue(), criteria.matches(a_A_a));
072: }
073:
074: public void testMatchWithOneTrueSubcriteria() {
075: MockSelectionCriteria mock = new MockSelectionCriteria();
076: mock.setValue(true);
077: subcriteria.add(mock);
078:
079: assertEquals("a", mock.getValue(), criteria.matches(a));
080: assertEquals("a.A", mock.getValue(), criteria.matches(a_A));
081: assertEquals("a.A.a", mock.getValue(), criteria.matches(a_A_a));
082: }
083:
084: public void testMatchWithTwoSubcriteriaFalseFalse() {
085: MockSelectionCriteria mock1 = new MockSelectionCriteria();
086: mock1.setValue(false);
087: subcriteria.add(mock1);
088:
089: MockSelectionCriteria mock2 = new MockSelectionCriteria();
090: mock2.setValue(false);
091: subcriteria.add(mock2);
092:
093: assertEquals("a", mock1.getValue() || mock2.getValue(),
094: criteria.matches(a));
095: assertEquals("a.A", mock1.getValue() || mock2.getValue(),
096: criteria.matches(a_A));
097: assertEquals("a.A.a", mock1.getValue() || mock2.getValue(),
098: criteria.matches(a_A_a));
099: }
100:
101: public void testMatchWithTwoSubcriteriaFalseTrue() {
102: MockSelectionCriteria mock1 = new MockSelectionCriteria();
103: mock1.setValue(false);
104: subcriteria.add(mock1);
105:
106: MockSelectionCriteria mock2 = new MockSelectionCriteria();
107: mock2.setValue(true);
108: subcriteria.add(mock2);
109:
110: assertEquals("a", mock1.getValue() || mock2.getValue(),
111: criteria.matches(a));
112: assertEquals("a.A", mock1.getValue() || mock2.getValue(),
113: criteria.matches(a_A));
114: assertEquals("a.A.a", mock1.getValue() || mock2.getValue(),
115: criteria.matches(a_A_a));
116: }
117:
118: public void testMatchWithTwoSubcriteriaTrueFalse() {
119: MockSelectionCriteria mock1 = new MockSelectionCriteria();
120: mock1.setValue(true);
121: subcriteria.add(mock1);
122:
123: MockSelectionCriteria mock2 = new MockSelectionCriteria();
124: mock2.setValue(false);
125: subcriteria.add(mock2);
126:
127: assertEquals("a", mock1.getValue() || mock2.getValue(),
128: criteria.matches(a));
129: assertEquals("a.A", mock1.getValue() || mock2.getValue(),
130: criteria.matches(a_A));
131: assertEquals("a.A.a", mock1.getValue() || mock2.getValue(),
132: criteria.matches(a_A_a));
133: }
134:
135: public void testMatchWithTwoSubcriteriaTrueTrue() {
136: MockSelectionCriteria mock1 = new MockSelectionCriteria();
137: mock1.setValue(true);
138: subcriteria.add(mock1);
139:
140: MockSelectionCriteria mock2 = new MockSelectionCriteria();
141: mock2.setValue(true);
142: subcriteria.add(mock2);
143:
144: assertEquals("a", mock1.getValue() || mock2.getValue(),
145: criteria.matches(a));
146: assertEquals("a.A", mock1.getValue() || mock2.getValue(),
147: criteria.matches(a_A));
148: assertEquals("a.A.a", mock1.getValue() || mock2.getValue(),
149: criteria.matches(a_A_a));
150: }
151: }
|