performingmockmvc:postapi上执行mockmvc时出错

gdrx4gfi  于 2021-07-13  发布在  Java
关注(0)|答案(1)|浏览(395)

在post api上执行mockmvc时出错。因为在这个post call中,我的服务层检查客户是否存在。所以这是给我的客户找不到的错误。我怎么能在这里嘲笑顾客?

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);
dauxcl2d

dauxcl2d1#

这应该管用

Mockito.when(customerService.findCustumerbyId(customerId).thenReturn(new Customer());`

相关问题