(no commit message)
[utils] / support / general / src / test / java / org / wamblee / conditions / OrConditionTest.java
1 /*
2  * Copyright 2005-2010 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 package org.wamblee.conditions;
17
18 import junit.framework.TestCase;
19
20 import java.util.ArrayList;
21 import java.util.List;
22
23 /**
24  * Tests the Or Condition.
25  * 
26  * @author Erik Brakkee
27  */
28 public class OrConditionTest extends TestCase {
29     public void checkResult(boolean aFirst, boolean aSecond, boolean aResult) {
30         OrCondition<Integer> or = new OrCondition<Integer>(
31             new FixedCondition<Integer>(aFirst), new FixedCondition<Integer>(
32                 aSecond));
33         assertEquals(aResult, or.matches(0));
34     }
35
36     public void checkResult(boolean[] aValues, boolean aResult) {
37         List<Condition<Integer>> conditions = new ArrayList<Condition<Integer>>();
38
39         for (boolean value : aValues) {
40             conditions.add(new FixedCondition<Integer>(value));
41         }
42
43         OrCondition<Integer> or = new OrCondition<Integer>(conditions);
44         assertEquals(aResult, or.matches(Integer.valueOf(0)));
45     }
46
47     /**
48      * Checks all combinations of two conditions.
49      * 
50      */
51     public void testTwoConditions() {
52         checkResult(false, false, false);
53         checkResult(true, false, true);
54         checkResult(false, true, true);
55         checkResult(true, true, true);
56     }
57
58     public void testMultipleConditions() {
59         checkResult(new boolean[] { false, false, false }, false);
60         checkResult(new boolean[] { true, false, false }, true);
61         checkResult(new boolean[] { false, true, false }, true);
62         checkResult(new boolean[] { false, false, true }, true);
63         checkResult(new boolean[] { true, true, true }, true);
64     }
65 }