[英]performing MockMvc : getting error while performing mockMvc on post api
在 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);
那应该工作
Mockito.when(customerService.findCustumerbyId(customerId).thenReturn(new Customer());`
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.