KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > hivemind > conditional > TestNode


1 // Copyright 2004, 2005 The Apache Software Foundation
2
//
3
// Licensed under the Apache License, Version 2.0 (the "License");
4
// you may not use this file except in compliance with the License.
5
// You may obtain a copy of the License at
6
//
7
// http://www.apache.org/licenses/LICENSE-2.0
8
//
9
// Unless required by applicable law or agreed to in writing, software
10
// distributed under the License is distributed on an "AS IS" BASIS,
11
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
// See the License for the specific language governing permissions and
13
// limitations under the License.
14

15 package org.apache.hivemind.conditional;
16
17 import org.apache.hivemind.conditional.EvaluationContext;
18 import org.apache.hivemind.conditional.Evaluator;
19 import org.apache.hivemind.conditional.Node;
20 import org.apache.hivemind.conditional.NodeImpl;
21 import org.apache.hivemind.test.HiveMindTestCase;
22 import org.easymock.MockControl;
23
24 /**
25  * Tests for the {@link org.apache.hivemind.conditional.NodeImpl} class.
26  *
27  * @author Howard M. Lewis Ship
28  * @since 1.1
29  */

30 public class TestNode extends HiveMindTestCase
31 {
32     public void testConstructorAndGetters()
33     {
34         Node left = (Node) newMock(Node.class);
35         Node right = (Node) newMock(Node.class);
36         Evaluator evaluator = (Evaluator) newMock(Evaluator.class);
37
38         replayControls();
39
40         Node n = new NodeImpl(left, right, evaluator);
41
42         assertSame(left, n.getLeft());
43         assertSame(right, n.getRight());
44
45         verifyControls();
46     }
47
48     public void testEvaluate()
49     {
50         MockControl control = newControl(Evaluator.class);
51         Evaluator evaluator = (Evaluator) control.getMock();
52         EvaluationContext context = (EvaluationContext) newMock(EvaluationContext.class);
53
54         Node n = new NodeImpl(evaluator);
55
56         evaluator.evaluate(context, n);
57         control.setReturnValue(false);
58
59         evaluator.evaluate(context, n);
60         control.setReturnValue(true);
61
62         replayControls();
63
64         assertEquals(false, n.evaluate(context));
65         assertEquals(true, n.evaluate(context));
66
67         verifyControls();
68     }
69 }
Popular Tags