### Question:
SessionAuthDelegate implements RequestAuthorizer { protected Application validateAndGetApplication(Map<String,String> params) throws ErrorEventException { String clientId = params.get(OAuthUtil.ATTR_CLIENT_ID); if(StringUtils.isBlank(clientId)) { throw new ErrorEventException(Errors.CODE_MISSING_PARAM, "Missing or invalid client_id"); } Application app = appRegistry.getApplication(params.get(OAuthUtil.ATTR_CLIENT_ID)); if(app == null) { throw new ErrorEventException(Errors.CODE_MISSING_PARAM, "Missing or invalid client_id"); } if(app.isSendsRedirectQueryParam()) { String redirectUri = params.get(OAuthUtil.ATTR_REDIRECT_URI); if(StringUtils.isBlank(redirectUri)) { throw new ErrorEventException(Errors.CODE_MISSING_PARAM, "Missing or invalid redirect_uri"); } if(!Objects.equal(redirectUri, app.getRedirect())) { throw new ErrorEventException(Errors.CODE_MISSING_PARAM, "Missing or invalid redirect_uri"); } } return app; } @Inject  SessionAuthDelegate(
         SessionAuth sessionAuth,
         Authenticator authenticator,
         TemplateService tmplSvc,
         OAuthConfig config,
         AppRegistry appRegistry,
         BridgeMetrics metrics); @Override boolean isAuthorized(ChannelHandlerContext ctx, FullHttpRequest req); @Override boolean handleFailedAuth(ChannelHandlerContext ctx, FullHttpRequest req);  }### Answer:
@Test(expected=ErrorEventException.class) public void testMissingClientIdThrows() { delegate.validateAndGetApplication(ImmutableMap.of()); }
@Test(expected=ErrorEventException.class) public void testInvalidClientIdThrows() { delegate.validateAndGetApplication(ImmutableMap.of(OAuthUtil.ATTR_CLIENT_ID, "wrong")); }
@Test(expected=ErrorEventException.class) public void testAppSendsRedirectButMissingThrows() { delegate.validateAndGetApplication(ImmutableMap.of(OAuthUtil.ATTR_CLIENT_ID, "app2")); }
@Test(expected=ErrorEventException.class) public void testAppSendsRedirectButWrongThrows() { delegate.validateAndGetApplication(ImmutableMap.of( OAuthUtil.ATTR_CLIENT_ID, "app2", OAuthUtil.ATTR_REDIRECT_URI, "http: )); }
@Test public void testAppSendsRedirectAndItsValid() { assertNotNull(delegate.validateAndGetApplication(ImmutableMap.of( OAuthUtil.ATTR_CLIENT_ID, "app2", OAuthUtil.ATTR_REDIRECT_URI, "http: ))); }