How to mock ObjectMapper.readValue() using mockito

后端 未结 3 1725
野趣味
野趣味 2021-02-20 17:29

I\'m testing a service layer and not sure how to mock ObjectMapper().readValue in that class. I\'m fairly new to mockito and could figure out how to do

3条回答
  •  北海茫月
    2021-02-20 18:04

    Problem is with the this line where you are mocking the call to objectmapper.

    Mockito.when((objMapper).readValue(“”,ConfigDetail.class)).thenReturn(configDetail);
    

    Correct syntax is

    Mockito.when(objMapper.readValue(“”,ConfigDetail.class)).thenReturn(configDetail);

    Notice the bracket position. When using Spy or Verify, the bracket position is diff. then when using when-then syntax.

提交回复
热议问题