If I have a method I need to test which relies on queries made with criteriaBuilder and criteriaQuery how can I do that? The problem I am having is that in the entityManager in the test environment will be null. mocking EntityManager.class will just give me an entity manager where the criteria builder is null. Using where(...).thenReturn()... would defeat the purpose of the test because it relies on the criteriaQuery.
CodePudding user response:
It is not necessary that Entity Manager will be null. You can use an H2 database with some initial data for test case execution with a scope of test. You can also refer the link for help. link