WsUserContext implements UserContext { @Override public Principal getPrincipal() { if (null == principal) { principal = principalTools.getPrincipal(handshakeRequest); } return principal; } WsUserContext(HandshakeRequest handshakeRequest); @Override Principal getPrincipal(); @Override boolean isUserInRole(String role);  }
@Test public void testGetPrincipal() { System.out.println("getPrincipal"); Principal principal = mock(Principal.class); PrincipalTools principalTools = mock(PrincipalTools.class); HandshakeRequest handshakeRequest = mock(HandshakeRequest.class); when(principalTools.getPrincipal(eq(handshakeRequest))).thenReturn(principal); WsUserContext instance = new WsUserContext(handshakeRequest); instance.principalTools = principalTools; Principal result = instance.getPrincipal(); assertThat(result).isNotNull(); assertThat(result).isEqualTo(principal); }