From 82627283fd017062439d6d898afba9127d224b1d Mon Sep 17 00:00:00 2001 From: Varun Gudisena Date: Tue, 3 Oct 2017 18:18:12 -0500 Subject: Add unit test cases Add unit test cases Issue-Id: DMAAP-151 Change-Id: I5f70774ad35aef71aa6f00b2433224d113f4f85b Signed-off-by: Varun Gudisena --- .../att/nsa/dmaap/DMaaPWebExceptionMapperTest.java | 41 +++++++++++----------- 1 file changed, 20 insertions(+), 21 deletions(-) (limited to 'src/test/java') diff --git a/src/test/java/com/att/nsa/dmaap/DMaaPWebExceptionMapperTest.java b/src/test/java/com/att/nsa/dmaap/DMaaPWebExceptionMapperTest.java index 22c31c9..cb1edb5 100644 --- a/src/test/java/com/att/nsa/dmaap/DMaaPWebExceptionMapperTest.java +++ b/src/test/java/com/att/nsa/dmaap/DMaaPWebExceptionMapperTest.java @@ -32,9 +32,22 @@ import javax.ws.rs.ServiceUnavailableException; import org.junit.After; import org.junit.Before; import org.junit.Test; - +import org.junit.runner.RunWith; +import org.mockito.InjectMocks; +import org.mockito.Mock; +import org.powermock.api.mockito.PowerMockito; +import org.powermock.modules.junit4.PowerMockRunner; + +import com.att.nsa.cambria.exception.DMaaPErrorMessages; +@RunWith(PowerMockRunner.class) public class DMaaPWebExceptionMapperTest { + @InjectMocks + DMaaPWebExceptionMapper mapper; + + @Mock + DMaaPErrorMessages msgs; + @Before public void setUp() throws Exception { } @@ -46,8 +59,6 @@ public class DMaaPWebExceptionMapperTest { @Test public void testToResponse() { - DMaaPWebExceptionMapper mapper = new DMaaPWebExceptionMapper(); - try { mapper.toResponse(null); } catch (NullPointerException e) { @@ -58,9 +69,7 @@ public class DMaaPWebExceptionMapperTest { @Test public void testToResponseNotFoundException() { - - DMaaPWebExceptionMapper mapper = new DMaaPWebExceptionMapper(); - + PowerMockito.when(msgs.getNotFound()).thenReturn("Not found"); try { mapper.toResponse(new NotFoundException()); } catch (NullPointerException e) { @@ -71,9 +80,7 @@ public class DMaaPWebExceptionMapperTest { @Test public void testToResponseInternalServerErrorException() { - - DMaaPWebExceptionMapper mapper = new DMaaPWebExceptionMapper(); - + PowerMockito.when(msgs.getNotFound()).thenReturn("Not found"); try { mapper.toResponse(new InternalServerErrorException()); @@ -85,9 +92,7 @@ public class DMaaPWebExceptionMapperTest { @Test public void testToResponseNotAuthorizedException() { - - DMaaPWebExceptionMapper mapper = new DMaaPWebExceptionMapper(); - + PowerMockito.when(msgs.getNotFound()).thenReturn("Not found"); try { mapper.toResponse(new NotAuthorizedException("Error", "Error")); @@ -99,9 +104,7 @@ public class DMaaPWebExceptionMapperTest { @Test public void testToResponseBadRequestException() { - - DMaaPWebExceptionMapper mapper = new DMaaPWebExceptionMapper(); - + PowerMockito.when(msgs.getNotFound()).thenReturn("Not found"); try { mapper.toResponse(new BadRequestException()); @@ -113,9 +116,7 @@ public class DMaaPWebExceptionMapperTest { @Test public void testToResponseNotAllowedException() { - - DMaaPWebExceptionMapper mapper = new DMaaPWebExceptionMapper(); - + PowerMockito.when(msgs.getNotFound()).thenReturn("Not found"); try { mapper.toResponse(new NotAllowedException("Not Allowed")); @@ -127,9 +128,7 @@ public class DMaaPWebExceptionMapperTest { @Test public void testToResponseServiceUnavailableException() { - - DMaaPWebExceptionMapper mapper = new DMaaPWebExceptionMapper(); - + PowerMockito.when(msgs.getNotFound()).thenReturn("Not found"); try { mapper.toResponse(new ServiceUnavailableException()); -- cgit 1.2.3-korg