I use JDBI in my project and I have a unit test like this:
@Test
public void testGetUser() {
when(jdbi.withExtension(any(), any())).thenReturn(new ArrayList<>());
List<User> users = dao.getUsers();
assertTrue(users.isEmpty());
}
For reference, JDBI's withExtension
method is declared like this:
public <R, E, X extends Exception> R withExtension(Class<E> extensionType, ExtensionCallback<R, E, X> callback)
And you can use it like this (extracted from JDBI docs):
// Jdbi implements your interface based on annotations
List<User> userNames = jdbi.withExtension(UserDao.class, dao -> {
dao.createTable();
dao.insertPositional(0, "Alice");
dao.insertPositional(1, "Bob");
dao.insertNamed(2, "Clarice");
dao.insertBean(new User(3, "David"));
return dao.listUsers();
});
The method dao.getUsers()
doesn't do anything exceptional besides accessing the DB using JDBI and catches any exceptions and re-throws them as a custom exception that extends from Exception
.
So far so good, all as expected, as I have:
- IntelliJ can understand the test and compile and runs it, no problems.
- I am using Maven and I can also run
mvn build
in the terminal without errors.
The problem:
In Eclipse, I have an error in testGetUser()
: Unhandled exception type Exception
in the line when(jdbi.withExtension(any(), any())).thenReturn(new ArrayList<>());
.
I can't figure out why but my guess is that it is getting confused because of the Generics use.
I'd appreciate any ideas!