1
2
3
4
5
6
7 package nl.tudelft.simulation.event.util;
8
9 import java.util.ArrayList;
10 import java.util.List;
11
12 import junit.framework.Assert;
13 import junit.framework.TestCase;
14 import nl.tudelft.simulation.event.EventInterface;
15 import nl.tudelft.simulation.event.EventListenerInterface;
16
17 /***
18 * The test script for the EventIterator class.
19 * <p>
20 * (c) copyright 2002-2005-2004 <a href="http://www.simulation.tudelft.nl">Delft
21 * University of Technology </a>, the Netherlands. <br>
22 * See for project information <a
23 * href="http://www.simulation.tudelft.nl">www.simulation.tudelft.nl </a> <br>
24 * License of use: <a href="http://www.gnu.org/copyleft/lesser.html">Lesser
25 * General Public License (LGPL) </a>, no warranty.
26 *
27 * @author <a href="http://www.peter-jacobs.com">Peter Jacobs </a>
28 * @version $Revision: 1.6 $ $Date: 2005/07/04 12:23:03 $
29 * @since 1.5
30 */
31 public class EventIteratorTest extends TestCase implements
32 EventListenerInterface
33 {
34 /*** a check on the removed state */
35 private boolean removed = false;
36
37 /*** TEST_METHOD is the name of the test method */
38 public static final String TEST_METHOD = "test";
39
40 /***
41 * constructs a new EventIteratorTest.
42 */
43 public EventIteratorTest()
44 {
45 this(TEST_METHOD);
46 }
47
48 /***
49 * constructs a new EventIteratorTest
50 *
51 * @param method the name of the test method
52 */
53 public EventIteratorTest(final String method)
54 {
55 super(method);
56 }
57
58 /***
59 * tests the classes in the reference class.
60 */
61 public void test()
62 {
63 List<Object> list = new ArrayList<Object>();
64 list.add(new Object());
65 EventIterator<Object> iterator = new EventIterator<Object>(list
66 .iterator());
67 iterator.next();
68 iterator.addListener(this, EventIterator.OBJECT_REMOVED_EVENT);
69 iterator.remove();
70 Assert.assertTrue(this.removed);
71 }
72
73 /***
74 * @see nl.tudelft.simulation.event.EventListenerInterface
75 * #notify(nl.tudelft.simulation.event.EventInterface)
76 */
77 public void notify(final EventInterface event)
78 {
79 if (event.getType().equals(EventIterator.OBJECT_REMOVED_EVENT))
80 {
81 this.removed = true;
82 }
83 }
84 }