### Question:
TrainServiceImpl implements TrainService { @Override public TrainType retrieve(String id, HttpHeaders headers) { if (repository.findById(id) == null) { return null; } else { return repository.findById(id); } }  @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 testRetrieve1() { Mockito.when(repository.findById(Mockito.anyString())).thenReturn(null); TrainType result = trainServiceImpl.retrieve("id", headers); Assert.assertNull(result); }
@Test public void testRetrieve2() { TrainType trainType = new TrainType(); Mockito.when(repository.findById(Mockito.anyString())).thenReturn(trainType); TrainType result = trainServiceImpl.retrieve("id", headers); Assert.assertNotNull(result); }