Trying to create a unit test for an elastic search exception handler that uses ResponseException but having trouble setting up the object. Mocking doesn’t work as ResponseException is a final class.
JavaScript
x
private ResponseException responseException = new ResponseException(response);
produces the following compilation error: Unhandled exception: java.io.IOException
Any help is appreciated.
Advertisement
Answer
Typical Java trick for this case:
JavaScript
private ResponseException responseException = create(response);
private ResponseException create(Response response) {
try {
return new ResponseException(response);
} catch(Exception ex) {
throw new RuntimeException(ex);
}
}