I have to make fun of the next security step using EasyMock or UnitilsMock. Could you suggest a way to achieve this?
String id = context.getCallerPrincipal().getName();
This step is security related. Therefore, I canβt create the Principle object and do about the two-level level. I know that mockito easily handles such things as follows:
@Mock(answer = Answers.RETURNS_DEEP_STUBS) SessionContext mockContext;
But I need a similar solution using EasyMock or Unitils Mock. The full code I want unit test is below
@Override @PermitAll public List<Employee> findAll() { boolean isAdmin = context.isCallerInRole(Roles.ADMIN); if (isAdmin) { return super.findAll(); } else { String id = context.getCallerPrincipal().getName(); Query query = getEntityManager().createNamedQuery("findEmployeeById"); query.setParameter("employeeId", id); return query.getResultList(); } }
-Thanks
source share