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

The following examples show how to use org.robolectric.util.ActivityController#get() . 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: ReceiptViewActivityTest.java    From gift-card-guard with GNU General Public License v3.0 6 votes vote down vote up
@Test
public void LoadReceipt()
{
    Intent intent = new Intent();
    final Bundle bundle = new Bundle();
    bundle.putString("receipt", "receipt");
    intent.putExtras(bundle);

    ActivityController activityController =  Robolectric.buildActivity(
        ReceiptViewActivity.class).withIntent(intent).create();
    activityController.start();
    activityController.resume();

    Activity activity = (Activity)activityController.get();
    WebView receiptView = (WebView)activity.findViewById(R.id.imageView);

    ShadowWebView.LoadDataWithBaseURL loadedData = shadowOf(receiptView).getLastLoadDataWithBaseURL();
    assertEquals("", loadedData.baseUrl);
    assertEquals("text/html", loadedData.mimeType);
    assertEquals("utf-8", loadedData.encoding);
    assertNull(loadedData.historyUrl);
    assertTrue(loadedData.data.contains("src=\"file://receipt\""));
}
 
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: 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 5
Source File: MainActivityTest.java    From gift-card-guard with GNU General Public License v3.0 5 votes vote down vote up
@Test
public void addOneGiftCard()
{
    ActivityController activityController = Robolectric.buildActivity(MainActivity.class).create();

    Activity mainActivity = (Activity)activityController.get();
    activityController.start();
    activityController.resume();

    TextView helpText = (TextView)mainActivity.findViewById(R.id.helpText);
    ListView list = (ListView)mainActivity.findViewById(R.id.list);

    assertEquals(0, list.getCount());

    DBHelper db = new DBHelper(mainActivity);
    db.insertGiftCard("store", "cardId", "value", "receipt");

    assertEquals(View.VISIBLE, helpText.getVisibility());
    assertEquals(View.GONE, list.getVisibility());

    activityController.pause();
    activityController.resume();

    assertEquals(View.GONE, helpText.getVisibility());
    assertEquals(View.VISIBLE, list.getVisibility());

    assertEquals(1, list.getAdapter().getCount());
    Cursor cursor = (Cursor)list.getAdapter().getItem(0);
    assertNotNull(cursor);
}
 
Example 6
Source File: ControllerActivity.java    From AndroidUnitTest with Apache License 2.0 5 votes vote down vote up
public Activity createAndInitActivity(Class activityClass, @Nullable RActivity activityAnnotation) {
    ActivityController activityController = ActivityController.of(Robolectric.getShadowsAdapter(), activityClass);
    androidUnitTest.setActivityController(activityController);
    if (activityAnnotation != null) {
        ActivityState activityState = activityAnnotation.state();
        setActivityState(activityController, activityState);
    }
    Activity activity = (Activity) activityController.get();
    return Mockito.spy(activity);
}
 
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: ActivitiesTest.java    From tickmate with GNU General Public License v3.0 5 votes vote down vote up
@Test
public void editTrackActivityStoresChanges() throws Exception {
    openMethod.invoke(dataSource);
    Track t = new Track("Testing", "Run my tests");
    t.setEnabled(true);
    dataSource.storeTrack(t);
    closeMethod.invoke(dataSource);
    assertThat(t, equalTo(t));

    Intent i = new Intent(RuntimeEnvironment.application.getApplicationContext(), tickmate.getClass());
    i.putExtra("track_id", t.getId());
    ActivityController<TrackPreferenceActivity> r_eta = Robolectric.buildActivity(TrackPreferenceActivity.class)
            .withIntent(i)
            .create(new Bundle())
            .start()
            .resume();

    TrackPreferenceActivity eta = r_eta.get();
    TrackPreferenceFragment tpf = (TrackPreferenceFragment) eta.getFragmentManager().findFragmentById(android.R.id.content);
    EditTextPreference description = (EditTextPreference) tpf.findPreference("description");
    assertThat(description.getText().toString(), is("Run my tests"));
    description.setText("Krishna Hare");

    r_eta.pause();
    r_eta.stop();

    Track t_also = dataSource.getTrack(t.getId());

    assertThat(t, equalTo(t_also));
    assertThat(t_also.getName(), is(t.getName()));
    assertThat(t_also.getIcon(), is(t.getIcon()));
    assertThat(t_also.getDescription(), is("Krishna Hare"));
    assertThat(t_also.isEnabled(), is(t.isEnabled()));
}
 
Example 11
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 12
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();
}