WsUserContext implements UserContext { @Override public boolean isUserInRole(String role) { if (null != handshakeRequest) { return handshakeRequest.isUserInRole(role); } return false; } WsUserContext(HandshakeRequest handshakeRequest); @Override Principal getPrincipal(); @Override boolean isUserInRole(String role);  }
@Test public void testIsUserInRole() { System.out.println("isUserInRole"); HandshakeRequest handshakeRequest = mock(HandshakeRequest.class); when(handshakeRequest.isUserInRole(eq("OK"))).thenReturn(true); when(handshakeRequest.isUserInRole(eq("NOK"))).thenReturn(false); WsUserContext instance = new WsUserContext(handshakeRequest); boolean result = instance.isUserInRole("OK"); assertThat(result).isTrue(); result = instance.isUserInRole("NOK"); assertThat(result).isFalse(); }
@Test public void testIsUserInRoleNoHandshakeRequest() { System.out.println("isUserInRole"); WsUserContext instance = new WsUserContext(null); boolean result = instance.isUserInRole("OK"); assertThat(result).isFalse(); result = instance.isUserInRole("NOK"); assertThat(result).isFalse(); }