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