У меня есть проект Spring Boot, который я тестирую, и у меня есть метод get в контроллере:
@GetMapping("/updatecrime/{id}")
public String updateCrime(@PathVariable Long id) {
Crime oldCrime = new Crime(id);
this.service.addCrime(id, oldCrime);
Crime newCrime = new Crime(oldCrime.getId(), oldCrime.getZipCode(), oldCrime.getTotPopulation(),
oldCrime.getMedianAge(), oldCrime.getTotMales(), 10, oldCrime.getTotHouseholds(),
oldCrime.getAvgHouseholdSize());
return new Gson().toJson(this.service.updateCrime(id, oldCrime, newCrime));
}
Я проверил охват моих тестов, и весь этот метод покрыт ожидаемым для этой последней строки:
return new Gson().toJson(this.service.updateCrime(id, oldCrime, newCrime))
Какое утверждение мне нужно, чтобы покрыть это? Это мой тест по методу:
this.objectMapper = new ObjectMapper();
try {
ResultActions resultActions = this.mvc
.perform(MockMvcRequestBuilders.get("/updatecrime/5"));
MvcResult result = resultActions.andReturn();
String contentString = result.getResponse().getContentAsString();
Crime crime = objectMapper.readValue(contentString, Crime.class);
assertTrue(crime.getTotFemales() == 10);
} catch (Exception e) {
e.printStackTrace();
}