0

@Repository public class DAOImpl extends GenericDaoImpl implements SomeDAO {

@Autowired
EntityManager em;

@Override
public List<PropertyURL> getProperties(String env) throws Exception{
    List<String> inParam = new ArrayList<>();
    inParam.add(env);
    Map<String, Object> params = new HashMap<>();
    params.put(ProEnum.ENV.getProperty(), inParam);
    List<PropertyURL> URL = null;
    String query = "PropertyURL.getProperty";
    URL = executeNamedQuery(query, params);
    return URL;
}

How can i mock executeNamedQuery(query, params) call and return some thing Ex:Mockito.when(entityManagerMock.merge(Mockito.any())).thenReturn(someObject);

Siva Sai kiran
  • 47
  • 1
  • 10
  • Before trying to mock an `EntityManager`, I'd ask myself if it wouldn't be better to test a component that interacts with JPA directly using integration tests. If you mock out `executeNamedQuery` and only run a unit test, how are you going to verify that your query works? – crizzis Nov 11 '20 at 19:31
  • We have both integration tests and unit tests,but for unit tests we need to cover the whole method to see the flow is going as expected. – Siva Sai kiran Nov 11 '20 at 20:23

0 Answers0