01: // Copyright 2006, 2007 The Apache Software Foundation
02: //
03: // Licensed under the Apache License, Version 2.0 (the "License");
04: // you may not use this file except in compliance with the License.
05: // You may obtain a copy of the License at
06: //
07: // http://www.apache.org/licenses/LICENSE-2.0
08: //
09: // 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.tapestry.corelib.components;
16:
17: import java.util.Arrays;
18: import java.util.Collections;
19:
20: import org.apache.tapestry.internal.test.InternalBaseTestCase;
21: import org.apache.tapestry.services.Heartbeat;
22: import org.testng.annotations.Test;
23:
24: public class LoopTest extends InternalBaseTestCase {
25: @Test
26: public void non_empty_iterator() {
27: Heartbeat hb = mockHeartbeat();
28:
29: // Really hard to test the exact timing of all this; it will have to
30: // be "proven" by integration tests.
31:
32: hb.begin();
33: getMocksControl().times(3);
34:
35: hb.end();
36: getMocksControl().times(3);
37:
38: replay();
39:
40: Loop loop = new Loop();
41:
42: loop.setHeartbeat(hb);
43:
44: loop.setSource(Arrays.asList("alpha", "beta", "gamma"));
45:
46: assertTrue(loop.setup());
47: assertEquals(loop.getIndex(), 0);
48:
49: loop.begin();
50: assertEquals(loop.getValue(), "alpha");
51: assertEquals(loop.getIndex(), 0);
52:
53: assertFalse(loop.after());
54: loop.begin();
55: assertEquals(loop.getValue(), "beta");
56: assertEquals(loop.getIndex(), 1);
57:
58: assertFalse(loop.after());
59: loop.begin();
60: assertEquals(loop.getValue(), "gamma");
61: assertEquals(loop.getIndex(), 2);
62:
63: assertTrue(loop.after());
64:
65: verify();
66: }
67:
68: @Test
69: public void iterator_is_null() {
70: Loop loop = new Loop();
71:
72: loop.setSource(null);
73:
74: assertFalse(loop.setup());
75: }
76:
77: @Test
78: public void iterator_is_empty() {
79: Loop loop = new Loop();
80:
81: loop.setSource(Collections.EMPTY_LIST);
82:
83: assertFalse(loop.setup());
84: }
85: }
|