执行 MockMvc:在 post api 上执行 mockMvc 时出错
performing MockMvc : getting error while performing mockMvc on post api
在 post api 上执行 mockMvc 时出错。
因为在这个 post 中调用我的服务层检查客户是否存在。
所以它给我客户未找到错误。
我怎么能在这里嘲笑客户?
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);
应该可行
Mockito.when(customerService.findCustumerbyId(customerId).thenReturn(new Customer());`
在 post api 上执行 mockMvc 时出错。 因为在这个 post 中调用我的服务层检查客户是否存在。 所以它给我客户未找到错误。 我怎么能在这里嘲笑客户?
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);
应该可行
Mockito.when(customerService.findCustumerbyId(customerId).thenReturn(new Customer());`