@Test
  public void testLoginToSaasWhenHttpException() throws Exception {
    Credentials testSaasUsernameAndPassword =
        Commons.createDtoFromJson(TEST_CREDENTIALS_JSON, Credentials.class);

    doThrow(new AuthenticationException("error"))
        .when(mockFacade)
        .loginToCodenvySaaS(testSaasUsernameAndPassword);
    Response result = service.loginToCodenvySaaS(testSaasUsernameAndPassword);
    assertEquals(result.getStatus(), Response.Status.BAD_REQUEST.getStatusCode());

    doReturn(new DtoServerImpls.TokenImpl().withValue(TEST_ACCESS_TOKEN))
        .when(mockFacade)
        .loginToCodenvySaaS(testSaasUsernameAndPassword);
    doThrow(new HttpException(500, "Login error"))
        .when(mockFacade)
        .getAccountWhereUserIsOwner(null, TEST_ACCESS_TOKEN);
    result = service.loginToCodenvySaaS(testSaasUsernameAndPassword);
    assertEquals(result.getStatus(), Response.Status.INTERNAL_SERVER_ERROR.getStatusCode());
  }
  @Test
  public void testLoginToSaas() throws Exception {
    Credentials testSaasUsernameAndPassword =
        Commons.createDtoFromJson(TEST_CREDENTIALS_JSON, Credentials.class);

    doReturn(new DtoServerImpls.TokenImpl().withValue(TEST_ACCESS_TOKEN))
        .when(mockFacade)
        .loginToCodenvySaaS(testSaasUsernameAndPassword);
    doReturn(
            new org.eclipse.che.api.account.server.dto.DtoServerImpls.AccountReferenceImpl()
                .withId(TEST_ACCOUNT_ID)
                .withName(TEST_ACCOUNT_NAME))
        .when(mockFacade)
        .getAccountWhereUserIsOwner(null, TEST_ACCESS_TOKEN);

    Response result = service.loginToCodenvySaaS(testSaasUsernameAndPassword);
    assertEquals(result.getStatus(), Response.Status.OK.getStatusCode());

    assertNotNull(service.saasUserCredentials);

    SaasUserCredentials testSaasSaasUserCredentials = service.saasUserCredentials;
    assertEquals(testSaasSaasUserCredentials.getAccountId(), TEST_ACCOUNT_ID);
    assertEquals(testSaasSaasUserCredentials.getToken(), TEST_ACCESS_TOKEN);
  }