Skip to content

Commit

Permalink
Add try/catch to Jdbi#withHandle inside Mockito#when in Jdbi3HelpersT…
Browse files Browse the repository at this point in the history
…est (#462)

Add a try/catch inside the FindDatabasePlugin#whenWithHandleCalled method
to make VSCode (I guess really the Red Hat Java extension) happy. For some reason,
it always complains that about "Unhandled exception type Exception Java(16777384)".

It apparently "thinks" the exception thrown by the Jdbi#withHandle method,
which is called inside the Mockito#when method, must be handled.

Neither Maven nor IntelliJ have any problems with the code, and they compile it
and run it just fine.

But whenever I need to pop into Gitpod and do something, this code is flagged
by VSCode/Red Hat Java Extension. So, the easiest thing to do is just appease it
and add a try/catch around that code. If an exception is thrown, wrap with a
RuntimeException.
  • Loading branch information
sleberknight authored Feb 6, 2024
1 parent 9da30f7 commit ce4ef85
Showing 1 changed file with 5 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,11 @@ void shouldReturnEmptyWhenExceptionThrownFindingPlugin() {

@SuppressWarnings("unchecked")
private OngoingStubbing<Object> whenWithHandleCalled() {
return when(jdbi.withHandle(any(HandleCallback.class)));
try {
return when(jdbi.withHandle(any(HandleCallback.class)));
} catch (Exception e) {
throw new RuntimeException(e);
}
}
}

Expand Down

0 comments on commit ce4ef85

Please sign in to comment.