diff options
author | 2018-09-14 17:22:14 -0400 | |
---|---|---|
committer | 2018-09-14 17:23:12 -0400 | |
commit | f8426d18257c33fa8a0267e4f96f7e53bb4a82ee (patch) | |
tree | 78aee264bca03560e43e03ccd2e65dabfef8b44c /src/test/java/io/swagger/api/impl | |
parent | 4a81073bb3ce0e873bcf38853e66f8ae4150da67 (diff) |
Address warnings
Change-Id: I953b71d130c78bb20cf602e101021e29b538088e
Issue-ID: DCAEGEN2-605
Signed-off-by: Shadi Haidar <sh1986@att.com>
Diffstat (limited to 'src/test/java/io/swagger/api/impl')
4 files changed, 137 insertions, 129 deletions
diff --git a/src/test/java/io/swagger/api/impl/DcaeServiceTypesApiServiceImplTests.java b/src/test/java/io/swagger/api/impl/DcaeServiceTypesApiServiceImplTests.java index 4a47787..c1d200f 100644 --- a/src/test/java/io/swagger/api/impl/DcaeServiceTypesApiServiceImplTests.java +++ b/src/test/java/io/swagger/api/impl/DcaeServiceTypesApiServiceImplTests.java @@ -18,35 +18,36 @@ package io.swagger.api.impl;/*- * ============LICENSE_END========================================================= */ -import org.onap.dcae.inventory.daos.DCAEServiceTypesDAO; -import org.onap.dcae.inventory.daos.DCAEServicesDAO; -import org.onap.dcae.inventory.daos.InventoryDAOManager; -import org.onap.dcae.inventory.dbthings.models.DCAEServiceObject; -import org.onap.dcae.inventory.dbthings.models.DCAEServiceTypeObject; -import io.swagger.model.DCAEServiceType; -import io.swagger.model.DCAEServiceTypeRequest; -import org.joda.time.DateTime; -import org.junit.Before; -import org.junit.Test; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; + +import java.util.Arrays; +import java.util.Objects; +import java.util.UUID; import javax.ws.rs.core.Response; import javax.ws.rs.core.UriBuilder; import javax.ws.rs.core.UriInfo; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; -import static org.mockito.Mockito.*; - +import org.joda.time.DateTime; +import org.junit.Before; +import org.junit.Test; import org.junit.runner.RunWith; +import org.onap.dcae.inventory.daos.DCAEServiceTypesDAO; +import org.onap.dcae.inventory.daos.DCAEServicesDAO; +import org.onap.dcae.inventory.daos.InventoryDAOManager; +import org.onap.dcae.inventory.dbthings.models.DCAEServiceObject; +import org.onap.dcae.inventory.dbthings.models.DCAEServiceTypeObject; import org.powermock.api.mockito.PowerMockito; import org.powermock.core.classloader.annotations.PrepareForTest; import org.powermock.modules.junit4.PowerMockRunner; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import java.util.Arrays; -import java.util.Objects; -import java.util.UUID; +import io.swagger.model.DCAEServiceType; +import io.swagger.model.DCAEServiceTypeRequest; /** @@ -56,35 +57,36 @@ import java.util.UUID; @RunWith(PowerMockRunner.class) public class DcaeServiceTypesApiServiceImplTests { - private final static Logger LOG = LoggerFactory.getLogger(DcaeServiceTypesApiServiceImplTests.class); + private static final Logger log = LoggerFactory.getLogger(DcaeServiceTypesApiServiceImplTests.class); - private final static String URL_PATH = "http://testing-is-good.com"; + private static final String URL_PATH = "http://testing-is-good.com"; private DcaeServiceTypesApiServiceImpl api = null; private UriInfo uriInfo = null; - private DCAEServiceTypesDAO mockTypesDAO = null; - private DCAEServicesDAO mockServicesDAO = null; + private DCAEServiceTypesDAO mockTypesDao = null; + private DCAEServicesDAO mockServicesDao = null; @Before public void setupClass() { api = new DcaeServiceTypesApiServiceImpl(); uriInfo = mock(UriInfo.class); - mockTypesDAO = mock(DCAEServiceTypesDAO.class); - mockServicesDAO = mock(DCAEServicesDAO.class); + mockTypesDao = mock(DCAEServiceTypesDAO.class); + mockServicesDao = mock(DCAEServicesDAO.class); // PowerMockito does bytecode magic to mock static methods and use final classes PowerMockito.mockStatic(InventoryDAOManager.class); - InventoryDAOManager mockDAOManager = mock(InventoryDAOManager.class); + InventoryDAOManager mockDaoManager = mock(InventoryDAOManager.class); - when(InventoryDAOManager.getInstance()).thenReturn(mockDAOManager); - when(mockDAOManager.getDCAEServiceTypesDAO()).thenReturn(mockTypesDAO); - when(mockDAOManager.getDCAEServicesDAO()).thenReturn(mockServicesDAO); + when(InventoryDAOManager.getInstance()).thenReturn(mockDaoManager); + when(mockDaoManager.getDCAEServiceTypesDAO()).thenReturn(mockTypesDao); + when(mockDaoManager.getDCAEServicesDAO()).thenReturn(mockServicesDao); when(uriInfo.getBaseUriBuilder()).thenReturn(UriBuilder.fromPath(URL_PATH)); } - private static boolean matchTypeVsTypeObject(DCAEServiceType serviceType, DCAEServiceTypeObject serviceTypeObject, String prefixPath) { + private static boolean matchTypeVsTypeObject(DCAEServiceType serviceType, DCAEServiceTypeObject serviceTypeObject, + String prefixPath) { return Objects.equals(serviceType.getTypeId(), serviceTypeObject.getTypeId()) && Objects.equals(serviceType.getTypeName(), serviceTypeObject.getTypeName()) && Objects.equals(serviceType.getTypeVersion(), serviceTypeObject.getTypeVersion()) @@ -125,7 +127,7 @@ public class DcaeServiceTypesApiServiceImplTests { for (DCAEServiceTypeObject fixture : new DCAEServiceTypeObject[] {minimalFixture, fullFixture}) { String someTypeId = fixture.getTypeId(); - when(mockTypesDAO.getByTypeId(someTypeId)).thenReturn(fixture); + when(mockTypesDao.getByTypeId(someTypeId)).thenReturn(fixture); try { Response response = api.dcaeServiceTypesTypeIdGet(someTypeId, uriInfo, null); @@ -140,18 +142,19 @@ public class DcaeServiceTypesApiServiceImplTests { @Test public void testGetNotFound() { String someTypeId = "abc:1"; - when(mockTypesDAO.getByTypeId(someTypeId)).thenReturn(null); + when(mockTypesDao.getByTypeId(someTypeId)).thenReturn(null); try { Response response = api.dcaeServiceTypesTypeIdGet(someTypeId, uriInfo, null); assertEquals("GET - 404 test case failed", 404, response.getStatus()); - } catch(Exception e) { + } catch (Exception e) { throw new RuntimeException("Unexpected exception: get 404", e); } } // TODO: Update this to check type id again. Must mock dao calls deeper. - private static boolean matchTypeVsTypeRequest(DCAEServiceType serviceType, DCAEServiceTypeRequest serviceTypeRequest, String prefixPath) { + private static boolean matchTypeVsTypeRequest(DCAEServiceType serviceType, + DCAEServiceTypeRequest serviceTypeRequest, String prefixPath) { return Objects.equals(serviceType.getTypeName(), serviceTypeRequest.getTypeName()) && Objects.equals(serviceType.getTypeVersion(), serviceTypeRequest.getTypeVersion()) && Objects.equals(serviceType.getOwner(), serviceTypeRequest.getOwner()) @@ -208,8 +211,8 @@ public class DcaeServiceTypesApiServiceImplTests { DCAEServiceTypeObject fakeExistingType = new DCAEServiceTypeObject(); fakeExistingType.setTypeId(expectedTypeIdUUID.toString()); - when(mockTypesDAO.getByRequestFromNotASDC(minimalFixture)).thenReturn(fakeExistingType); - when(mockServicesDAO.countByType(DCAEServiceObject.DCAEServiceStatus.RUNNING, fakeExistingType.getTypeId())).thenReturn(10); + when(mockTypesDao.getByRequestFromNotASDC(minimalFixture)).thenReturn(fakeExistingType); + when(mockServicesDao.countByType(DCAEServiceObject.DCAEServiceStatus.RUNNING, fakeExistingType.getTypeId())).thenReturn(10); try { Response response = api.dcaeServiceTypesTypeIdPost(minimalFixture, uriInfo, null); diff --git a/src/test/java/io/swagger/api/impl/DcaeServicesApiServiceImplH2Tests.java b/src/test/java/io/swagger/api/impl/DcaeServicesApiServiceImplH2Tests.java index 0a3b777..cbdff7d 100644 --- a/src/test/java/io/swagger/api/impl/DcaeServicesApiServiceImplH2Tests.java +++ b/src/test/java/io/swagger/api/impl/DcaeServicesApiServiceImplH2Tests.java @@ -20,19 +20,23 @@ package io.swagger.api.impl; -import com.codahale.metrics.MetricRegistry; -import io.dropwizard.db.DataSourceFactory; -import io.dropwizard.jackson.Jackson; -import io.dropwizard.jdbi.DBIFactory; -import io.dropwizard.setup.Environment; -import io.swagger.api.Util; -import io.swagger.model.DCAEServiceRequest; +import static org.junit.Assert.assertEquals; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; + +import javax.ws.rs.core.Response; +import javax.ws.rs.core.SecurityContext; +import javax.ws.rs.core.UriInfo; + import org.joda.time.DateTime; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; import org.onap.dcae.inventory.clients.DatabusControllerClient; -import org.onap.dcae.inventory.daos.*; +import org.onap.dcae.inventory.daos.DCAEServiceComponentsDAO; +import org.onap.dcae.inventory.daos.DCAEServicesComponentsMapsDAO; +import org.onap.dcae.inventory.daos.DCAEServicesDAO; +import org.onap.dcae.inventory.daos.InventoryDAOManager; import org.onap.dcae.inventory.dbthings.models.DCAEServiceObject; import org.powermock.api.mockito.PowerMockito; import org.powermock.core.classloader.annotations.PrepareForTest; @@ -41,14 +45,14 @@ import org.skife.jdbi.v2.DBI; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import javax.ws.rs.core.Response; -import javax.ws.rs.core.SecurityContext; -import javax.ws.rs.core.UriInfo; +import com.codahale.metrics.MetricRegistry; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.fail; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.when; +import io.dropwizard.db.DataSourceFactory; +import io.dropwizard.jackson.Jackson; +import io.dropwizard.jdbi.DBIFactory; +import io.dropwizard.setup.Environment; +import io.swagger.api.Util; +import io.swagger.model.DCAEServiceRequest; /** * Created by mhwang on 9/25/17. @@ -62,16 +66,16 @@ import static org.mockito.Mockito.when; @RunWith(PowerMockRunner.class) public class DcaeServicesApiServiceImplH2Tests { - private final static Logger LOG = LoggerFactory.getLogger(DcaeServicesApiServiceImplH2Tests.class); + private static final Logger log = LoggerFactory.getLogger(DcaeServicesApiServiceImplH2Tests.class); - private DCAEServicesDAO mockServicesDAO = null; - private DCAEServiceComponentsDAO mockComponentsDAO = null; - private DCAEServicesComponentsMapsDAO mockComponentsMapsDAO = null; + private DCAEServicesDAO mockServicesDao = null; + private DCAEServiceComponentsDAO mockComponentsDao = null; + private DCAEServicesComponentsMapsDAO mockComponentsMapsDao = null; // https://stackoverflow.com/questions/35825383/how-to-test-jdbi-daos-with-h2-in-memory-database - // Caused by: java.lang.ClassNotFoundException: Unable to load class: org.h2.Driver from ClassLoader:sun.misc.Launcher$AppClassLoader@18b4aac2;ClassLoader:sun.misc.Launcher$AppClassLoader@18b4aac2 - protected DataSourceFactory getDataSourceFactory() - { + // Caused by: java.lang.ClassNotFoundException: Unable to load class: org.h2.Driver from + // ClassLoader:sun.misc.Launcher$AppClassLoader@18b4aac2;ClassLoader:sun.misc.Launcher$AppClassLoader@18b4aac2 + protected DataSourceFactory getDataSourceFactory() { DataSourceFactory dataSourceFactory = new DataSourceFactory(); dataSourceFactory.setDriverClass( "org.h2.Driver" ); dataSourceFactory.setUrl( "jdbc:h2:mem:testDb" ); @@ -85,23 +89,23 @@ public class DcaeServicesApiServiceImplH2Tests { public void setUp() { Environment env = new Environment( "test-env", Jackson.newObjectMapper(), null, new MetricRegistry(), null ); DBI dbi = new DBIFactory().build( env, getDataSourceFactory(), "test" ); - mockServicesDAO = dbi.onDemand(DCAEServicesDAO.class); - mockComponentsDAO = dbi.onDemand(DCAEServiceComponentsDAO.class); - mockComponentsMapsDAO = dbi.onDemand(DCAEServicesComponentsMapsDAO.class); + mockServicesDao = dbi.onDemand(DCAEServicesDAO.class); + mockComponentsDao = dbi.onDemand(DCAEServiceComponentsDAO.class); + mockComponentsMapsDao = dbi.onDemand(DCAEServicesComponentsMapsDAO.class); // PowerMockito does bytecode magic to mock static methods and use final classes PowerMockito.mockStatic(InventoryDAOManager.class); - InventoryDAOManager mockDAOManager = mock(InventoryDAOManager.class); + InventoryDAOManager mockDaoManager = mock(InventoryDAOManager.class); - when(InventoryDAOManager.getInstance()).thenReturn(mockDAOManager); - when(mockDAOManager.getHandle()).thenReturn(dbi.open()); + when(InventoryDAOManager.getInstance()).thenReturn(mockDaoManager); + when(mockDaoManager.getHandle()).thenReturn(dbi.open()); } @Test - public void testDcaeServicesGet () { - mockServicesDAO.createTable(); - mockComponentsDAO.createTable(); - mockComponentsMapsDAO.createTable(); + public void testDcaeServicesGet() { + mockServicesDao.createTable(); + mockComponentsDao.createTable(); + mockComponentsMapsDao.createTable(); DCAEServiceRequest request = new DCAEServiceRequest(); request.setTypeId("some-type-id"); @@ -110,7 +114,7 @@ public class DcaeServicesApiServiceImplH2Tests { request.setVnfLocation("some-vnf-location"); request.setDeploymentRef("some-deployment-ref"); DCAEServiceObject so = new DCAEServiceObject("some-service-id", request); - mockServicesDAO.insert(so); + mockServicesDao.insert(so); DatabusControllerClient dbcc = mock(DatabusControllerClient.class); DcaeServicesApiServiceImpl api = new DcaeServicesApiServiceImpl(dbcc); diff --git a/src/test/java/io/swagger/api/impl/DcaeServicesApiServiceImplTests.java b/src/test/java/io/swagger/api/impl/DcaeServicesApiServiceImplTests.java index 64b7f88..0f5a0a8 100644 --- a/src/test/java/io/swagger/api/impl/DcaeServicesApiServiceImplTests.java +++ b/src/test/java/io/swagger/api/impl/DcaeServicesApiServiceImplTests.java @@ -18,10 +18,19 @@ package io.swagger.api.impl;/*- * ============LICENSE_END========================================================= */ -import io.swagger.api.NotFoundException; -import io.swagger.api.Util; -import io.swagger.model.DCAEService; -import io.swagger.model.DCAEServiceRequest; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.fail; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; + +import java.lang.reflect.Method; +import java.util.ArrayList; +import java.util.Collection; +import java.util.List; + +import javax.ws.rs.core.Response; +import javax.ws.rs.core.UriInfo; + import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; @@ -35,21 +44,13 @@ import org.onap.dcae.inventory.dbthings.models.DCAEServiceObject; import org.powermock.api.mockito.PowerMockito; import org.powermock.core.classloader.annotations.PrepareForTest; import org.powermock.modules.junit4.PowerMockRunner; - -import static org.junit.Assert.assertEquals; -import static org.mockito.Mockito.*; - import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import javax.ws.rs.core.Response; -import javax.ws.rs.core.UriInfo; -import java.lang.reflect.Method; -import java.util.ArrayList; -import java.util.Collection; -import java.util.List; - -import static org.junit.Assert.fail; +import io.swagger.api.NotFoundException; +import io.swagger.api.Util; +import io.swagger.model.DCAEService; +import io.swagger.model.DCAEServiceRequest; /** * Created by mhwang on 9/25/17. @@ -58,26 +59,26 @@ import static org.junit.Assert.fail; @RunWith(PowerMockRunner.class) public class DcaeServicesApiServiceImplTests { - private final static Logger LOG = LoggerFactory.getLogger(DcaeServicesApiServiceImplTests.class); + private static final Logger log = LoggerFactory.getLogger(DcaeServicesApiServiceImplTests.class); - private DCAEServiceTypesDAO mockTypesDAO = null; - private DCAEServicesDAO mockServicesDAO = null; - private DCAEServiceComponentsDAO mockComponentsDAO = null; + private DCAEServiceTypesDAO mockTypesDao = null; + private DCAEServicesDAO mockServicesDao = null; + private DCAEServiceComponentsDAO mockComponentsDao = null; @Before public void setupClass() { - mockTypesDAO = mock(DCAEServiceTypesDAO.class); - mockServicesDAO = mock(DCAEServicesDAO.class); - mockComponentsDAO = mock(DCAEServiceComponentsDAO.class); + mockTypesDao = mock(DCAEServiceTypesDAO.class); + mockServicesDao = mock(DCAEServicesDAO.class); + mockComponentsDao = mock(DCAEServiceComponentsDAO.class); // PowerMockito does bytecode magic to mock static methods and use final classes PowerMockito.mockStatic(InventoryDAOManager.class); - InventoryDAOManager mockDAOManager = mock(InventoryDAOManager.class); + InventoryDAOManager mockDaoManager = mock(InventoryDAOManager.class); - when(InventoryDAOManager.getInstance()).thenReturn(mockDAOManager); - when(mockDAOManager.getDCAEServicesDAO()).thenReturn(mockServicesDAO); - when(mockDAOManager.getDCAEServiceComponentsDAO()).thenReturn(mockComponentsDAO); - when(mockDAOManager.getDCAEServiceTypesDAO()).thenReturn(mockTypesDAO); + when(InventoryDAOManager.getInstance()).thenReturn(mockDaoManager); + when(mockDaoManager.getDCAEServicesDAO()).thenReturn(mockServicesDao); + when(mockDaoManager.getDCAEServiceComponentsDAO()).thenReturn(mockComponentsDao); + when(mockDaoManager.getDCAEServiceTypesDAO()).thenReturn(mockTypesDao); } @Test @@ -86,10 +87,10 @@ public class DcaeServicesApiServiceImplTests { // This block is a trick to make a private method accessible for testing try { - createDCAEService = DcaeServicesApiServiceImpl.class.getDeclaredMethod("createDCAEService", DCAEServiceObject.class, - Collection.class, UriInfo.class); + createDCAEService = DcaeServicesApiServiceImpl.class.getDeclaredMethod("createDCAEService", + DCAEServiceObject.class, Collection.class, UriInfo.class); createDCAEService.setAccessible(true); - } catch(NoSuchMethodException e) { + } catch (NoSuchMethodException e) { fail("Failed to do the reflection trick to test the private method: createDCAEService"); } @@ -107,7 +108,7 @@ public class DcaeServicesApiServiceImplTests { try { DCAEService service = (DCAEService) createDCAEService.invoke(api, serviceObject, components, uriInfo); assertEquals(service.getServiceId(), serviceObject.getServiceId()); - } catch(Exception e) { + } catch (Exception e) { fail("Failed to execute the hacked createDCAEService method"); } } @@ -119,8 +120,8 @@ public class DcaeServicesApiServiceImplTests { serviceRequest.setTypeId("type-id-abc"); serviceRequest.setVnfId("vnf-id-def"); DCAEServiceObject serviceObject = new DCAEServiceObject(serviceId, serviceRequest); - when(mockServicesDAO.getByServiceId(DCAEServiceObject.DCAEServiceStatus.RUNNING, serviceId)).thenReturn(serviceObject); - when(mockComponentsDAO.getByServiceId(serviceId)).thenReturn(new ArrayList<DCAEServiceComponentObject>()); + when(mockServicesDao.getByServiceId(DCAEServiceObject.DCAEServiceStatus.RUNNING, serviceId)).thenReturn(serviceObject); + when(mockComponentsDao.getByServiceId(serviceId)).thenReturn(new ArrayList<DCAEServiceComponentObject>()); DatabusControllerClient dbcc = mock(DatabusControllerClient.class); DcaeServicesApiServiceImpl api = new DcaeServicesApiServiceImpl(dbcc); @@ -129,15 +130,15 @@ public class DcaeServicesApiServiceImplTests { try { Response response = api.dcaeServicesServiceIdGet(serviceId, uriInfo, null); assertEquals(response.getStatus(), 200); - } catch(NotFoundException e) { + } catch (NotFoundException e) { fail("Service should have been found"); } } /* - Commented this unit test because could not get past Nullpointer in the line trying to mock the explicit "bind" function - call. Mockito does not handle mocking overloaded functions well so it goes into the actual method where an member variable - called foreman is null. + Commented this unit test because could not get past Nullpointer in the line trying to mock the explicit "bind" + function call. Mockito does not handle mocking overloaded functions well so it goes into the actual method where + an member variable called foreman is null. @Test public void testDcaeServicesGet() { Handle mockHandle = mock(Handle.class); @@ -174,17 +175,17 @@ public class DcaeServicesApiServiceImplTests { @Test public void testDcaeServicesServiceIdPutMissingType() { - String serviceId = "service-id-123"; DCAEServiceRequest serviceRequest = new DCAEServiceRequest(); serviceRequest.setTypeId("type-id-abc"); serviceRequest.setVnfId("vnf-id-def"); - when(mockTypesDAO.getByTypeIdActiveOnly(serviceRequest.getTypeId())).thenReturn(null); + when(mockTypesDao.getByTypeIdActiveOnly(serviceRequest.getTypeId())).thenReturn(null); DatabusControllerClient dbcc = mock(DatabusControllerClient.class); DcaeServicesApiServiceImpl api = new DcaeServicesApiServiceImpl(dbcc); UriInfo uriInfo = new Util.FakeUriInfo(); + String serviceId = "service-id-123"; Response response = api.dcaeServicesServiceIdPut(serviceId, serviceRequest, uriInfo, null); assertEquals(response.getStatus(), 422); } @@ -196,7 +197,7 @@ public class DcaeServicesApiServiceImplTests { serviceRequest.setTypeId("type-id-abc"); serviceRequest.setVnfId("vnf-id-def"); DCAEServiceObject serviceObject = new DCAEServiceObject(serviceId, serviceRequest); - when(mockServicesDAO.getByServiceId(DCAEServiceObject.DCAEServiceStatus.RUNNING, serviceId)).thenReturn(serviceObject); + when(mockServicesDao.getByServiceId(DCAEServiceObject.DCAEServiceStatus.RUNNING, serviceId)).thenReturn(serviceObject); DatabusControllerClient dbcc = mock(DatabusControllerClient.class); DcaeServicesApiServiceImpl api = new DcaeServicesApiServiceImpl(dbcc); @@ -205,10 +206,10 @@ public class DcaeServicesApiServiceImplTests { try { Response response = api.dcaeServicesServiceIdDelete(serviceId, null); assertEquals(response.getStatus(), 200); - } catch(NotFoundException e) { + } catch (NotFoundException e) { fail("Should have NOT thrown a NotFoundException"); - } catch(Exception e) { - LOG.error("Unexpected exception", e); + } catch (Exception e) { + log.error("Unexpected exception", e); fail("Unexpected exception"); } } @@ -216,7 +217,7 @@ public class DcaeServicesApiServiceImplTests { @Test public void testDcaeServicesServiceIdDeleteMissingService() { String serviceId = "service-id-123"; - when(mockServicesDAO.getByServiceId(DCAEServiceObject.DCAEServiceStatus.RUNNING, serviceId)).thenReturn(null); + when(mockServicesDao.getByServiceId(DCAEServiceObject.DCAEServiceStatus.RUNNING, serviceId)).thenReturn(null); DatabusControllerClient dbcc = mock(DatabusControllerClient.class); DcaeServicesApiServiceImpl api = new DcaeServicesApiServiceImpl(dbcc); @@ -225,10 +226,10 @@ public class DcaeServicesApiServiceImplTests { try { api.dcaeServicesServiceIdDelete(serviceId, null); fail("Should have thrown a NotFoundException"); - } catch(NotFoundException e) { - LOG.info("NotFoundException successfully thrown"); - } catch(Exception e) { - LOG.error("Unexpected exception", e); + } catch (NotFoundException e) { + log.info("NotFoundException successfully thrown"); + } catch (Exception e) { + log.error("Unexpected exception", e); fail("Unexpected exception"); } } diff --git a/src/test/java/io/swagger/api/impl/DcaeServicesGroupbyApiServiceImplTests.java b/src/test/java/io/swagger/api/impl/DcaeServicesGroupbyApiServiceImplTests.java index 0ae2c3a..c2d0944 100644 --- a/src/test/java/io/swagger/api/impl/DcaeServicesGroupbyApiServiceImplTests.java +++ b/src/test/java/io/swagger/api/impl/DcaeServicesGroupbyApiServiceImplTests.java @@ -18,7 +18,13 @@ package io.swagger.api.impl;/*- * ============LICENSE_END========================================================= */ -import io.swagger.api.Util; +import static org.junit.Assert.assertEquals; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; + +import javax.ws.rs.core.Response; +import javax.ws.rs.core.UriInfo; + import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; @@ -27,13 +33,7 @@ import org.powermock.api.mockito.PowerMockito; import org.powermock.core.classloader.annotations.PrepareForTest; import org.powermock.modules.junit4.PowerMockRunner; -import javax.ws.rs.core.Response; -import javax.ws.rs.core.UriInfo; - -import static org.junit.Assert.assertEquals; -import static org.mockito.Matchers.any; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.when; +import io.swagger.api.Util; /** * Created by mhwang on 9/27/17. @@ -46,9 +46,9 @@ public class DcaeServicesGroupbyApiServiceImplTests { public void setupClass() { // PowerMockito does bytecode magic to mock static methods and use final classes PowerMockito.mockStatic(InventoryDAOManager.class); - InventoryDAOManager mockDAOManager = mock(InventoryDAOManager.class); + InventoryDAOManager mockDaoManager = mock(InventoryDAOManager.class); - when(InventoryDAOManager.getInstance()).thenReturn(mockDAOManager); + when(InventoryDAOManager.getInstance()).thenReturn(mockDaoManager); } @Test @@ -62,9 +62,9 @@ public class DcaeServicesGroupbyApiServiceImplTests { } /* - Commented this unit test because could not get past Nullpointer in the line trying to mock the explicit "bind" function - call. Mockito does not handle mocking overloaded functions well so it goes into the actual method where an member variable - called foreman is null. + Commented this unit test because could not get past Nullpointer in the line trying to mock the explicit "bind" + function call. Mockito does not handle mocking overloaded functions well so it goes into the actual method where + an member variable called foreman is null. @Test public void testNoResults() { DcaeServicesGroupbyApiServiceImpl api = new DcaeServicesGroupbyApiServiceImpl(); |