AuthService extends EndpointService { public void login(String username, String password) throws IOException { String requestUrl = RESOURCE + "/login"; Credentials creds = new Credentials(); creds.setPassword(password); creds.setUsername(username); ArgusResponse response = getClient().executeHttpRequest(ArgusHttpClient.RequestType.POST, requestUrl, creds); try { assertValidResponse(response, requestUrl); } catch (TokenExpiredException e) { throw new RuntimeException("This should never happen. login() method should never throw a TokenExpiredException", e); } Map<String, String> tokens = fromJson(response.getResult(), new TypeReference<Map<String, String>>() {}); getClient().accessToken = tokens.get("accessToken"); getClient().refreshToken = tokens.get("refreshToken"); } AuthService(ArgusHttpClient client); void login(String username, String password); void obtainNewAccessToken(); void logout();  }
@Test public void testBadLogin() throws IOException, TokenExpiredException { try(ArgusService argusService = new ArgusService(getMockedClient("/AuthServiceTest2.json"))) { AuthService authService = argusService.getAuthService(); authService.login("aBadUsername", "aBadPassword"); } catch (ArgusServiceException ex) { assertEquals(401, ex.getStatus()); return; } fail("Expected an ArgusServiceException for bad login."); }