### Question:
TrainServiceImpl implements TrainService { @Override public boolean delete(String id, HttpHeaders headers) { boolean result = false; if (repository.findById(id) != null) { repository.deleteById(id); result = true; } return result; }  @Override boolean create(TrainType trainType, HttpHeaders headers); @Override TrainType retrieve(String id, HttpHeaders headers); @Override boolean update(TrainType trainType, HttpHeaders headers); @Override boolean delete(String id, HttpHeaders headers); @Override List<TrainType> query(HttpHeaders headers);  }### Answer:
@Test public void testDelete1() { TrainType trainType = new TrainType(); Mockito.when(repository.findById(Mockito.anyString())).thenReturn(trainType); Mockito.doNothing().doThrow(new RuntimeException()).when(repository).deleteById(Mockito.anyString()); boolean result = trainServiceImpl.delete("id", headers); Assert.assertTrue(result); }
@Test public void testDelete2() { Mockito.when(repository.findById(Mockito.anyString())).thenReturn(null); boolean result = trainServiceImpl.delete("id", headers); Assert.assertFalse(result); }