@Test(expected = ClientErrorException.class) public void testGetReturns403() throws Exception { // Arrange Mockito.when(response.getStatus()).thenReturn(403); Mockito.when(response.getStatusInfo().getFamily()) .thenReturn(Response.Status.Family.CLIENT_ERROR); Mockito.when(builder.get()).thenReturn(response); // Act classUnderTest.getOne(builder); // Assert fail("Should have thrown an Exception"); }
@Test @SuppressWarnings("unchecked") public void testDeleteReturns200() throws Exception { // Arrange Mockito.when(response.getStatus()).thenReturn(200); Mockito.when(response.readEntity(Mockito.any(Class.class))).thenReturn(null); Mockito.when(response.getStatusInfo().getFamily()) .thenReturn(Response.Status.Family.SUCCESSFUL); Mockito.when(builder.delete(Response.class)).thenReturn(response); // Act Issue deleteOne = classUnderTest.deleteOne(builder); // Assert assertEquals(null, deleteOne); }
@Test @SuppressWarnings("unchecked") public void testPutReturns204() throws Exception { // Arrange Mockito.when(response.getStatus()).thenReturn(204); Mockito.when(response.readEntity(Mockito.any(Class.class))).thenReturn(entity); Mockito.when(response.getStatusInfo().getFamily()) .thenReturn(Response.Status.Family.SUCCESSFUL); Mockito.when(builder.put(entity, Response.class)).thenReturn(response); // Act Issue putOne = classUnderTest.putOne(builder, entity); // Assert assertEquals(null, putOne); }
@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); }
@Test @SuppressWarnings("unchecked") public void testGetReturns200() throws Exception { // Arrange Issue expected = new Issue(new Project("1"), "sum", "desc", new IssueType("1", "A")); Mockito.when(response.getStatus()).thenReturn(200); String jsonstring = ClientUtils.getGson().toJson(expected); Mockito.when(response.readEntity(Mockito.any(Class.class))).thenReturn(jsonstring); Mockito.when(builder.get()).thenReturn(response); // Act Issue actual = classUnderTest.getOne(builder); // Assert assertEquals(expected, actual); }