@Test public void create() throws AppException { SampleEntity sample = createSampleEntity(ID, "IPI"); Mockito.when(repository.save(sample)).thenReturn(createSampleEntity(ID, "IPI")); SampleEntity newSample = service.create(sample); Mockito.verify(repository).save(sample); MatcherAssert.assertThat(newSample.id, Matchers.equalTo(ID)); }
@Test(expected = AppException.class) public void createWithError() throws AppException { when(repository.save(createSampleEntity(ID, null))) .thenThrow(new IllegalArgumentException("Error")); service.create(createSampleEntity(ID, null)); }