### Question:
TokenHandler extends HttpResource { protected FullHttpResponse doHandleRefreshToken(String refresh, String appId) throws Exception { Pair<UUID, Integer> personWithTtl = oauthDao.getPersonWithRefresh(appId, refresh); if(personWithTtl == null) { OAuthMetrics.incRefreshTokenExpired(); return OAuthUtil.badRequest(INVALID_GRANT); } try { FullHttpResponse response = updateTokensAndRespond(personWithTtl.getKey(), personWithTtl.getValue(), appId, refresh); OAuthMetrics.incRefreshTokenSuccess(); return response; } catch(Exception e) { logger.warn("Failed to update tokens", e); OAuthMetrics.incRefreshTokenException(); throw e; } } @Inject  TokenHandler(
         ApplicationAuth authorizer,
         BridgeMetrics metrics,
         AppRegistry appRegistry,
         OAuthDAO oauthDao,
         OAuthConfig config,
         PlaceSelectionHandler placeSelectionHandler
   ); @Override FullHttpResponse respond(FullHttpRequest req, ChannelHandlerContext ctx);  }### Answer:
@Test public void testRefreshNoPerson() throws Exception { EasyMock.expect(mockDao.getPersonWithRefresh("app1", token)).andReturn(null); replay(); FullHttpResponse response = tokenHandler.doHandleRefreshToken(token, "app1"); assertEquals(HttpResponseStatus.BAD_REQUEST, response.getStatus()); verify(); }
@Test public void testRefreshSuccess() throws Exception { EasyMock.expect(mockDao.getPersonWithRefresh("app1", token)).andReturn(new ImmutablePair<>(person, (int) TimeUnit.DAYS.toSeconds(5))); mockDao.updateTokens(EasyMock.eq("app1"), EasyMock.anyString(), EasyMock.anyString(), EasyMock.eq(person)); EasyMock.expectLastCall(); replay(); FullHttpResponse response = tokenHandler.doHandleRefreshToken(token, "app1"); String body = new String(response.content().array(), StandardCharsets.UTF_8).trim(); TokenResponse tokRes = gson.fromJson(body, TokenResponse.class); assertNotNull(tokRes.getAccessToken()); assertNotNull(tokRes.getRefreshToken()); assertEquals(config.getAccessTtlMinutes(), TimeUnit.MINUTES.convert(tokRes.getExpiresIn(), TimeUnit.SECONDS)); assertEquals(HttpResponseStatus.OK, response.getStatus()); verify(); }