### Question:
TrainServiceImpl implements TrainService { @Override public boolean update(TrainType trainType, HttpHeaders headers) { boolean result = false; if (repository.findById(trainType.getId()) != null) { TrainType type = new TrainType(trainType.getId(), trainType.getEconomyClass(), trainType.getConfortClass()); type.setAverageSpeed(trainType.getAverageSpeed()); repository.save(type); 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 testUpdate1() { TrainType trainType = new TrainType(); Mockito.when(repository.findById(Mockito.anyString())).thenReturn(trainType); Mockito.when(repository.save(Mockito.any(TrainType.class))).thenReturn(null); boolean result = trainServiceImpl.update(trainType, headers); Assert.assertTrue(result); }
@Test public void testUpdate2() { TrainType trainType = new TrainType(); Mockito.when(repository.findById(Mockito.anyString())).thenReturn(null); boolean result = trainServiceImpl.update(trainType, headers); Assert.assertFalse(result); }