1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 package net.grinder.engine.process;
23
24 import junit.framework.TestCase;
25
26 import net.grinder.common.StubTest;
27 import net.grinder.common.Test;
28 import net.grinder.scriptengine.Instrumenter;
29 import net.grinder.statistics.StatisticsServicesImplementation;
30 import net.grinder.statistics.StatisticsSetFactory;
31 import net.grinder.testutility.RandomStubFactory;
32 import net.grinder.util.TimeAuthority;
33 import net.grinder.util.TimeAuthorityStubFactory;
34
35
36
37
38
39
40
41 public class TestTestRegistry extends TestCase {
42 private final RandomStubFactory<TestStatisticsHelper>
43 m_testStatisticsHelperStubFactory =
44 RandomStubFactory.create(TestStatisticsHelper.class);
45 private final TestStatisticsHelper m_testStatisticsHelper =
46 m_testStatisticsHelperStubFactory.getStub();
47
48 private final TimeAuthorityStubFactory m_timeAuthorityStubFactory =
49 new TimeAuthorityStubFactory();
50 private final TimeAuthority m_timeAuthority =
51 m_timeAuthorityStubFactory.getStub();
52
53 public TestTestRegistry(String name) {
54 super(name);
55 }
56
57 public void testConstructor() throws Exception {
58 final ThreadContextLocator threadContextLocator =
59 new StubThreadContextLocator();
60 final StatisticsSetFactory statisticsSetFactory =
61 StatisticsServicesImplementation.getInstance().getStatisticsSetFactory();
62
63 final TestRegistryImplementation testRegistryImplementation =
64 new TestRegistryImplementation(
65 threadContextLocator, statisticsSetFactory, m_testStatisticsHelper,
66 m_timeAuthority);
67
68 assertNotNull(testRegistryImplementation.getTestStatisticsMap());
69
70 m_testStatisticsHelperStubFactory.assertNoMoreCalls();
71 m_timeAuthorityStubFactory.assertNoMoreCalls();
72 }
73
74 public void testRegister() throws Exception {
75 final ThreadContextLocator threadContextLocator =
76 new StubThreadContextLocator();
77 final StatisticsSetFactory statisticsSetFactory =
78 StatisticsServicesImplementation.getInstance().getStatisticsSetFactory();
79
80 final TestRegistryImplementation testRegistryImplementation =
81 new TestRegistryImplementation(
82 threadContextLocator, statisticsSetFactory, m_testStatisticsHelper,
83 m_timeAuthority);
84
85 assertNull(testRegistryImplementation.getNewTests());
86
87 final Test test1 = new StubTest(1, "Test 1");
88 final Test test2 = new StubTest(2, "Test 2");
89
90 try {
91 testRegistryImplementation.register(test1);
92 fail("Expected AssertionError");
93 }
94 catch (AssertionError e) {
95 }
96
97 final RandomStubFactory<Instrumenter> instrumenterStubFactory =
98 RandomStubFactory.create(Instrumenter.class);
99 testRegistryImplementation.setInstrumenter(
100 instrumenterStubFactory.getStub());
101
102 final TestRegistryImplementation.RegisteredTest registeredTest1a =
103 testRegistryImplementation.register(test1);
104
105 final TestRegistryImplementation.RegisteredTest registeredTest1b =
106 testRegistryImplementation.register(test1);
107
108 final TestRegistryImplementation.RegisteredTest registeredTest2 =
109 testRegistryImplementation.register(test2);
110
111 assertSame(registeredTest1a, registeredTest1b);
112 assertNotSame(registeredTest2, registeredTest1a);
113
114 assertTrue(testRegistryImplementation.getNewTests().contains(test1));
115 assertNull(testRegistryImplementation.getNewTests());
116
117 m_testStatisticsHelperStubFactory.assertNoMoreCalls();
118 m_timeAuthorityStubFactory.assertNoMoreCalls();
119 }
120 }