### Question:
WebFormHandler { public BaseConsent login(String appId, String sessionId, String sessionData, String username, String password, BaseClient.CookieStorage cookieStorage) throws UserLoginFailedException { String result = this.client.login(appId, sessionId, sessionData, username, password, cookieStorage); if(Strings.isNullOrEmpty(result)) { throw new UserLoginFailedException("Failed to extract necessary consent information from the login request since the returned result was null or empty."); } try { return ConsentFactory.fromResponse(result); } catch(IllegalArgumentException e) { throw new UserLoginFailedException("Failed to extract necessary consent information from the login request.", e); } } WebFormHandler(OAuthConfig config);   WebFormHandler(WebFormClient client); BaseConsent login(String appId, String sessionId, String sessionData, String username, String password, BaseClient.CookieStorage cookieStorage); BaseConsent consent(String appId, String sessionId, String sessionData, List<String> approvedScopes, BaseClient.CookieStorage cookieStorage);  }### Answer:
@Test public void testLogin_whenResponseIsValid_shouldReturnAConsent() throws Exception { Mockito.when(client.login(anyString(), anyString(), anyString(), anyString(), anyString(), any(BaseClient.CookieStorage.class))).thenReturn(consentFormHTML); assertThat(webFormHandler.login("app-id", "session-id", "session-data", "user", "password", cookieStorage)) .isInstanceOf(BaseConsent.class); }
@Test(expected = UserLoginFailedException.class) public void testLogin_whenResponseIsNull_shouldThrowException() throws Exception { Mockito.when(client.login(anyString(), anyString(), anyString(), anyString(), anyString(), any(BaseClient.CookieStorage.class))).thenReturn(null); webFormHandler.login("app-id", "session-id", "session-data", "user", "password", cookieStorage); }
@Test(expected = UserLoginFailedException.class) public void testLogin_whenResponseIsInvalid_shouldThrowException() throws Exception { Mockito.when(client.login(anyString(), anyString(), anyString(), anyString(), anyString(), any(BaseClient.CookieStorage.class))).thenReturn("<html>"); webFormHandler.login("app-id", "session-id", "session-data", "user", "password", cookieStorage); }