AuthService extends EndpointService { public void obtainNewAccessToken() throws TokenExpiredException, IOException { String requestUrl = RESOURCE + "/token/refresh"; Map<String, String> token = new HashMap<>(); token.put("refreshToken", getClient().refreshToken); ArgusResponse response = getClient().executeHttpRequest(ArgusHttpClient.RequestType.POST, requestUrl, token); if(response.getStatus() == HttpStatus.SC_UNAUTHORIZED) { throw new TokenExpiredException(response.getErrorMessage(), requestUrl, response.getResult()); } assertValidResponse(response, requestUrl); Map<String, String> tokenMap = fromJson(response.getResult(), new TypeReference<Map<String, String>>() {}); getClient().accessToken = tokenMap.get("accessToken"); } AuthService(ArgusHttpClient client); void login(String username, String password); void obtainNewAccessToken(); void logout();  }
@Test public void testObtainNewAccessToken() throws IOException, TokenExpiredException { try(ArgusService argusService = new ArgusService(getMockedClient("/AuthServiceTest2.json"))) { AuthService authService = argusService.getAuthService(); authService.login("aUsername", "aPassword"); assertEquals("anAccessToken", authService.getClient().accessToken); authService.obtainNewAccessToken(); assertEquals("aNewAccessToken", authService.getClient().accessToken); } }