How to get a JsonProcessingException using Jackson

后端 未结 8 1245
醉梦人生
醉梦人生 2021-01-07 16:35

Might be a strange question but indeed I would like to achieve a a bit more coverage on my tests and although I coded against a JsonProcessingException I can\'t

8条回答
  •  孤独总比滥情好
    2021-01-07 17:16

    just in case this may help someone, when i was unit testing for a JsonProcessingException i kept getting this error:

    JsonProcessingException has protected access in com.fasterxml.jackson...
    

    this was my code

    // error is on the below line
    JsonProcessingException e = new JsonProcessingException("borked");
    
    doThrow(e).when(classMock).methodToMock(any(), any());
    

    i found out i just needed to add "{}" as such

    JsonProcessingException e = new JsonProcessingException("borked") {};
    

提交回复
热议问题