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 File: ViewCanaryInternalTest.java    From AndroidGodEye with 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 #2
Source File: BudgetViewActivityTest.java    From budget-watch with 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 #3
Source File: NavigationSceneUtilityTests.java    From scene with 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 #4
Source File: RibActivityTest.java    From RIBs with 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 #5
Source File: TransactionViewActivityTest.java    From budget-watch with 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 #6
Source File: AppUtilsTest.java    From materialistic with 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 #7
Source File: ViewModelUtilTest.java    From toothpick with 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 #8
Source File: NavigationSceneUtilityTests.java    From scene with 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 #9
Source File: AndroidLifecycleFragmentTest.java    From RxLifecycle with 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 #10
Source File: MainActivityTest.java    From openwebnet-android with 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 #11
Source File: RibActivityTest.java    From RIBs with 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");
}
 
Example #12
Source File: BudgetActivityTest.java    From budget-watch with GNU General Public License v3.0 6 votes vote down vote up
@Test
public void testClickAdd()
{
    ActivityController activityController = Robolectric.buildActivity(BudgetActivity.class).create();
    Activity activity = (Activity)activityController.get();

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

    shadowOf(activity).clickMenuItem(R.id.action_add);

    ShadowActivity shadowActivity = shadowOf(activity);
    Intent startedIntent = shadowActivity.getNextStartedActivity();

    ComponentName name = startedIntent.getComponent();
    assertNotNull(name);
    assertEquals("protect.budgetwatch/.BudgetViewActivity", name.flattenToShortString());
    Bundle bundle = startedIntent.getExtras();
    assertNull(bundle);
}
 
Example #13
Source File: TransactionViewActivityTest.java    From budget-watch with 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 #14
Source File: BaseFragmentActivityTest.java    From edx-app-android with 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 #15
Source File: TransactionActivityTest.java    From budget-watch with 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 #16
Source File: TransactionViewActivityTest.java    From budget-watch with 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 #17
Source File: AndroidLifecycleFragmentTest.java    From RxLifecycle with 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 #18
Source File: RxActivityLifecycleTest.java    From RxLifecycle with 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 #19
Source File: GroupSceneUtilityTests.java    From scene with 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 File: LifecycleUtilTest.java    From toothpick with 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 #21
Source File: AndroidLifecycleActivityTest.java    From RxLifecycle with 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 #22
Source File: MainActivityTest.java    From openwebnet-android with 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 #23
Source File: MainActivityTest.java    From budget-watch with 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 #24
Source File: SceneLifecycleManagerExceptionTests.java    From scene with 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 #25
Source File: SceneLifecycleManagerExceptionTests.java    From scene with 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 #26
Source File: MainActivityTest.java    From openwebnet-android with 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 #27
Source File: AnimatorUtilityTests.java    From scene with 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 #28
Source File: AndroidLifecycleActivityTest.java    From RxLifecycle with 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 #29
Source File: ViewModelUtilTest.java    From toothpick with 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 #30
Source File: GiftCardViewActivityTest.java    From gift-card-guard with 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());
}