org.robolectric.android.controller.ActivityController Java Examples

The following examples show how to use org.robolectric.android.controller.ActivityController. 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 Project: budget-watch   Author: brarcher   File: TransactionViewActivityTest.java    License: GNU General Public License v3.0 6 votes vote down vote up
@Test
public void startAsEditNoReceiptCheckValueWithLocale() throws IOException
{
    ActivityController activityController = setupActivity("budget", "", false, true);
    Activity activity = (Activity)activityController.get();

    for(String locale : ImmutableList.of(
            "en",  // 100.10
            "nl")) // 100,10
    {
        System.out.println("Using locale: " + locale);
        Locale.setDefault(new Locale(locale));

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

        EditText value = (EditText)activity.findViewById(R.id.valueEdit);

        assertEquals("100.10", value.getText().toString());
    }
}
 
Example #2
Source Project: openwebnet-android   Author: openwebnet   File: MainActivityTest.java    License: MIT License 6 votes vote down vote up
@Test
public void shouldVerifyInstance_stateTitle() {
    when(environmentService.findAll()).thenReturn(Observable.empty());

    ActivityController<MainActivity> controller = Robolectric.buildActivity(MainActivity.class);
    activity = controller
        .create()
        .start()
        .resume()
        .visible()
        .get();
    ButterKnife.bind(this, activity);

    assertEquals("wrong title", labelAppName, activity.getSupportActionBar().getTitle());

    String CUSTOM_TITLE = "myNewTitle";
    activity.getSupportActionBar().setTitle(CUSTOM_TITLE);

    activity = controller
        .stop()
        .resume()
        .visible()
        .get();

    assertEquals("wrong title", CUSTOM_TITLE, activity.getSupportActionBar().getTitle());
}
 
Example #3
Source Project: RxLifecycle   Author: trello   File: AndroidLifecycleFragmentTest.java    License: Apache License 2.0 6 votes vote down vote up
private void testLifecycle(LifecycleOwner owner) {
    Fragment fragment = (Fragment) owner;
    ActivityController<?> controller = startFragment(fragment);

    TestObserver<Lifecycle.Event> testObserver = AndroidLifecycle.createLifecycleProvider(owner).lifecycle().test();

    controller.start();
    controller.resume();
    controller.pause();
    controller.stop();
    controller.destroy();

    testObserver.assertValues(
            Lifecycle.Event.ON_CREATE,
            Lifecycle.Event.ON_START,
            Lifecycle.Event.ON_RESUME,
            Lifecycle.Event.ON_PAUSE,
            Lifecycle.Event.ON_STOP,
            Lifecycle.Event.ON_DESTROY
    );
}
 
Example #4
Source Project: scene   Author: bytedance   File: NavigationSceneUtilityTests.java    License: Apache License 2.0 6 votes vote down vote up
@LooperMode(PAUSED)
@Test
public void testNotImmediateSetupInActivityOnCreate() {
    ActivityController<TestActivity> controller = Robolectric.buildActivity(TestActivity.class).create();
    TestActivity activity = controller.get();
    SceneDelegate sceneDelegate = NavigationSceneUtility.setupWithActivity(activity, TestScene.class).immediate(false).build();
    NavigationScene navigationScene = sceneDelegate.getNavigationScene();
    assertNotNull(navigationScene);

    assertEquals(State.NONE, navigationScene.getState());
    shadowOf(getMainLooper()).idle();//execute Handler posted task
    assertEquals(State.ACTIVITY_CREATED, navigationScene.getState());

    controller.start();
    assertEquals(State.STARTED, navigationScene.getState());
    controller.resume();
    assertEquals(State.RESUMED, navigationScene.getState());
    controller.pause();
    assertEquals(State.STARTED, navigationScene.getState());
    controller.stop();
    assertEquals(State.ACTIVITY_CREATED, navigationScene.getState());
    controller.destroy();
    assertEquals(State.NONE, navigationScene.getState());
}
 
Example #5
Source Project: materialistic   Author: hidroh   File: AppUtilsTest.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void testOpenExternalComment() {
    ActivityController<TestListActivity> controller = Robolectric.buildActivity(TestListActivity.class);
    TestListActivity activity = controller.create().start().resume().get();
    AppUtils.openExternal(activity, mock(PopupMenu.class),
            new View(activity), new TestHnItem(1), null);
    assertNull(ShadowAlertDialog.getLatestAlertDialog());
    AppUtils.openExternal(activity, mock(PopupMenu.class),
            new View(activity), new TestHnItem(1) {
                @Override
                public String getUrl() {
                    return String.format(HackerNewsClient.WEB_ITEM_PATH, "1");
                }
            }, null);
    assertNull(ShadowAlertDialog.getLatestAlertDialog());
    controller.destroy();
}
 
Example #6
Source Project: edx-app-android   Author: edx   File: BaseFragmentActivityTest.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Testing overall lifecycle and setup
 */
@Test
public void lifecycleTest() {
    ActivityController<? extends BaseFragmentActivity> controller =
            Robolectric.buildActivity(getActivityClass(), getIntent());
    BaseFragmentActivity activity = controller.get();
    ShadowActivity shadowActivity = Shadows.shadowOf(activity);

    controller.create().start();
    // Action bar state initialization
    ActionBar bar = activity.getSupportActionBar();
    if (bar != null) {
        int displayOptions = bar.getDisplayOptions();
        assertTrue((displayOptions & ActionBar.DISPLAY_HOME_AS_UP) > 0);
        assertTrue((displayOptions & ActionBar.DISPLAY_SHOW_HOME) > 0);
        assertTrue(null == activity.findViewById(android.R.id.home));
    }

    controller.postCreate(null).resume().postResume().visible();

    // Action bar home button
    assertTrue(shadowActivity.clickMenuItem(android.R.id.home));
    activity.finish();
    assertThat(activity).isFinishing();
}
 
Example #7
Source Project: scene   Author: bytedance   File: NavigationSceneUtilityTests.java    License: Apache License 2.0 6 votes vote down vote up
@LooperMode(PAUSED)
@Test
public void testNotImmediateSetupInActivityOnResume() {
    ActivityController<TestActivity> controller = Robolectric.buildActivity(TestActivity.class).create().start().resume();
    TestActivity activity = controller.get();
    SceneDelegate sceneDelegate = NavigationSceneUtility.setupWithActivity(activity, TestScene.class).immediate(false).build();
    NavigationScene navigationScene = sceneDelegate.getNavigationScene();
    assertNotNull(navigationScene);

    assertEquals(State.NONE, navigationScene.getState());
    shadowOf(getMainLooper()).idle();//execute Handler posted task
    assertEquals(State.RESUMED, navigationScene.getState());

    controller.pause();
    assertEquals(State.STARTED, navigationScene.getState());
    controller.stop();
    assertEquals(State.ACTIVITY_CREATED, navigationScene.getState());
    controller.destroy();
    assertEquals(State.NONE, navigationScene.getState());
}
 
Example #8
Source Project: budget-watch   Author: brarcher   File: BudgetViewActivityTest.java    License: GNU General Public License v3.0 6 votes vote down vote up
@Test
public void startAsUpdateCheckActionBar() throws Exception
{
    ActivityController activityController = setupActivity("budgetName", 100, false, true);
    Activity activity = (Activity)activityController.get();

    final Menu menu = shadowOf(activity).getOptionsMenu();
    assertTrue(menu != null);

    assertEquals(menu.size(), 2);

    MenuItem item = menu.findItem(R.id.action_delete);
    assertNotNull(item);
    assertEquals("Delete", item.getTitle().toString());

    item = menu.findItem(R.id.action_save);
    assertNotNull(item);
    assertEquals("Save", item.getTitle().toString());
}
 
Example #9
Source Project: scene   Author: bytedance   File: NavigationSceneUtilityTests.java    License: Apache License 2.0 6 votes vote down vote up
@LooperMode(PAUSED)
@Test
public void testNotImmediateSetupInActivityOnPause() {
    ActivityController<TestActivity> controller = Robolectric.buildActivity(TestActivity.class).create().start().resume().pause();
    TestActivity activity = controller.get();
    SceneDelegate sceneDelegate = NavigationSceneUtility.setupWithActivity(activity, TestScene.class).immediate(false).build();
    NavigationScene navigationScene = sceneDelegate.getNavigationScene();
    assertNotNull(navigationScene);

    assertEquals(State.NONE, navigationScene.getState());
    shadowOf(getMainLooper()).idle();//execute Handler posted task
    assertEquals(State.STARTED, navigationScene.getState());

    controller.stop();
    assertEquals(State.ACTIVITY_CREATED, navigationScene.getState());
    controller.destroy();
    assertEquals(State.NONE, navigationScene.getState());
}
 
Example #10
Source Project: RxLifecycle   Author: trello   File: AndroidLifecycleFragmentTest.java    License: Apache License 2.0 6 votes vote down vote up
private void testBindUntilEvent(LifecycleOwner owner) {
    Fragment fragment = (Fragment) owner;
    ActivityController<?> controller = startFragment(fragment);

    TestObserver<Object> testObserver = observable.compose(AndroidLifecycle.createLifecycleProvider(owner).bindUntilEvent(Lifecycle.Event.ON_STOP)).test();

    testObserver.assertNotComplete();
    controller.start();
    testObserver.assertNotComplete();
    controller.resume();
    testObserver.assertNotComplete();
    controller.pause();
    testObserver.assertNotComplete();
    controller.stop();
    testObserver.assertComplete();
}
 
Example #11
Source Project: openwebnet-android   Author: openwebnet   File: MainActivityTest.java    License: MIT License 6 votes vote down vote up
@Test
public void shouldVerifyInstance_initHeaderAuthenticated() {
    when(environmentService.findAll()).thenReturn(Observable.empty());
    when(firebaseService.isAuthenticated()).thenReturn(true);
    when(firebaseService.getUserPhotoUrl()).thenReturn(null);

    ActivityController<MainActivity> controller = Robolectric.buildActivity(MainActivity.class);
    activity = controller
        .create()
        .start()
        .resume()
        .visible()
        .get();
    ButterKnife.bind(this, activity);

    verify(firebaseService, times(1)).getUserPhotoUrl();
    ImageView headerImageView = navigationView.findViewById(R.id.imageViewHeader);
    assertFalse("OnClickListeners should be null", headerImageView.hasOnClickListeners());
}
 
Example #12
Source Project: scene   Author: bytedance   File: SceneLifecycleManagerExceptionTests.java    License: Apache License 2.0 6 votes vote down vote up
@Test(expected = NullPointerException.class)
public void testOnSaveInstanceStateExceptionNPE() {
    ActivityController<TestActivity> controller = Robolectric.buildActivity(TestActivity.class).create().start().resume();
    TestActivity testActivity = controller.get();
    SceneLifecycleManager<NavigationScene> sceneLifecycleManager = new SceneLifecycleManager<>();

    NavigationScene navigationScene = new NavigationScene();
    NavigationSceneOptions options = new NavigationSceneOptions(ChildScene.class);
    navigationScene.setArguments(options.toBundle());

    sceneLifecycleManager.onActivityCreated(testActivity, testActivity.mFrameLayout,
            navigationScene, new Scope.RootScopeFactory() {
                @NonNull
                @Override
                public Scope getRootScope() {
                    return Scope.DEFAULT_ROOT_SCOPE_FACTORY.getRootScope();
                }
            }, true, null);
    sceneLifecycleManager.onSaveInstanceState(null);
}
 
Example #13
Source Project: scene   Author: bytedance   File: SceneLifecycleManagerExceptionTests.java    License: Apache License 2.0 6 votes vote down vote up
@Test(expected = IllegalStateException.class)
public void testStateException() {
    ActivityController<TestActivity> controller = Robolectric.buildActivity(TestActivity.class).create().start().resume();
    TestActivity testActivity = controller.get();
    SceneLifecycleManager<NavigationScene> sceneLifecycleManager = new SceneLifecycleManager<>();

    NavigationScene navigationScene = new NavigationScene();
    NavigationSceneOptions options = new NavigationSceneOptions(ChildScene.class);
    navigationScene.setArguments(options.toBundle());

    sceneLifecycleManager.onActivityCreated(testActivity, testActivity.mFrameLayout,
            navigationScene, new Scope.RootScopeFactory() {
                @NonNull
                @Override
                public Scope getRootScope() {
                    return Scope.DEFAULT_ROOT_SCOPE_FACTORY.getRootScope();
                }
            }, false, null);
    sceneLifecycleManager.onResume();
}
 
Example #14
Source Project: openwebnet-android   Author: openwebnet   File: MainActivityTest.java    License: MIT License 6 votes vote down vote up
@Test
public void shouldVerifyInstance_initHeaderNotAuthenticated() {
    when(environmentService.findAll()).thenReturn(Observable.empty());
    when(firebaseService.isAuthenticated()).thenReturn(false);

    ActivityController<MainActivity> controller = Robolectric.buildActivity(MainActivity.class);
    activity = controller
        .create()
        .start()
        .resume()
        .visible()
        .get();
    ButterKnife.bind(this, activity);

    verify(firebaseService, never()).getUserPhotoUrl();
    ImageView headerImageView = navigationView.findViewById(R.id.imageViewHeader);
    assertTrue("OnClickListeners should not be null", headerImageView.hasOnClickListeners());
}
 
Example #15
Source Project: RxLifecycle   Author: trello   File: AndroidLifecycleActivityTest.java    License: Apache License 2.0 6 votes vote down vote up
private void testBindUntilEvent(ActivityController<? extends LifecycleOwner> controller) {
    LifecycleProvider<Lifecycle.Event> activity = AndroidLifecycle.createLifecycleProvider(controller.get());

    TestObserver<Object> testObserver = observable.compose(activity.bindUntilEvent(Lifecycle.Event.ON_STOP)).test();

    controller.create();
    testObserver.assertNotComplete();
    controller.start();
    testObserver.assertNotComplete();
    controller.resume();
    testObserver.assertNotComplete();
    controller.pause();
    testObserver.assertNotComplete();
    controller.stop();
    testObserver.assertComplete();
}
 
Example #16
Source Project: toothpick   Author: stephanenicolas   File: ViewModelUtilTest.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void testCloseOnClear() {
  // GIVEN
  ActivityController<FragmentActivity> activityController =
      Robolectric.buildActivity(FragmentActivity.class).create();
  FragmentActivity activity = activityController.get();
  Application application = ApplicationProvider.getApplicationContext();
  Scope activityScope = Toothpick.openScopes(application, activity);

  // WHEN
  ViewModelUtil.closeOnViewModelCleared(activity, activityScope);
  activityController.destroy();

  // THEN
  assertThat(Toothpick.isScopeOpen(activity), is(false));
}
 
Example #17
Source Project: budget-watch   Author: brarcher   File: MainActivityTest.java    License: GNU General Public License v3.0 6 votes vote down vote up
private void testItemClickLaunchesActivity(int index, String expectedActivity)
{
    ActivityController activityController = Robolectric.buildActivity(MainActivity.class).create();
    Activity activity = (Activity)activityController.get();

    activityController.start();
    activityController.resume();

    ListView list = (ListView)activity.findViewById(R.id.list);

    ShadowListView shadowList = shadowOf(list);
    shadowList.populateItems();

    // First item should be the Budgets, second should be Transactions
    shadowList.performItemClick(index);

    testNextStartedActivity(activity, expectedActivity);
}
 
Example #18
Source Project: RxLifecycle   Author: trello   File: AndroidLifecycleActivityTest.java    License: Apache License 2.0 6 votes vote down vote up
private void testLifecycle(ActivityController<? extends LifecycleOwner> controller) {
    LifecycleProvider<Lifecycle.Event> provider = AndroidLifecycle.createLifecycleProvider(controller.get());

    TestObserver<Lifecycle.Event> testObserver = provider.lifecycle().test();

    controller.create();
    controller.start();
    controller.resume();
    controller.pause();
    controller.stop();
    controller.destroy();

    testObserver.assertValues(
            Lifecycle.Event.ON_CREATE,
            Lifecycle.Event.ON_START,
            Lifecycle.Event.ON_RESUME,
            Lifecycle.Event.ON_PAUSE,
            Lifecycle.Event.ON_STOP,
            Lifecycle.Event.ON_DESTROY
    );
}
 
Example #19
Source Project: scene   Author: bytedance   File: GroupSceneUtilityTests.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void testSetupInActivityOnStart() {
    ActivityController<TestActivity> controller = Robolectric.buildActivity(TestActivity.class).create().start();
    TestActivity activity = controller.get();
    GroupSceneDelegate sceneDelegate = GroupSceneUtility.setupWithActivity(activity, TestScene.class).build();
    GroupScene groupScene = sceneDelegate.getGroupScene();
    assertNotNull(groupScene);
    assertEquals(State.STARTED, groupScene.getState());
    controller.resume();
    assertEquals(State.RESUMED, groupScene.getState());
    controller.pause();
    assertEquals(State.STARTED, groupScene.getState());
    controller.stop();
    assertEquals(State.ACTIVITY_CREATED, groupScene.getState());
    controller.destroy();
    assertEquals(State.NONE, groupScene.getState());
}
 
Example #20
Source Project: RxLifecycle   Author: trello   File: RxActivityLifecycleTest.java    License: Apache License 2.0 6 votes vote down vote up
private void testLifecycle(ActivityController<? extends LifecycleProvider<ActivityEvent>> controller) {
    LifecycleProvider<ActivityEvent> activity = controller.get();

    TestObserver<ActivityEvent> testObserver = activity.lifecycle().test();

    controller.create();
    controller.start();
    controller.resume();
    controller.pause();
    controller.stop();
    controller.destroy();

    testObserver.assertValues(
        ActivityEvent.CREATE,
        ActivityEvent.START,
        ActivityEvent.RESUME,
        ActivityEvent.PAUSE,
        ActivityEvent.STOP,
        ActivityEvent.DESTROY
    );
}
 
Example #21
Source Project: gift-card-guard   Author: brarcher   File: GiftCardViewActivityTest.java    License: GNU General Public License v3.0 6 votes vote down vote up
@Test
public void startWithoutParametersCancel()
{
    ActivityController activityController = Robolectric.buildActivity(GiftCardViewActivity.class).create();
    activityController.start();
    activityController.visible();
    activityController.resume();

    Activity activity = (Activity)activityController.get();

    final Button cancelButton = (Button) activity.findViewById(R.id.cancelButton);

    assertEquals(false, activity.isFinishing());
    cancelButton.performClick();
    assertEquals(true, activity.isFinishing());
}
 
Example #22
Source Project: scene   Author: bytedance   File: AnimatorUtilityTests.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void testResetViewStatus() {
    ActivityController<NavigationSourceUtility.TestActivity> controller = Robolectric.buildActivity(NavigationSourceUtility.TestActivity.class).create().start().resume();
    NavigationSourceUtility.TestActivity testActivity = controller.get();
    View view = new View(testActivity);
    view.setTranslationX(1);
    view.setTranslationY(1);
    view.setScaleX(2.0f);
    view.setScaleY(2.0f);
    view.setRotation(1.0f);
    view.setRotationX(1.0f);
    view.setRotationY(1.0f);
    view.setAlpha(0.5f);
    view.startAnimation(new AlphaAnimation(0.0f, 1.0f));

    AnimatorUtility.resetViewStatus(view);
    assertEquals(0.0f, view.getTranslationX(), 0.0f);
    assertEquals(0.0f, view.getTranslationY(), 0.0f);
    assertEquals(1.0f, view.getScaleX(), 0.0f);
    assertEquals(1.0f, view.getScaleY(), 0.0f);
    assertEquals(0.0f, view.getRotation(), 0.0f);
    assertEquals(0.0f, view.getRotationX(), 0.0f);
    assertEquals(0.0f, view.getRotationY(), 0.0f);
    assertEquals(1.0f, view.getAlpha(), 0.0f);
    assertNull(view.getAnimation());
}
 
Example #23
Source Project: toothpick   Author: stephanenicolas   File: LifecycleUtilTest.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void testCloseOnDestroy() {
  // GIVEN
  ActivityController<FragmentActivity> activityController =
      Robolectric.buildActivity(FragmentActivity.class).create();
  FragmentActivity activity = activityController.get();
  Application application = ApplicationProvider.getApplicationContext();
  Scope activityScope = Toothpick.openScopes(application, activity);

  // WHEN
  LifecycleUtil.closeOnDestroy(activity, activityScope);
  activityController.destroy();

  // THEN
  assertThat(Toothpick.isScopeOpen(activity), is(false));
}
 
Example #24
Source Project: AndroidGodEye   Author: Kyson   File: ViewCanaryInternalTest.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void inspectInner() {
    ActivityController<TestViewCanaryActivity> activityController = Robolectric.buildActivity(TestViewCanaryActivity.class).create().start().resume();
    ViewCanaryInternal viewCanaryInternal = new ViewCanaryInternal();
    Map<Activity, List<List<ViewIdWithSize>>> recentLayoutListRecords = new HashMap<>();
    try {
        viewCanaryInternal.inspectInner(new WeakReference<>(activityController.get()), GodEye.instance().<ViewCanary>getModule(GodEye.ModuleName.VIEW_CANARY), GodEye.instance().<ViewCanary>getModule(GodEye.ModuleName.VIEW_CANARY).config(), recentLayoutListRecords).run();
        GodEye.instance().<ViewCanary, ViewIssueInfo>moduleObservable(GodEye.ModuleName.VIEW_CANARY).test().assertNoValues();

        recentLayoutListRecords.put(activityController.get(), new ArrayList<>());
        viewCanaryInternal.inspectInner(new WeakReference<>(activityController.get()), GodEye.instance().<ViewCanary>getModule(GodEye.ModuleName.VIEW_CANARY), GodEye.instance().<ViewCanary>getModule(GodEye.ModuleName.VIEW_CANARY).config(), recentLayoutListRecords).run();
        GodEye.instance().<ViewCanary, ViewIssueInfo>moduleObservable(GodEye.ModuleName.VIEW_CANARY).test().assertValueCount(1);

        viewCanaryInternal.inspectInner(new WeakReference<>(activityController.get()), GodEye.instance().<ViewCanary>getModule(GodEye.ModuleName.VIEW_CANARY), GodEye.instance().<ViewCanary>getModule(GodEye.ModuleName.VIEW_CANARY).config(), recentLayoutListRecords).run();
        GodEye.instance().<ViewCanary, ViewIssueInfo>moduleObservable(GodEye.ModuleName.VIEW_CANARY).test().assertValueCount(1);
    } catch (UninstallException e) {
        Assert.fail();
    }
}
 
Example #25
Source Project: budget-watch   Author: brarcher   File: TransactionViewActivityTest.java    License: GNU General Public License v3.0 6 votes vote down vote up
@Test
public void startAsAddCaptureReceiptFailureCreateExpense() throws IOException
{
    ActivityController activityController = setupActivity("budget", null, false, false);

    // Add something that will 'handle' the media capture intent
    registerMediaStoreIntentHandler();

    Activity activity = (Activity)activityController.get();

    checkAllFields(activity, "", "", "budget","", "", "", nowString, "", false, false);

    // Complete image capture in failure
    Uri imageLocation = captureImageWithResult(activity, R.id.captureButton, false, ORIGINAL_JPEG_QUALITY);

    checkAllFields(activity, "", "", "budget", "", "", "", nowString, "", false, false);

    // Save and check the gift card
    saveExpenseWithArguments(activity, "name", "account", "budget", 100, "note",
            nowString, nowMs, "", true);

    // Check that no file was created
    File imageFile = new File(imageLocation.getPath());
    assertEquals(false, imageFile.exists());
}
 
Example #26
Source Project: budget-watch   Author: brarcher   File: TransactionActivityTest.java    License: GNU General Public License v3.0 6 votes vote down vote up
@Test
public void bothTabsExists() throws Exception
{
    ActivityController activityController = Robolectric.buildActivity(TransactionActivity.class).create();

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

    TabLayout tabLayout = (TabLayout) activity.findViewById(R.id.tabLayout);
    assertNotNull(tabLayout);
    assertEquals(2, tabLayout.getTabCount());

    TabLayout.Tab expenseTab = tabLayout.getTabAt(0);
    assertNotNull(expenseTab);
    String expenseTabTitle = activity.getResources().getString(R.string.expensesTitle);
    assertEquals(expenseTabTitle, expenseTab.getText().toString());

    TabLayout.Tab revenueTab = tabLayout.getTabAt(1);
    assertNotNull(revenueTab);
    String revenueTabTitle = activity.getResources().getString(R.string.revenuesTitle);
    assertEquals(revenueTabTitle, revenueTab.getText().toString());
}
 
Example #27
Source Project: budget-watch   Author: brarcher   File: TransactionViewActivityTest.java    License: GNU General Public License v3.0 6 votes vote down vote up
@Test
public void startAsUpdateCheckActionBar() throws Exception
{
    ActivityController activityController = setupActivity("budget", "", false, true);
    Activity activity = (Activity)activityController.get();

    final Menu menu = shadowOf(activity).getOptionsMenu();
    assertTrue(menu != null);

    assertEquals(menu.size(), 2);

    MenuItem item = menu.findItem(R.id.action_delete);
    assertNotNull(item);
    assertEquals("Delete", item.getTitle().toString());

    item = menu.findItem(R.id.action_save);
    assertNotNull(item);
    assertEquals("Save", item.getTitle().toString());
}
 
Example #28
Source Project: RIBs   Author: uber   File: RibActivityTest.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void rxActivity_shouldCallback_onLowMemory() {
  ActivityController<EmptyActivity> activityController = buildActivity(EmptyActivity.class);
  RibActivity activity = activityController.setup().get();
  TestObserver<ActivityCallbackEvent> testSub = new TestObserver<>();
  activity
      .callbacks()
      .filter(
          new Predicate<ActivityCallbackEvent>() {
            @Override
            public boolean test(ActivityCallbackEvent activityEvent) throws Exception {
              return activityEvent.getType() == ActivityCallbackEvent.Type.LOW_MEMORY;
            }
          })
      .subscribe(testSub);

  activity.onLowMemory();

  testSub.assertValue(ActivityCallbackEvent.create(ActivityCallbackEvent.Type.LOW_MEMORY));
}
 
Example #29
Source Project: toothpick   Author: stephanenicolas   File: ViewModelUtilTest.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void testCloseOnClear_shouldNotCloseScope_whenConfigurationChange() {
  // GIVEN
  ActivityController<FragmentActivity> activityController =
      Robolectric.buildActivity(FragmentActivity.class).create();
  FragmentActivity activity = activityController.get();
  Application application = ApplicationProvider.getApplicationContext();
  Scope activityScope = Toothpick.openScopes(application, activity);

  // WHEN
  ViewModelUtil.closeOnViewModelCleared(activity, activityScope);
  activityController.configurationChange(new Configuration());

  // THEN
  assertThat(Toothpick.isScopeOpen(activity), is(true));
}
 
Example #30
Source Project: RIBs   Author: uber   File: RibActivityTest.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void rxActivity_shouldCallback_onActivityResult() {
  ActivityController<EmptyActivity> activityController = buildActivity(EmptyActivity.class);
  RibActivity activity = activityController.setup().get();
  TestObserver<ActivityCallbackEvent.ActivityResult> testSub = new TestObserver<>();
  activity.callbacks(ActivityCallbackEvent.ActivityResult.class).subscribe(testSub);

  android.os.Bundle data = new android.os.Bundle();
  data.putString("hello", "seattle");
  Intent intent = new Intent(Intent.ACTION_VIEW);
  intent.putExtras(data);
  int requestCode = 2;
  int resultCode = Activity.RESULT_OK;
  activity.onActivityResult(requestCode, resultCode, intent);

  testSub.assertValueCount(1);
  ActivityCallbackEvent.ActivityResult receivedEvent = testSub.values().get(0);
  assertThat(receivedEvent.getType()).isEqualTo(ActivityCallbackEvent.Type.ACTIVITY_RESULT);
  assertThat(receivedEvent.getRequestCode()).isEqualTo(requestCode);
  assertThat(receivedEvent.getResultCode()).isEqualTo(resultCode);
  assertThat(receivedEvent.getData()).isNotNull();
  assertThat(receivedEvent.getData().getExtras()).isNotNull();
  assertThat(receivedEvent.getData().getExtras().getString("hello")).isEqualTo("seattle");
}