### Question:
EndSession extends ServerResource { @Inject public EndSession(OAuth2RequestFactory<?, Request> requestFactory, OpenIDConnectEndSession openIDConnectEndSession, ExceptionHandler exceptionHandler, ClientRegistrationStore clientRegistrationStore) { this.requestFactory = requestFactory; this.openIDConnectEndSession = openIDConnectEndSession; this.exceptionHandler = exceptionHandler; this.clientRegistrationStore = clientRegistrationStore; } @Inject  EndSession(OAuth2RequestFactory<?, Request> requestFactory, OpenIDConnectEndSession openIDConnectEndSession,
            ExceptionHandler exceptionHandler, ClientRegistrationStore clientRegistrationStore); @Get Representation endSession();  }### Answer:
@Test public void shouldAttemptEndSessionAndReturnRedirectAttempt() throws Exception { String requestedUri = "http: String registeredUri = "http: when(oAuth2Request.getParameter(OAuth2Constants.Params.POST_LOGOUT_REDIRECT_URI)).thenReturn(requestedUri); when(client.getPostLogoutRedirectUris()).thenReturn(Collections.singleton(new URI(registeredUri))); Representation result = endSession.endSession(); verify(openIDConnectEndSession, times(1)).endSession(any(String.class)); assertThat(result).isNotNull(); }
@Test public void shouldAttemptEndSessionAndFailMismatchRedirect() throws Exception { String requestedUri = "http: String registeredUri = "http: when(oAuth2Request.getParameter(OAuth2Constants.Params.POST_LOGOUT_REDIRECT_URI)).thenReturn(requestedUri); when(client.getPostLogoutRedirectUris()).thenReturn(Collections.singleton(new URI(registeredUri))); OAuth2RestletException exception = null; try { endSession.endSession(); } catch (OAuth2RestletException e) { exception = e; } verify(openIDConnectEndSession, times(1)).endSession(any(String.class)); assertThat(exception).isNotNull(); assertThat(exception.getError()).isEqualTo("redirect_uri_mismatch"); }
@Test public void shouldAttemptEndSessionAndFailRelativeRedirect() throws Exception { String requestedUri = "example.com"; String registeredUri = "http: when(oAuth2Request.getParameter(OAuth2Constants.Params.POST_LOGOUT_REDIRECT_URI)).thenReturn(requestedUri); when(client.getPostLogoutRedirectUris()).thenReturn(Collections.singleton(new URI(registeredUri))); OAuth2RestletException exception = null; try { endSession.endSession(); } catch (OAuth2RestletException e) { exception = e; } verify(openIDConnectEndSession, times(1)).endSession(any(String.class)); assertThat(exception).isNotNull(); assertThat(exception.getError()).isEqualTo("relative_redirect_uri"); }
@Test public void shouldAttemptEndSessionAndNotRedirect() throws Exception { String requestedUri = ""; String registeredUri = "http: when(oAuth2Request.getParameter(OAuth2Constants.Params.POST_LOGOUT_REDIRECT_URI)).thenReturn(requestedUri); when(client.getPostLogoutRedirectUris()).thenReturn(Collections.singleton(new URI(registeredUri))); Representation result = endSession.endSession(); verify(openIDConnectEndSession, times(1)).endSession(any(String.class)); assertThat(result).isNull(); }