Java Code Examples for org.robolectric.util.ActivityController#create()

The following examples show how to use org.robolectric.util.ActivityController#create() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ControllerActivity.java    From AndroidUnitTest with Apache License 2.0 6 votes vote down vote up
private void applyState(ActivityState state,
                        ActivityController controller) {
    switch (state) {
        case STARTED:
            controller.start();
            break;
        case RESUMED:
            controller.resume();
            break;
        case PAUSED:
            controller.pause();
            break;
        case STOPPED:
            controller.stop();
            break;
        case DESTROYED:
            controller.destroy();
            break;
        case CREATED:
        default:
            controller.create();
            break;
    }
}
 
Example 2
Source File: LoginActivityTest.java    From rides-android-sdk with MIT License 6 votes vote down vote up
@Test
public void onLoginLoad_withSsoEnabled_andNotSupported_shouldReturnErrorResultIntent() {
    Intent intent = LoginActivity.newIntent(Robolectric.setupActivity(Activity.class), productPriority,
            loginConfiguration, ResponseType.TOKEN, false, true, true);

    ActivityController<LoginActivity> controller = Robolectric.buildActivity(LoginActivity.class).withIntent(intent);
    loginActivity = controller.get();
    loginActivity.ssoDeeplinkFactory = ssoDeeplinkFactory;
    ShadowActivity shadowActivity = shadowOf(loginActivity);
    when(ssoDeeplink.isSupported(SsoDeeplink.FlowVersion.REDIRECT_TO_SDK)).thenReturn(false);

    controller.create();

    assertThat(shadowActivity.getResultCode()).isEqualTo(Activity.RESULT_CANCELED);
    assertThat(shadowActivity.getResultIntent()).isNotNull();
    assertThat(getErrorFromIntent(shadowActivity.getResultIntent()))
            .isEqualTo(AuthenticationError.INVALID_REDIRECT_URI);
    assertThat(shadowActivity.isFinishing()).isTrue();
}
 
Example 3
Source File: LoginActivityTest.java    From rides-android-sdk with MIT License 6 votes vote down vote up
@Test
public void onLoginLoad_withResponseTypeToken_andNotForceWebview_andPrivilegedScopes_andRedirectToPlayStoreDisabled_shouldLoadChrometab() {
    loginConfiguration = new SessionConfiguration.Builder()
            .setClientId(CLIENT_ID)
            .setRedirectUri(REDIRECT_URI)
            .setScopes(MIXED_SCOPES)
            .build();
    Intent intent = LoginActivity.newIntent(Robolectric.setupActivity(Activity.class), loginConfiguration,
            ResponseType.TOKEN, false);

    ActivityController<LoginActivity> controller = Robolectric.buildActivity(LoginActivity.class).withIntent(intent);
    loginActivity = controller.get();
    loginActivity.customTabsHelper = customTabsHelper;
    controller.create();

    String expectedUrl = AuthUtils.buildUrl(REDIRECT_URI, ResponseType.TOKEN, loginConfiguration);
    verify(customTabsHelper).openCustomTab(any(LoginActivity.class), any(CustomTabsIntent.class),
            eq(Uri.parse(expectedUrl)), any(CustomTabsHelper.BrowserFallback.class));
}
 
Example 4
Source File: OAuthWebViewClientTest.java    From rides-android-sdk with MIT License 6 votes vote down vote up
@Test
public void onLoadLoginView_withNoRedirectUrl_shouldReturnError() {
    SessionConfiguration config = new SessionConfiguration.Builder().setClientId("clientId").build();
    Intent intent = new Intent();
    intent.putExtra(LoginActivity.EXTRA_SESSION_CONFIGURATION, config);
    final ActivityController<LoginActivity> controller = Robolectric.buildActivity(LoginActivity.class)
            .withIntent(intent);
    final ShadowActivity shadowActivity = Shadows.shadowOf(controller.get());

    controller.create();

    assertThat(shadowActivity.isFinishing()).isTrue();
    assertThat(shadowActivity.getResultCode()).isEqualTo(Activity.RESULT_CANCELED);
    assertThat(shadowActivity.getResultIntent()).isNotNull();
    assertThat(shadowActivity.getResultIntent().getStringExtra(LoginManager.EXTRA_ERROR)).isNotEmpty();
}
 
Example 5
Source File: LoginActivityTest.java    From blade-player with GNU General Public License v3.0 5 votes vote down vote up
@Test
public void shouldFinishLoginActivityWhenCompleted() {

    Activity context = Robolectric
            .buildActivity(Activity.class)
            .create()
            .get();

    AuthenticationRequest request = new AuthenticationRequest.Builder("test", AuthenticationResponse.Type.TOKEN, "test://test").build();
    AuthenticationResponse response = new AuthenticationResponse.Builder()
            .setType(AuthenticationResponse.Type.TOKEN)
            .setAccessToken("test_token")
            .setExpiresIn(3600)
            .build();

    Bundle bundle = new Bundle();
    bundle.putParcelable(LoginActivity.REQUEST_KEY, request);

    Intent intent = new Intent(context, LoginActivity.class);
    intent.putExtra(LoginActivity.EXTRA_AUTH_REQUEST, bundle);

    ActivityController<LoginActivity> loginActivityActivityController = buildActivity(LoginActivity.class)
            .withIntent(intent);

    final LoginActivity loginActivity = loginActivityActivityController.get();

    final ShadowActivity shadowLoginActivity = shadowOf(loginActivity);
    shadowLoginActivity.setCallingActivity(context.getComponentName());

    loginActivityActivityController.create();

    assertFalse(loginActivity.isFinishing());

    loginActivity.onClientComplete(response);

    assertTrue(loginActivity.isFinishing());
    assertEquals(Activity.RESULT_OK, shadowLoginActivity.getResultCode());
    assertEquals(response, shadowLoginActivity.getResultIntent().getBundleExtra(LoginActivity.EXTRA_AUTH_RESPONSE).get(LoginActivity.RESPONSE_KEY));
}
 
Example 6
Source File: LoginActivityTest.java    From rides-android-sdk with MIT License 5 votes vote down vote up
@Test
public void onLoginLoad_withEmptySessionConfiguration_shouldReturnErrorResultIntent() {
    ActivityController<LoginActivity> controller = Robolectric.buildActivity(LoginActivity.class);
    controller.create();

    ShadowActivity shadowActivity = shadowOf(controller.get());

    assertThat(shadowActivity.getResultCode()).isEqualTo(Activity.RESULT_CANCELED);
    assertThat(shadowActivity.getResultIntent()).isNotNull();
    assertThat(getErrorFromIntent(shadowActivity.getResultIntent()))
            .isEqualTo(AuthenticationError.INVALID_PARAMETERS);
    assertThat(shadowActivity.isFinishing()).isTrue();
}
 
Example 7
Source File: LoginActivityTest.java    From rides-android-sdk with MIT License 5 votes vote down vote up
@Test
public void onLoginLoad_withSsoEnabled_andSupported_shouldExecuteSsoDeeplink() {
    Intent intent = LoginActivity.newIntent(Robolectric.setupActivity(Activity.class), productPriority,
            loginConfiguration, ResponseType.TOKEN, false, true, true);

    ActivityController<LoginActivity> controller = Robolectric.buildActivity(LoginActivity.class).withIntent(intent);
    loginActivity = controller.get();
    loginActivity.ssoDeeplinkFactory = ssoDeeplinkFactory;

    when(ssoDeeplink.isSupported(SsoDeeplink.FlowVersion.REDIRECT_TO_SDK)).thenReturn(true);

    controller.create();

    verify(ssoDeeplink).execute(SsoDeeplink.FlowVersion.REDIRECT_TO_SDK);
}
 
Example 8
Source File: LoginActivityTest.java    From rides-android-sdk with MIT License 5 votes vote down vote up
@Test
public void onLoginLoad_withResponseTypeCode_andNotForceWebview_shouldLoadChrometab() {
    Intent intent = LoginActivity.newIntent(Robolectric.setupActivity(Activity.class), loginConfiguration,
            ResponseType.CODE, false);

    ActivityController<LoginActivity> controller = Robolectric.buildActivity(LoginActivity.class).withIntent(intent);
    loginActivity = controller.get();
    loginActivity.customTabsHelper = customTabsHelper;
    controller.create();

    String expectedUrl = AuthUtils.buildUrl(REDIRECT_URI, ResponseType.CODE, loginConfiguration);
    verify(customTabsHelper).openCustomTab(any(LoginActivity.class), any(CustomTabsIntent.class),
            eq(Uri.parse(expectedUrl)), any(CustomTabsHelper.BrowserFallback.class));
}
 
Example 9
Source File: LoginActivityTest.java    From rides-android-sdk with MIT License 5 votes vote down vote up
@Test
public void onLoginLoad_withResponseTypeToken_andNotForceWebview_andGeneralScopes_shouldLoadChrometab() {
    Intent intent = LoginActivity.newIntent(Robolectric.setupActivity(Activity.class), loginConfiguration,
            ResponseType.TOKEN, false);

    ActivityController<LoginActivity> controller = Robolectric.buildActivity(LoginActivity.class).withIntent(intent);
    loginActivity = controller.get();
    loginActivity.customTabsHelper = customTabsHelper;
    controller.create();

    String expectedUrl = AuthUtils.buildUrl(REDIRECT_URI, ResponseType.TOKEN, loginConfiguration);
    verify(customTabsHelper).openCustomTab(any(LoginActivity.class), any(CustomTabsIntent.class),
            eq(Uri.parse(expectedUrl)), any(CustomTabsHelper.BrowserFallback.class));
}
 
Example 10
Source File: ScreenUtilsTest.java    From android-utilset with Apache License 2.0 4 votes vote down vote up
private <T extends Activity> T createActivity(Class<T> activityClass) {
	ActivityController<T> controller = Robolectric.buildActivity(activityClass);
	controller.create();
	return controller.get();
}
 
Example 11
Source File: ActivityUtilsTest.java    From android-utilset with Apache License 2.0 4 votes vote down vote up
private <T extends Activity> T createActivity(Class<T> activityClass) {
	ActivityController<T> controller = Robolectric.buildActivity(activityClass);
	controller.create();
	return controller.get();
}