  @Test
  public void testUnauthorized() throws ServletException, AuthenticationException, IOException {

    JerseyEnvironment      jerseyEnvironment = mock(JerseyEnvironment.class     );
    WebSocketEnvironment   environment       = mock(WebSocketEnvironment.class  );
    WebSocketAuthenticator authenticator     = mock(WebSocketAuthenticator.class);
    ServletUpgradeRequest  request           = mock(ServletUpgradeRequest.class );
    ServletUpgradeResponse response          = mock(ServletUpgradeResponse.class);

    when(environment.getAuthenticator()).thenReturn(authenticator);
    when(authenticator.authenticate(eq(request))).thenReturn(new WebSocketAuthenticator.AuthenticationResult<>(Optional.empty(), true));
    when(environment.jersey()).thenReturn(jerseyEnvironment);

    WebSocketResourceProviderFactory factory    = new WebSocketResourceProviderFactory(environment);
    Object                           connection = factory.createWebSocket(request, response);

    assertNull(connection);
    verify(response).sendForbidden(eq("Unauthorized"));
    verify(authenticator).authenticate(eq(request));
  }