Ray Milkey

Fix tests that were hiding the setUp() mthod in the JerseyTest framework

REST API tests were defining a set up method called setUp(), which had
the unwanted side effect of hinding the parent class' implementation.
Made the set up and tear down methods for the tests have unique names so
both will be executed.

Also fixed some javadocs while editing the files.

Change-Id: Ifaa75fe650d5909b066769e5e12cb5c834267a20
...@@ -99,7 +99,7 @@ public class ApplicationsResourceTest extends ResourceTest { ...@@ -99,7 +99,7 @@ public class ApplicationsResourceTest extends ResourceTest {
99 ImmutableList.of("My Feature")); 99 ImmutableList.of("My Feature"));
100 100
101 /** 101 /**
102 - * Hamcrest matcher to check that an device representation in JSON matches 102 + * Hamcrest matcher to check that an application representation in JSON matches
103 * the actual device. 103 * the actual device.
104 */ 104 */
105 private static class AppJsonMatcher extends TypeSafeMatcher<JsonObject> { 105 private static class AppJsonMatcher extends TypeSafeMatcher<JsonObject> {
...@@ -143,7 +143,7 @@ public class ApplicationsResourceTest extends ResourceTest { ...@@ -143,7 +143,7 @@ public class ApplicationsResourceTest extends ResourceTest {
143 } 143 }
144 144
145 /** 145 /**
146 - * Factory to allocate an device matcher. 146 + * Factory to allocate an application matcher.
147 * 147 *
148 * @param app application object we are looking for 148 * @param app application object we are looking for
149 * @return matcher 149 * @return matcher
...@@ -152,10 +152,11 @@ public class ApplicationsResourceTest extends ResourceTest { ...@@ -152,10 +152,11 @@ public class ApplicationsResourceTest extends ResourceTest {
152 return new AppJsonMatcher(app); 152 return new AppJsonMatcher(app);
153 } 153 }
154 154
155 - 155 + /**
156 - @Override 156 + * Initializes test mocks and environment.
157 + */
157 @Before 158 @Before
158 - public void setUp() { 159 + public void setUpMocks() {
159 service = createMock(ApplicationAdminService.class); 160 service = createMock(ApplicationAdminService.class);
160 161
161 expect(service.getId("one")) 162 expect(service.getId("one"))
...@@ -190,8 +191,11 @@ public class ApplicationsResourceTest extends ResourceTest { ...@@ -190,8 +191,11 @@ public class ApplicationsResourceTest extends ResourceTest {
190 BaseResource.setServiceDirectory(testDirectory); 191 BaseResource.setServiceDirectory(testDirectory);
191 } 192 }
192 193
194 + /**
195 + * Verifies test mocks.
196 + */
193 @After 197 @After
194 - public void shutDown() { 198 + public void tearDownMocks() {
195 verify(service); 199 verify(service);
196 } 200 }
197 201
......
...@@ -206,8 +206,11 @@ public class DevicesResourceTest extends ResourceTest { ...@@ -206,8 +206,11 @@ public class DevicesResourceTest extends ResourceTest {
206 return new DeviceJsonArrayMatcher(device); 206 return new DeviceJsonArrayMatcher(device);
207 } 207 }
208 208
209 + /**
210 + * Initializes test mocks and environment.
211 + */
209 @Before 212 @Before
210 - public void setUp() { 213 + public void setUpMocks() {
211 mockDeviceService = createMock(DeviceService.class); 214 mockDeviceService = createMock(DeviceService.class);
212 215
213 expect(mockDeviceService.isAvailable(isA(DeviceId.class))) 216 expect(mockDeviceService.isAvailable(isA(DeviceId.class)))
...@@ -226,13 +229,13 @@ public class DevicesResourceTest extends ResourceTest { ...@@ -226,13 +229,13 @@ public class DevicesResourceTest extends ResourceTest {
226 .add(CodecService.class, codecService); 229 .add(CodecService.class, codecService);
227 230
228 BaseResource.setServiceDirectory(testDirectory); 231 BaseResource.setServiceDirectory(testDirectory);
229 -
230 -
231 } 232 }
232 233
234 + /**
235 + * Verifies test mocks.
236 + */
233 @After 237 @After
234 - public void tearDown() throws Exception { 238 + public void tearDownMocks() {
235 - super.tearDown();
236 verify(mockDeviceService); 239 verify(mockDeviceService);
237 } 240 }
238 241
......
...@@ -232,7 +232,7 @@ public class FlowsResourceTest extends ResourceTest { ...@@ -232,7 +232,7 @@ public class FlowsResourceTest extends ResourceTest {
232 * Sets up the global values for all the tests. 232 * Sets up the global values for all the tests.
233 */ 233 */
234 @Before 234 @Before
235 - public void setUp() { 235 + public void setUpTest() {
236 // Mock device service 236 // Mock device service
237 expect(mockDeviceService.getDevice(deviceId1)) 237 expect(mockDeviceService.getDevice(deviceId1))
238 .andReturn(device1); 238 .andReturn(device1);
...@@ -255,12 +255,9 @@ public class FlowsResourceTest extends ResourceTest { ...@@ -255,12 +255,9 @@ public class FlowsResourceTest extends ResourceTest {
255 255
256 /** 256 /**
257 * Cleans up and verifies the mocks. 257 * Cleans up and verifies the mocks.
258 - *
259 - * @throws Exception if the super teardown fails.
260 */ 258 */
261 @After 259 @After
262 - public void tearDown() throws Exception { 260 + public void tearDownTest() {
263 - super.tearDown();
264 verify(mockFlowService); 261 verify(mockFlowService);
265 } 262 }
266 263
......
...@@ -67,8 +67,11 @@ public class HostResourceTest extends ResourceTest { ...@@ -67,8 +67,11 @@ public class HostResourceTest extends ResourceTest {
67 final HostService mockHostService = createMock(HostService.class); 67 final HostService mockHostService = createMock(HostService.class);
68 final HashSet<Host> hosts = new HashSet<>(); 68 final HashSet<Host> hosts = new HashSet<>();
69 69
70 + /**
71 + * Initializes test mocks and environment.
72 + */
70 @Before 73 @Before
71 - public void setUp() { 74 + public void setUpTest() {
72 expect(mockHostService.getHosts()).andReturn(hosts).anyTimes(); 75 expect(mockHostService.getHosts()).andReturn(hosts).anyTimes();
73 76
74 // Register the services needed for the test 77 // Register the services needed for the test
...@@ -82,9 +85,11 @@ public class HostResourceTest extends ResourceTest { ...@@ -82,9 +85,11 @@ public class HostResourceTest extends ResourceTest {
82 BaseResource.setServiceDirectory(testDirectory); 85 BaseResource.setServiceDirectory(testDirectory);
83 } 86 }
84 87
88 + /**
89 + * Verifies mocks.
90 + */
85 @After 91 @After
86 - public void tearDown() throws Exception { 92 + public void tearDownTest() {
87 - super.tearDown();
88 verify(mockHostService); 93 verify(mockHostService);
89 } 94 }
90 95
......
...@@ -252,8 +252,11 @@ public class IntentsResourceTest extends ResourceTest { ...@@ -252,8 +252,11 @@ public class IntentsResourceTest extends ResourceTest {
252 return new IntentJsonArrayMatcher(intent); 252 return new IntentJsonArrayMatcher(intent);
253 } 253 }
254 254
255 + /**
256 + * Initializes test mocks and environment.
257 + */
255 @Before 258 @Before
256 - public void setUp() { 259 + public void setUpTest() {
257 expect(mockIntentService.getIntents()).andReturn(intents).anyTimes(); 260 expect(mockIntentService.getIntents()).andReturn(intents).anyTimes();
258 261
259 // Register the services needed for the test 262 // Register the services needed for the test
...@@ -270,9 +273,11 @@ public class IntentsResourceTest extends ResourceTest { ...@@ -270,9 +273,11 @@ public class IntentsResourceTest extends ResourceTest {
270 Intent.bindIdGenerator(mockGenerator); 273 Intent.bindIdGenerator(mockGenerator);
271 } 274 }
272 275
276 + /**
277 + * Tears down and verifies test mocks and environment.
278 + */
273 @After 279 @After
274 - public void tearDown() throws Exception { 280 + public void tearDownTest() {
275 - super.tearDown();
276 verify(mockIntentService); 281 verify(mockIntentService);
277 Intent.unbindIdGenerator(mockGenerator); 282 Intent.unbindIdGenerator(mockGenerator);
278 } 283 }
......
...@@ -151,9 +151,11 @@ public class LinksResourceTest extends ResourceTest { ...@@ -151,9 +151,11 @@ public class LinksResourceTest extends ResourceTest {
151 return new LinkJsonArrayMatcher(link); 151 return new LinkJsonArrayMatcher(link);
152 } 152 }
153 153
154 - 154 + /**
155 + * Initializes test mocks and environment.
156 + */
155 @Before 157 @Before
156 - public void setUp() { 158 + public void setUpTest() {
157 mockLinkService = createMock(LinkService.class); 159 mockLinkService = createMock(LinkService.class);
158 160
159 // Register the services needed for the test 161 // Register the services needed for the test
...@@ -167,9 +169,11 @@ public class LinksResourceTest extends ResourceTest { ...@@ -167,9 +169,11 @@ public class LinksResourceTest extends ResourceTest {
167 BaseResource.setServiceDirectory(testDirectory); 169 BaseResource.setServiceDirectory(testDirectory);
168 } 170 }
169 171
172 + /**
173 + * Tears down and verifies test mocks and environment.
174 + */
170 @After 175 @After
171 - public void tearDown() throws Exception { 176 + public void tearDownTest() {
172 - super.tearDown();
173 verify(mockLinkService); 177 verify(mockLinkService);
174 } 178 }
175 179
......
...@@ -129,8 +129,11 @@ public class PathsResourceTest extends ResourceTest { ...@@ -129,8 +129,11 @@ public class PathsResourceTest extends ResourceTest {
129 return new PathJsonMatcher(path); 129 return new PathJsonMatcher(path);
130 } 130 }
131 131
132 + /**
133 + * Initializes test mocks and environment.
134 + */
132 @Before 135 @Before
133 - public void setUp() { 136 + public void setUpTest() {
134 137
135 // Register the services needed for the test 138 // Register the services needed for the test
136 CodecManager codecService = new CodecManager(); 139 CodecManager codecService = new CodecManager();
...@@ -143,9 +146,11 @@ public class PathsResourceTest extends ResourceTest { ...@@ -143,9 +146,11 @@ public class PathsResourceTest extends ResourceTest {
143 BaseResource.setServiceDirectory(testDirectory); 146 BaseResource.setServiceDirectory(testDirectory);
144 } 147 }
145 148
149 + /**
150 + * Tears down test mocks and environment.
151 + */
146 @After 152 @After
147 - public void tearDown() throws Exception { 153 + public void tearDownTest() {
148 - super.tearDown();
149 verify(mockPathService); 154 verify(mockPathService);
150 } 155 }
151 156
......
...@@ -175,7 +175,7 @@ public class TopologyResourceTest extends ResourceTest { ...@@ -175,7 +175,7 @@ public class TopologyResourceTest extends ResourceTest {
175 * Initializes the test harness. 175 * Initializes the test harness.
176 */ 176 */
177 @Before 177 @Before
178 - public void setUp() { 178 + public void setUpTest() {
179 TopologyService topologyService = new MockTopologyService(); 179 TopologyService topologyService = new MockTopologyService();
180 CodecManager codecService = new CodecManager(); 180 CodecManager codecService = new CodecManager();
181 codecService.activate(); 181 codecService.activate();
......