2 * Copyright 2005 the original author or authors.
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 package org.wamblee.conditions;
19 import java.util.ArrayList;
20 import java.util.List;
22 import junit.framework.TestCase;
25 * Tests the Or Condition.
27 public class OrConditionTest extends TestCase {
29 public void checkResult(boolean aFirst, boolean aSecond, boolean aResult) {
30 OrCondition<Integer> or = new OrCondition<Integer>(new FixedCondition<Integer>(aFirst),
31 new FixedCondition<Integer>(aSecond));
32 assertEquals(aResult, or.matches(0));
35 public void checkResult(boolean[] aValues, boolean aResult) {
36 List<Condition<Integer>> conditions = new ArrayList<Condition<Integer>>();
37 for (boolean value: aValues) {
38 conditions.add(new FixedCondition<Integer>(value));
40 OrCondition<Integer> or = new OrCondition<Integer>(conditions);
41 assertEquals(aResult, or.matches(new Integer(0)));
45 * Checks all combinations of two conditions.
48 public void testTwoConditions() {
49 checkResult(false, false, false);
50 checkResult(true, false, true);
51 checkResult(false, true, true);
52 checkResult(true, true, true);
55 public void testMultipleConditions() {
56 checkResult(new boolean[]{ false, false, false} , false);
57 checkResult(new boolean[]{ true, false, false }, true);
58 checkResult(new boolean[]{ false, true, false }, true);
59 checkResult(new boolean[]{ false, false, true }, true);
60 checkResult(new boolean[]{ true, true, true }, true);