我一直在网上寻找,我似乎无法找到解决问题的方法。我有一个如下所示的集成测试,它应该返回字符串“Lossrates calculated successfully”,而是返回一个< []>空白字符串。
@Test
public void test() throws Exception {
String name = "mockName";
String date = new Date().toString();
LossrateRequest lossrateRequest = new LossrateRequest();
lossrateRequest.setAsOfDate(new Date().toString());
lossrateRequest.setName(name);
Date asOfDate = new SimpleDateFormat("EEE MMM d HH:mm:ss zzz yyyy").parse(date);
boolean testStatus = lossrateRequest.getName().isEmpty();
String expected = "Lossrates calculated successfully.";
Mockito.when(lossrateCalculationService.calculateHistory(name, asOfDate)).thenReturn(testStatus);
Mockito.when(lossrateService.saveGenerated(name, asOfDate, lossrateService.numOfRowsInHistoricalLoss()))
.thenReturn(testStatus);
RequestBuilder requestBuilder = MockMvcRequestBuilders.post("/api/historical-loss/generate")
.accept(MediaType.APPLICATION_JSON);
MvcResult result = mockMvc.perform(requestBuilder).andReturn();
assertEquals(expected, result.getResponse().getContentAsString());
}
我正在考虑由于MvcResult
行而发生的事情,但我在网上到处都有andReturn()
空白,因此我不知道为什么它会返回空白。