@Test(expected = ClientErrorException.class) public void testPostReturns400() throws Exception { // Arrange Mockito.when(response.getStatus()).thenReturn(400); Mockito.when(response.getStatusInfo().getFamily()) .thenReturn(Response.Status.Family.CLIENT_ERROR); Mockito.when(builder.post(entity, Response.class)).thenReturn(response); // Act classUnderTest.postOne(builder, expected); // Assert fail("Should have thrown an Exception"); }
@Test @SuppressWarnings("unchecked") public void testPostReturns200() throws Exception { Mockito.when(response.getStatus()).thenReturn(200); Mockito.when(response.getStatusInfo().getFamily()) .thenReturn(Response.Status.Family.SUCCESSFUL); Mockito.when(response.readEntity(Mockito.any(Class.class))).thenReturn(jsonstring); Mockito.when(builder.post(entity, Response.class)).thenReturn(response); // Act Issue actual = classUnderTest.postOne(builder, expected); // Assert assertEquals(expected, actual); }