在post api上执行mockMvc时出错。因为在这篇文章中,调用我的服务层会检查客户是否存在。因此,它给我的客户找不到错误。我怎么能在这里嘲笑客户呢?
final String PAYMENT_METHOD = "/customer/"+customerId+"/paymentMethod";
RequestBuilder request = MockMvcRequestBuilders.post(PAYMENT_METHOD).content(JsonUtils.toJson(paymentMethodDto))
.contentType(MediaType.APPLICATION_JSON)
.accept((MediaType.APPLICATION_JSON));
MvcResult result = mockMvc.perform(request).andExpect(status().isCreated()).andReturn();
Assert.assertEquals(result.getResponse().getStatus(), HttpStatus.CREATED.value());
ResponseEntity<PaymentMethodRes> responseEntity = paymentMethodController.addPaymentMethod(customerId, paymentMethodDto);
assertNotNull(responseEntity);发布于 2021-02-26 17:28:27
这应该是可行的
Mockito.when(customerService.findCustumerbyId(customerId).thenReturn(new Customer());`https://stackoverflow.com/questions/66383083
复制相似问题