OcelotContext { public boolean isUserInRole(String role) { HttpServletRequest request = getRequest(); if (request != null) { return request.isUserInRole(role); } logger.warn("Fail to get userInRole, HttpServletRequest is null in threadLocal"); return false; }  HttpSession getHttpSession(); Locale getLocale(); void setLocale(Locale locale); boolean isUserInRole(String role); Principal getPrincipal();  }
@Test public void testIsUserInRole() { when(instance.getRequest()).thenReturn(null).thenReturn(request); when(request.isUserInRole("OK")).thenReturn(Boolean.TRUE); when(request.isUserInRole("NOK")).thenReturn(Boolean.FALSE); boolean result = instance.isUserInRole("OK"); assertThat(result).isEqualTo(Boolean.FALSE); result = instance.isUserInRole("OK"); assertThat(result).isEqualTo(Boolean.TRUE); result = instance.isUserInRole("NOK"); assertThat(result).isEqualTo(Boolean.FALSE); }