1 /*
2 * Copyright (c) 2002-2003 The XDoclet Team.
3 * All rights reserved.
4 */
5
6 package xdoclet.util.predicates;
7
8 import junit.framework.TestCase;
9
10 /***
11 * Test to see that the 'And' Predicate is working properly
12 *
13 * @version $Revision: 1.4 $
14 * @author <a href="mailto:mbo@jcs.be">Mathias Bogaert</a>
15 * @author <a href="mailto:andreas.schaefer@madplanet.com">Andreas Schaefer</a>
16 */
17 public class AndTest extends TestCase {
18 public AndTest(String s) {
19 super(s);
20 }
21
22 /***
23 * Test the evaluation of And by using a binary mix of True and False
24 **/
25 public void testAnd() {
26 And trueAndFalse = new And();
27 trueAndFalse.add(new True());
28 trueAndFalse.add(new False());
29 assertTrue(!trueAndFalse.evaluate(null));
30
31 And trueAndTrue = new And();
32 trueAndTrue.add(new True());
33 trueAndTrue.add(new True());
34 assertTrue(trueAndTrue.evaluate(null));
35
36 And falseAndFalse = new And();
37 falseAndFalse.add(new False());
38 falseAndFalse.add(new False());
39 assertTrue(!falseAndFalse.evaluate(null));
40 }
41
42 /***
43 * Test the evaluation of And by using a multiple mix of True and False
44 */
45 public void testMultipleAnd() {
46 And multipleAnd = new And();
47 multipleAnd.add(new True());
48 multipleAnd.add(new True());
49 multipleAnd.add(new True());
50 multipleAnd.add(new True());
51 assertTrue("Five times True anded is not evaluated to true", multipleAnd.evaluate(null));
52
53 multipleAnd = new And();
54 multipleAnd.add(new True());
55 multipleAnd.add(new True());
56 multipleAnd.add(new False());
57 multipleAnd.add(new True());
58 multipleAnd.add(new True());
59 assertTrue("Four times True and one False anded is not evaluated to false",
60 !multipleAnd.evaluate(null));
61
62 multipleAnd = new And();
63 multipleAnd.add(new False());
64 multipleAnd.add(new False());
65 multipleAnd.add(new True());
66 multipleAnd.add(new False());
67 multipleAnd.add(new False());
68 assertTrue("Four times False and one True anded is not evaluated to false",
69 !multipleAnd.evaluate(null));
70 }
71
72 /***
73 * Test the proper implementation of composite predicate's create() method
74 */
75 public void testCompositePredicateMethod()
76 throws Exception {
77
78 And testAnd = new And();
79 testAnd.createElement("true");
80 testAnd.createElement("true");
81 assertTrue("Created and added Predicates (True, True) does not evaluate to true",
82 testAnd.evaluate(null));
83
84 testAnd = new And();
85 testAnd.createElement("true");
86 testAnd.createElement("false");
87 assertTrue("Created and added Predicates (True, False) does not evaluate to false",
88 !testAnd.evaluate(null));
89 }
90 }
This page was automatically generated by Maven