### Question:
BearerAuth implements RequestAuthorizer { @Override public boolean isAuthorized(ChannelHandlerContext ctx, FullHttpRequest req) { Optional<String> token = OAuthUtil.extractTokenFromBearer(req); Pair<UUID, Integer> personWithTtl = null; if(token.isPresent()) { personWithTtl = dao.getPersonWithAccess(appId, token.get()); } return token.isPresent() && personWithTtl != null; } BearerAuth(
         OAuthDAO dao,
         BridgeMetrics metrics,
         String appId
   );  BearerAuth(
      OAuthDAO dao,
      BridgeMetrics metrics,
      String appId,
      Function<FullHttpRequest, FullHttpResponse> responseSupplier
   ); @Override boolean isAuthorized(ChannelHandlerContext ctx, FullHttpRequest req); @Override boolean handleFailedAuth(ChannelHandlerContext ctx, FullHttpRequest req);  }### Answer:
@Test public void testIsAuthorizedNoHeader() { DefaultFullHttpRequest req = new DefaultFullHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.POST, "http: assertFalse(auth.isAuthorized(null, req)); }
@Test public void testIsAuthorizedNotBearer() { DefaultFullHttpRequest req = new DefaultFullHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.POST, "http: req.headers().add(HttpHeaders.AUTHORIZATION, "Basic foobar"); assertFalse(auth.isAuthorized(null, req)); }
@Test public void testIsAuthorizedNoPersonMatchesToken() { EasyMock.expect(oauthDao.getPersonWithAccess("app1", "foobar")).andReturn(null); replay(); DefaultFullHttpRequest req = new DefaultFullHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.POST, "http: req.headers().add(HttpHeaders.AUTHORIZATION, "Bearer foobar"); assertFalse(auth.isAuthorized(null, req)); }
@Test public void testIsAuthorized() { EasyMock.expect(oauthDao.getPersonWithAccess("app1", "foobar")).andReturn(new ImmutablePair<>(IrisUUID.randomUUID(), 5000)); replay(); DefaultFullHttpRequest req = new DefaultFullHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.POST, "http: req.headers().add(HttpHeaders.AUTHORIZATION, "Bearer foobar"); assertTrue(auth.isAuthorized(null, req)); }