81c4e4ed3ad4f610492794d2aecb7aedd31a45f1
[utils] / support / general / src / test / java / org / wamblee / conditions / AndConditionTest.java
1 /*
2  * Copyright 2005 the original author or authors.
3  * 
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  * 
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  * 
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */ 
16
17 package org.wamblee.conditions;
18
19 import java.util.ArrayList;
20 import java.util.List;
21
22 import junit.framework.TestCase;
23
24 /**
25  * Tests the Or Condition.  
26  *
27  * @author Erik Brakkee
28  */
29 public class AndConditionTest extends TestCase {
30     
31     public void checkResult(boolean aFirst, boolean aSecond, boolean aResult) { 
32         AndCondition<Integer> and = new AndCondition<Integer>(new FixedCondition<Integer>(aFirst), 
33                 new FixedCondition<Integer>(aSecond)); 
34         assertEquals(aResult, and.matches(0));
35     }
36     
37     public void checkResult(boolean[] aValues, boolean aResult) { 
38         List<Condition<Integer>> conditions = new ArrayList<Condition<Integer>>();
39         for (boolean value: aValues) { 
40             conditions.add(new FixedCondition<Integer>(value)); 
41         }
42         AndCondition<Integer> and = new AndCondition<Integer>(conditions);
43         assertEquals(aResult, and.matches(new Integer(0)));
44     }
45
46     /**
47      * Checks all combinations of two conditions. 
48      *
49      */
50     public void testTwoConditions() { 
51         checkResult(false, false, false);
52         checkResult(true, false, false);
53         checkResult(false, true, false); 
54         checkResult(true, true, true);
55     }
56     
57     public void testMultipleConditions() { 
58         checkResult(new boolean[]{ false, false, false} , false);
59         checkResult(new boolean[]{ true, false, false }, false); 
60         checkResult(new boolean[]{ false, true, false }, false); 
61         checkResult(new boolean[]{ false, false, true }, false); 
62         checkResult(new boolean[]{ true, true, true }, true); 
63     }
64 }