当前位置: 首页>>代码示例>>Java>>正文


Java Tasks.forException方法代码示例

本文整理汇总了Java中com.google.android.gms.tasks.Tasks.forException方法的典型用法代码示例。如果您正苦于以下问题:Java Tasks.forException方法的具体用法?Java Tasks.forException怎么用?Java Tasks.forException使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在com.google.android.gms.tasks.Tasks的用法示例。


在下文中一共展示了Tasks.forException方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: preview

import com.google.android.gms.tasks.Tasks; //导入方法依赖的package包/类
private Task<CameraController> preview() {
    if (mStreamManager != null && mStreamManager.getStreamState() == StreamManager.STATE_IDLE) {
        return mStreamManager.prepare(getConfig(), mTextureView)
                .addOnCompleteListener(this, new OnCompleteListener<CameraController>() {
                    @Override
                    public void onComplete(@NonNull Task<CameraController> task) {
                        if (task.isSuccessful()) {
                            Log.d(TAG, "Prepare succeeds");
                            mCameraController = task.getResult();
                            enableAllButtons();
                        } else {
                            Log.e(TAG, "Prepare fails " + task.getException());
                        }
                    }
                });
    }
    return Tasks.forException(new IllegalStateException());
}
 
开发者ID:StraaS,项目名称:StraaS-android-sdk-sample,代码行数:19,代码来源:MainActivity.java

示例2: fetchTopProvider

import com.google.android.gms.tasks.Tasks; //导入方法依赖的package包/类
public static Task<String> fetchTopProvider(FirebaseAuth auth, @NonNull String email) {
    if (TextUtils.isEmpty(email)) {
        return Tasks.forException(new NullPointerException("Email cannot be empty"));
    }

    return auth.fetchProvidersForEmail(email)
            .continueWith(new Continuation<ProviderQueryResult, String>() {
                @Override
                public String then(@NonNull Task<ProviderQueryResult> task) {
                    if (!task.isSuccessful()) return null;

                    List<String> providers = task.getResult().getProviders();
                    return providers == null || providers.isEmpty()
                            ? null : providers.get(providers.size() - 1);
                }
            });
}
 
开发者ID:firebase,项目名称:FirebaseUI-Android,代码行数:18,代码来源:ProviderUtils.java

示例3: then

import com.google.android.gms.tasks.Tasks; //导入方法依赖的package包/类
@Override
public Task<Void> then(@NonNull Task<AuthResult> task) throws Exception {
    if(task.isSuccessful()) {
        return VOID_TASK;
    }
    try {
        throw task.getException();
    } catch (Exception e) {
        return Tasks.forException(e);
    }
}
 
开发者ID:firebase,项目名称:digits-migration-helper-android,代码行数:12,代码来源:AuthMigrator.java

示例4: migrateAndClear_badSessionResponse

import com.google.android.gms.tasks.Tasks; //导入方法依赖的package包/类
@Test
public void migrateAndClear_badSessionResponse() throws JSONException {
    Task<AuthResult> task = Tasks.forException(new FirebaseWebRequestException("msg", 400));

    when(mockStorageHelpers.getDigitsSessionJson()).thenReturn(VALID_DIGITS_SESSION);
    when(mockStorageHelpers.getUnsignedJWT(mjsonCaptor.capture())).thenReturn(DIGITS_JWT);
    when(mockFirebaseAuth.signInWithCustomToken(DIGITS_JWT)).thenReturn(task);
    AuthMigrator authMigrator = new AuthMigrator(mockFirebaseApp, mockStorageHelpers,
            mockFirebaseAuth);
    assertFalse(authMigrator.migrate(true).isSuccessful());
    verify(mockFirebaseAuth).signInWithCustomToken(DIGITS_JWT);
    verify(mockStorageHelpers).clearDigitsSession();
    checkCompleteJsonObject(mjsonCaptor.getValue());
}
 
开发者ID:firebase,项目名称:digits-migration-helper-android,代码行数:15,代码来源:AuthMigratorTest.java

示例5: migrateAndClear_unauthorizedSessionResponse

import com.google.android.gms.tasks.Tasks; //导入方法依赖的package包/类
@Test
public void migrateAndClear_unauthorizedSessionResponse() throws JSONException {
    Task<AuthResult> task = Tasks.forException(new FirebaseWebRequestException("msg", 403));

    when(mockStorageHelpers.getDigitsSessionJson()).thenReturn(VALID_DIGITS_SESSION);
    when(mockStorageHelpers.getUnsignedJWT(mjsonCaptor.capture())).thenReturn(DIGITS_JWT);
    when(mockFirebaseAuth.signInWithCustomToken(DIGITS_JWT)).thenReturn(task);
    AuthMigrator authMigrator = new AuthMigrator(mockFirebaseApp, mockStorageHelpers,
            mockFirebaseAuth);
    assertFalse(authMigrator.migrate(true).isSuccessful());
    verify(mockFirebaseAuth).signInWithCustomToken(DIGITS_JWT);
    verify(mockStorageHelpers).clearDigitsSession();
    checkCompleteJsonObject(mjsonCaptor.getValue());
}
 
开发者ID:firebase,项目名称:digits-migration-helper-android,代码行数:15,代码来源:AuthMigratorTest.java

示例6: migrateAndKeep_unauthorizedSessionResponse

import com.google.android.gms.tasks.Tasks; //导入方法依赖的package包/类
@Test
public void migrateAndKeep_unauthorizedSessionResponse() throws JSONException {
    Task<AuthResult> task = Tasks.forException(new FirebaseWebRequestException("msg", 403));

    when(mockStorageHelpers.getDigitsSessionJson()).thenReturn(VALID_DIGITS_SESSION);
    when(mockStorageHelpers.getUnsignedJWT(mjsonCaptor.capture())).thenReturn(DIGITS_JWT);
    when(mockFirebaseAuth.signInWithCustomToken(DIGITS_JWT)).thenReturn(task);
    AuthMigrator authMigrator = new AuthMigrator(mockFirebaseApp, mockStorageHelpers,
            mockFirebaseAuth);
    assertFalse(authMigrator.migrate(false).isSuccessful());
    verify(mockFirebaseAuth).signInWithCustomToken(DIGITS_JWT);
    verify(mockStorageHelpers, times(0)).clearDigitsSession();
    checkCompleteJsonObject(mjsonCaptor.getValue());
}
 
开发者ID:firebase,项目名称:digits-migration-helper-android,代码行数:15,代码来源:AuthMigratorTest.java

示例7: addRating

import com.google.android.gms.tasks.Tasks; //导入方法依赖的package包/类
private Task<Void> addRating(final DocumentReference restaurantRef, final Rating rating) {
    // TODO(developer): Implement
    return Tasks.forException(new Exception("not yet implemented"));
}
 
开发者ID:firebase,项目名称:friendlyeats-android,代码行数:5,代码来源:RestaurantDetailActivity.java

示例8: testSignInFailed_withFacebookAlreadyLinked

import com.google.android.gms.tasks.Tasks; //导入方法依赖的package包/类
@Test
@Config(shadows = {AuthHelperShadow.class})
public void testSignInFailed_withFacebookAlreadyLinked() {
    AppCompatBase mockActivity = mock(AppCompatBase.class);
    IdpResponse idpResponse =
            new IdpResponse.Builder(
                    new User.Builder(GoogleAuthProvider.PROVIDER_ID, TestConstants.EMAIL)
                            .build())
                    .setToken(TestConstants.TOKEN)
                    .build();
    CredentialSignInHandler credentialSignInHandler = new CredentialSignInHandler(
            mockActivity,
            null,
            RC_ACCOUNT_LINK,
            idpResponse);

    FlowParameters mockFlowParams = mock(FlowParameters.class);
    when(mockActivity.getFlowParams()).thenReturn(mockFlowParams);

    AuthHelper mockAuthHelper = mock(AuthHelper.class);
    when(mockActivity.getAuthHelper()).thenReturn(mockAuthHelper);
    AuthHelperShadow.getFirebaseAuth(); // Force static initialization
    when(mockAuthHelper.getFirebaseAuth()).thenReturn(AuthHelperShadow.getFirebaseAuth());

    ProgressDialogHolder mockHolder = mock(ProgressDialogHolder.class);
    when(mockActivity.getDialogHolder()).thenReturn(mockHolder);

    // pretend the account has Facebook linked already
    when(AuthHelperShadow.getFirebaseAuth().fetchProvidersForEmail(TestConstants.EMAIL)).thenReturn(
            new AutoCompleteTask<ProviderQueryResult>(
                    new FakeProviderQueryResult(
                            Arrays.asList(FacebookAuthProvider.PROVIDER_ID)), true, null));

    // pretend there was already an account with this email
    Task<AuthResult> exceptionTask = Tasks.forException(
            new FirebaseAuthUserCollisionException(LINKING_ERROR, LINKING_EXPLANATION));
    credentialSignInHandler.onComplete(exceptionTask);
    ArgumentCaptor<Intent> intentCaptor = ArgumentCaptor.forClass(Intent.class);
    ArgumentCaptor<Integer> intCaptor = ArgumentCaptor.forClass(Integer.class);
    verify(mockActivity).startActivityForResult(intentCaptor.capture(), intCaptor.capture());
    Intent capturedIntent = intentCaptor.getValue();
    User capturedUser = User.getUser(capturedIntent);
    assertEquals(RC_ACCOUNT_LINK, (int) intCaptor.getValue());
    assertEquals(
            WelcomeBackIdpPrompt.class.getName(),
            capturedIntent.getComponent().getClassName());
    assertEquals(
            TestConstants.EMAIL,
            capturedUser.getEmail());
    assertEquals(
            FacebookAuthProvider.PROVIDER_ID,
            capturedUser.getProviderId());

}
 
开发者ID:firebase,项目名称:FirebaseUI-Android,代码行数:55,代码来源:CredentialSignInHandlerTest.java


注:本文中的com.google.android.gms.tasks.Tasks.forException方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。