Reputation: 1
I need to be able to mock a table in mockito for testing queries.
i.e. I have a Predicate
public Preciate makePredicate(){
return criteriaBuilder.like(tableRoot.get(col), "test");
}
and I want to be able to test something like this
criteriaQuery.where(makePredicate());
ResultSet res = criteriaQuery.getResultSet();
and verify values in res
I need to be able to mock a table of a database and be able to insert mocked values into the table but I am not sure how to do that.
Upvotes: 0
Views: 1702
Reputation: 22603
Mocking a table is the wrong level of abstraction for your tests, unless you are writing some kind of very low level DB library.
In your case you would either
I would personally cover in an integration test with an in memory database.
Generally speaking you don't want to mock the JDBC library or the database as that would be impossible and would require an immense knowledge of the underlying calls between JDBC and the DB.
Upvotes: 3