@Test public void getAll() { ProviderRestService tested = getTested(); // case - OK ESDataOnlyResponse res = new ESDataOnlyResponse(null); Mockito.when(tested.entityService.getAll(10, 12, ProviderRestService.FIELDS_TO_REMOVE)) .thenReturn(res); Assert.assertEquals(res, tested.getAll(10, 12)); Mockito.verify(tested.entityService).getAll(10, 12, ProviderRestService.FIELDS_TO_REMOVE); Mockito.verifyNoMoreInteractions(tested.entityService); // case - OK, null returned Mockito.reset(tested.entityService); Mockito.when(tested.entityService.getAll(10, 12, ProviderRestService.FIELDS_TO_REMOVE)) .thenReturn(null); Assert.assertEquals(null, tested.getAll(10, 12)); Mockito.verify(tested.entityService).getAll(10, 12, ProviderRestService.FIELDS_TO_REMOVE); Mockito.verifyNoMoreInteractions(tested.entityService); }
@Test(expected = RuntimeException.class) public void getAll_exceptionFromService() { ProviderRestService tested = getTested(); // case - error Mockito.reset(tested.entityService); Mockito.when(tested.entityService.getAll(10, 12, ProviderRestService.FIELDS_TO_REMOVE)) .thenThrow(new RuntimeException("my exception")); TestUtils.assertResponseStatus(tested.getAll(10, 12), Status.INTERNAL_SERVER_ERROR); Mockito.verify(tested.entityService).getAll(10, 12, ProviderRestService.FIELDS_TO_REMOVE); Mockito.verifyNoMoreInteractions(tested.entityService); }