1
2
3
4
5
6
7
8
9
10 package nl.tudelft.simulation.event.ref;
11
12 import junit.framework.Assert;
13 import junit.framework.TestCase;
14
15 /***
16 * The test script for the reference package. All classes in this package are
17 * tested with this test
18 * <p>
19 * (c) copyright 2003-2004 <a href="http://www.simulation.tudelft.nl">Delft
20 * University of Technology </a>, the Netherlands. <br>
21 * See for project information <a
22 * href="http://www.simulation.tudelft.nl">www.simulation.tudelft.nl </a> <br>
23 * License of use: <a href="http://www.gnu.org/copyleft/gpl.html">General Public
24 * License (GPL) </a>, no warranty <br>
25 *
26 * @author <a href="http://www.simulation.tudelft.nl/people/jacobs.html">Peter
27 * Jacobs </a>
28 * @version 1.0, 2004-03-18
29 * @since 1.2
30 */
31 public class EventRefTest extends TestCase
32 {
33 /*** TEST_METHOD is the name of the test method */
34 public static final String TEST_METHOD = "test";
35
36 /***
37 * constructs a new EventIteratorTest.
38 */
39 public EventRefTest()
40 {
41 this(TEST_METHOD);
42 }
43
44 /***
45 * constructs a new EventIteratorTest
46 *
47 * @param method the name of the test method
48 */
49 public EventRefTest(final String method)
50 {
51 super(method);
52 }
53
54 /***
55 * tests the classes in the reference class.
56 */
57 public void test()
58 {
59 try
60 {
61
62
63
64 Object referent = new String("EventIteratorTest");
65
66
67
68
69
70 Reference reference = new WeakReference(referent);
71 Assert.assertEquals(reference.get(), referent);
72 Runtime.getRuntime().gc();
73 Assert.assertNotNull(reference.get());
74
75
76
77 reference = new WeakReference(new String("EventIteratorTest"));
78 Runtime.getRuntime().gc();
79 Assert.assertNull(reference.get());
80
81
82 reference = new StrongReference(new String("EventIteratorTest"));
83 Assert.assertNotNull(reference.get());
84 Runtime.getRuntime().gc();
85 Assert.assertNotNull(reference.get());
86 } catch (Throwable throwable)
87 {
88
89 Assert.fail();
90 }
91 }
92 }