I have many hours struggling with this problem.
I have the following line of code:
Mockito.doReturn(new ErrorResponse()).when(mockobjectMapper).readValue("Test", ErrorResponse.class);
The method "readValue" spits an error:
Unhandled exceptions: com.fasterxml.jackson.core.JsonProcessingException, com.fasterxml.jackson.databind.JsonMappingException
I can surround it with try-catch block, but I have many different classes which will have the same catch. For example:
try {
Mockito.doReturn(someObject1).when(someMock).execute(Mockito.eq(someObject2));
} catch (SomeInterfaceException e) {
// Will never be reached
log.error("{}", StructuredArguments.fields(e));
}
How can I move the try-catch block to an utils class with a method which will receive the line of code which spits the error?