public void testLoginFailsDueToEmptyPassword() throws IOException, URISyntaxException {
    try {
      playClient.login(emailAddress, "");

      fail("should have thrown IllegalArgumentException");
    } catch (IllegalArgumentException e) {
    }
  }
  public void testLoginHappyPath() throws IOException, URISyntaxException {
    RestResponse googleLoginResponse = mock(RestResponse.class);

    // mock the call to login to Google
    when(restClient.doPost(
            Const.USE_HTTPS, HostName.GOOGLE, Path.GOOGLE_LOGIN, null, null, null, loginForm))
        .thenReturn(googleLoginResponse);

    // the response to the initial login to Google will contain the authorization string in the body
    String authToken = "authToken";
    String googleLoginResponseBody = Const.GOOLE_LOGIN_AUTH + authToken + "\n";
    when(googleLoginResponse.getBody()).thenReturn(googleLoginResponseBody);
    when(googleLoginResponse.getStatusCode()).thenReturn(HttpStatus.SC_OK);

    when(googleUtil.getAuthTokenFromLoginResponse(googleLoginResponseBody)).thenReturn(authToken);

    // setup the query params for the login to Play
    Map<String, String> playLoginQueryParams = new HashMap<String, String>();
    playLoginQueryParams.put(QueryParamConst.HL_NAME, QueryParamConst.HL_VALUE);
    playLoginQueryParams.put(QueryParamConst.U_NAME, QueryParamConst.U_VALUE);

    // setup the request headers for the login to play
    Map<String, String> playLoginRequestHeaders = new HashMap<String, String>();
    when(googleUtil.createAuthHeaderValue(authToken)).thenReturn(authHeaderValue);
    playLoginRequestHeaders.put(HeaderName.AUTHORIZATION, authHeaderValue);

    // the response to logging into play will contain the st and sjsaid cookies
    String sjsaidValue = "sjsaidValue";
    Map<String, String> playLoginResponseCookies = new HashMap<String, String>();
    playLoginResponseCookies.put(CookieName.SJSAID, sjsaidValue);
    playLoginResponseCookies.put(CookieName.XT, xtValue);

    RestResponse playLoginResponse = mock(RestResponse.class);
    when(playLoginResponse.getCookies()).thenReturn(playLoginResponseCookies);
    when(playLoginResponse.getStatusCode()).thenReturn(HttpStatus.SC_OK);

    // mock the login to Play
    when(restClient.doPost(
            Const.USE_HTTPS,
            HostName.PLAY,
            Path.MUSIC_LOGIN,
            playLoginQueryParams,
            playLoginRequestHeaders,
            null,
            null))
        .thenReturn(playLoginResponse);

    when(playSessionFactory.create(xtValue, sjsaidValue, authToken)).thenReturn(playSession);

    LoginResponse loginResponse = mock(LoginResponse.class);
    when(loginResponseFactory.create(LoginResult.SUCCESS, playSession)).thenReturn(loginResponse);

    // do the call
    assertEquals(loginResponse, playClient.login(emailAddress, password));
  }
  public void testLoginFailsDueToOtherError() throws IOException, URISyntaxException {
    // mock interactions -- assume bad credentials
    RestResponse restResponse = mock(RestResponse.class);
    when(restResponse.getStatusCode()).thenReturn(HttpStatus.SC_INTERNAL_SERVER_ERROR);

    when(restClient.doPost(
            Const.USE_HTTPS, HostName.GOOGLE, Path.GOOGLE_LOGIN, null, null, null, loginForm))
        .thenReturn(restResponse);

    LoginResponse loginResponse = mock(LoginResponse.class);
    when(loginResponseFactory.create(LoginResult.FAILURE, null)).thenReturn(loginResponse);

    // do the call
    assertEquals(loginResponse, playClient.login(emailAddress, password));
  }
  public void testLoginFailsDueToBadCredentials() throws IOException, URISyntaxException {
    // mock interactions -- assume bad credentials
    RestResponse googleLoginResponse = mock(RestResponse.class);
    when(googleLoginResponse.getStatusCode()).thenReturn(HttpStatus.SC_FORBIDDEN);

    when(restClient.doPost(
            Const.USE_HTTPS, HostName.GOOGLE, Path.GOOGLE_LOGIN, null, null, null, loginForm))
        .thenReturn(googleLoginResponse);

    LoginResponse loginResponse = mock(LoginResponse.class);
    when(loginResponseFactory.create(LoginResult.BAD_CREDENTIALS, null)).thenReturn(loginResponse);

    // do the call
    assertEquals(loginResponse, playClient.login(emailAddress, password));
  }