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
diff --git a/web/api/src/test/java/org/onosproject/rest/ApplicationsResourceTest.java b/web/api/src/test/java/org/onosproject/rest/ApplicationsResourceTest.java
index d7ace4d..81db631 100644
--- a/web/api/src/test/java/org/onosproject/rest/ApplicationsResourceTest.java
+++ b/web/api/src/test/java/org/onosproject/rest/ApplicationsResourceTest.java
@@ -99,7 +99,7 @@
ImmutableList.of("My Feature"));
/**
- * Hamcrest matcher to check that an device representation in JSON matches
+ * Hamcrest matcher to check that an application representation in JSON matches
* the actual device.
*/
private static class AppJsonMatcher extends TypeSafeMatcher<JsonObject> {
@@ -143,7 +143,7 @@
}
/**
- * Factory to allocate an device matcher.
+ * Factory to allocate an application matcher.
*
* @param app application object we are looking for
* @return matcher
@@ -152,10 +152,11 @@
return new AppJsonMatcher(app);
}
-
- @Override
+ /**
+ * Initializes test mocks and environment.
+ */
@Before
- public void setUp() {
+ public void setUpMocks() {
service = createMock(ApplicationAdminService.class);
expect(service.getId("one"))
@@ -190,8 +191,11 @@
BaseResource.setServiceDirectory(testDirectory);
}
+ /**
+ * Verifies test mocks.
+ */
@After
- public void shutDown() {
+ public void tearDownMocks() {
verify(service);
}
diff --git a/web/api/src/test/java/org/onosproject/rest/DevicesResourceTest.java b/web/api/src/test/java/org/onosproject/rest/DevicesResourceTest.java
index 722665e..93dc04c 100644
--- a/web/api/src/test/java/org/onosproject/rest/DevicesResourceTest.java
+++ b/web/api/src/test/java/org/onosproject/rest/DevicesResourceTest.java
@@ -206,8 +206,11 @@
return new DeviceJsonArrayMatcher(device);
}
+ /**
+ * Initializes test mocks and environment.
+ */
@Before
- public void setUp() {
+ public void setUpMocks() {
mockDeviceService = createMock(DeviceService.class);
expect(mockDeviceService.isAvailable(isA(DeviceId.class)))
@@ -226,13 +229,13 @@
.add(CodecService.class, codecService);
BaseResource.setServiceDirectory(testDirectory);
-
-
}
+ /**
+ * Verifies test mocks.
+ */
@After
- public void tearDown() throws Exception {
- super.tearDown();
+ public void tearDownMocks() {
verify(mockDeviceService);
}
diff --git a/web/api/src/test/java/org/onosproject/rest/FlowsResourceTest.java b/web/api/src/test/java/org/onosproject/rest/FlowsResourceTest.java
index e05cbe3..fc28624 100644
--- a/web/api/src/test/java/org/onosproject/rest/FlowsResourceTest.java
+++ b/web/api/src/test/java/org/onosproject/rest/FlowsResourceTest.java
@@ -232,7 +232,7 @@
* Sets up the global values for all the tests.
*/
@Before
- public void setUp() {
+ public void setUpTest() {
// Mock device service
expect(mockDeviceService.getDevice(deviceId1))
.andReturn(device1);
@@ -255,12 +255,9 @@
/**
* Cleans up and verifies the mocks.
- *
- * @throws Exception if the super teardown fails.
*/
@After
- public void tearDown() throws Exception {
- super.tearDown();
+ public void tearDownTest() {
verify(mockFlowService);
}
diff --git a/web/api/src/test/java/org/onosproject/rest/HostResourceTest.java b/web/api/src/test/java/org/onosproject/rest/HostResourceTest.java
index 2d9cdeb..a5c4b77 100644
--- a/web/api/src/test/java/org/onosproject/rest/HostResourceTest.java
+++ b/web/api/src/test/java/org/onosproject/rest/HostResourceTest.java
@@ -67,8 +67,11 @@
final HostService mockHostService = createMock(HostService.class);
final HashSet<Host> hosts = new HashSet<>();
+ /**
+ * Initializes test mocks and environment.
+ */
@Before
- public void setUp() {
+ public void setUpTest() {
expect(mockHostService.getHosts()).andReturn(hosts).anyTimes();
// Register the services needed for the test
@@ -82,9 +85,11 @@
BaseResource.setServiceDirectory(testDirectory);
}
+ /**
+ * Verifies mocks.
+ */
@After
- public void tearDown() throws Exception {
- super.tearDown();
+ public void tearDownTest() {
verify(mockHostService);
}
diff --git a/web/api/src/test/java/org/onosproject/rest/IntentsResourceTest.java b/web/api/src/test/java/org/onosproject/rest/IntentsResourceTest.java
index b2eee81..3289c87 100644
--- a/web/api/src/test/java/org/onosproject/rest/IntentsResourceTest.java
+++ b/web/api/src/test/java/org/onosproject/rest/IntentsResourceTest.java
@@ -252,8 +252,11 @@
return new IntentJsonArrayMatcher(intent);
}
+ /**
+ * Initializes test mocks and environment.
+ */
@Before
- public void setUp() {
+ public void setUpTest() {
expect(mockIntentService.getIntents()).andReturn(intents).anyTimes();
// Register the services needed for the test
@@ -270,9 +273,11 @@
Intent.bindIdGenerator(mockGenerator);
}
+ /**
+ * Tears down and verifies test mocks and environment.
+ */
@After
- public void tearDown() throws Exception {
- super.tearDown();
+ public void tearDownTest() {
verify(mockIntentService);
Intent.unbindIdGenerator(mockGenerator);
}
diff --git a/web/api/src/test/java/org/onosproject/rest/LinksResourceTest.java b/web/api/src/test/java/org/onosproject/rest/LinksResourceTest.java
index 274a8f2..c62199c 100644
--- a/web/api/src/test/java/org/onosproject/rest/LinksResourceTest.java
+++ b/web/api/src/test/java/org/onosproject/rest/LinksResourceTest.java
@@ -151,9 +151,11 @@
return new LinkJsonArrayMatcher(link);
}
-
+ /**
+ * Initializes test mocks and environment.
+ */
@Before
- public void setUp() {
+ public void setUpTest() {
mockLinkService = createMock(LinkService.class);
// Register the services needed for the test
@@ -167,9 +169,11 @@
BaseResource.setServiceDirectory(testDirectory);
}
+ /**
+ * Tears down and verifies test mocks and environment.
+ */
@After
- public void tearDown() throws Exception {
- super.tearDown();
+ public void tearDownTest() {
verify(mockLinkService);
}
diff --git a/web/api/src/test/java/org/onosproject/rest/PathsResourceTest.java b/web/api/src/test/java/org/onosproject/rest/PathsResourceTest.java
index 2cdd23e..19b5f2a 100644
--- a/web/api/src/test/java/org/onosproject/rest/PathsResourceTest.java
+++ b/web/api/src/test/java/org/onosproject/rest/PathsResourceTest.java
@@ -129,8 +129,11 @@
return new PathJsonMatcher(path);
}
+ /**
+ * Initializes test mocks and environment.
+ */
@Before
- public void setUp() {
+ public void setUpTest() {
// Register the services needed for the test
CodecManager codecService = new CodecManager();
@@ -143,9 +146,11 @@
BaseResource.setServiceDirectory(testDirectory);
}
+ /**
+ * Tears down test mocks and environment.
+ */
@After
- public void tearDown() throws Exception {
- super.tearDown();
+ public void tearDownTest() {
verify(mockPathService);
}
diff --git a/web/api/src/test/java/org/onosproject/rest/TopologyResourceTest.java b/web/api/src/test/java/org/onosproject/rest/TopologyResourceTest.java
index d25fd59..b7bd0d5 100644
--- a/web/api/src/test/java/org/onosproject/rest/TopologyResourceTest.java
+++ b/web/api/src/test/java/org/onosproject/rest/TopologyResourceTest.java
@@ -175,7 +175,7 @@
* Initializes the test harness.
*/
@Before
- public void setUp() {
+ public void setUpTest() {
TopologyService topologyService = new MockTopologyService();
CodecManager codecService = new CodecManager();
codecService.activate();