コード例 #1
0
 @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");
 }
コード例 #2
0
  @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);
  }