Java 类org.robolectric.android.controller.ActivityController 实例源码

项目:Android-RxPresenter    文件:RxPresenterTest.java   
@Test public void testBindActivity() throws Exception {
  ActivityController controller = Robolectric.buildActivity(TestActivity.class).create().start();
  NaviActivity activity = (NaviActivity) controller.get();

  this.presenter.bind(activity);

  controller.create();
  //before activity start view is unbound
  assertTrue(this.presenter.view == null);

  controller.start();
  //after activity started view has been bound automatically
  assertTrue(this.presenter.view != null);

  controller.destroy();
  //before activity destroyed view is unbound
  assertTrue(this.presenter.view == null);
}
项目:Android-RxPresenter    文件:RxPresenterTest.java   
@Test public void testActivityObservableBindLifecycle() throws Exception {
  final Observable<Object> observable = PublishSubject.create().asObservable();

  TestSubscriber<Object> testSubscriber = TestSubscriber.create();

  ActivityController controller = Robolectric.buildActivity(TestActivity.class).create().start();
  NaviActivity activity = (NaviActivity) controller.get();
  this.presenter.bind(activity);

  this.presenter.bindLifecycle(observable, testSubscriber);

  controller.create();
  assertFalse(testSubscriber.isUnsubscribed());
  controller.start();
  assertFalse(testSubscriber.isUnsubscribed());
  controller.resume();
  assertFalse(testSubscriber.isUnsubscribed());
  controller.pause();
  assertFalse(testSubscriber.isUnsubscribed());
  controller.stop();
  assertFalse(testSubscriber.isUnsubscribed());
  controller.destroy();
  testSubscriber.assertCompleted();
  testSubscriber.assertUnsubscribed();
}
项目:RIBs    文件:RibActivityTest.java   
@Test
public void onCreate_withSaveInstanceState_shouldForwardToRootRiblet() {
  android.os.Bundle interactorBundle = new android.os.Bundle();
  interactorBundle.putString(TEST_BUNDLE_KEY, TEST_BUNDLE_VALUE);

  android.os.Bundle testBundle = new android.os.Bundle();
  testBundle.putBundle(Router.KEY_INTERACTOR, interactorBundle);

  ActivityController<EmptyActivity> activityController =
      Robolectric.buildActivity(EmptyActivity.class);
  activityController.create(testBundle);

  assertThat(
          activityController
              .get()
              .getTestInteractor()
              .getSavedInstanceState()
              .getString(TEST_BUNDLE_KEY))
      .isEqualTo(TEST_BUNDLE_VALUE);
}
项目:RIBs    文件:RibActivityTest.java   
@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));
}
项目:RIBs    文件:RibActivityTest.java   
@Test
public void ribActivity_onSaveInstanceStateAndCallbackFlagEnabled_shouldEmitToCallbacks() {
  ActivityController<EmptyActivity> activityController = buildActivity(EmptyActivity.class);
  RibActivity activity = activityController.setup().get();
  TestObserver<ActivityCallbackEvent.SaveInstanceState> testSub = new TestObserver<>();
  activity.callbacks(ActivityCallbackEvent.SaveInstanceState.class).subscribe(testSub);

  android.os.Bundle state = new android.os.Bundle();
  state.putString("hello", "seattle");
  activity.onSaveInstanceState(state);

  testSub.assertValueCount(1);
  ActivityCallbackEvent.SaveInstanceState receivedEvent = testSub.values().get(0);
  assertThat(receivedEvent.getType()).isEqualTo(ActivityCallbackEvent.Type.SAVE_INSTANCE_STATE);
  assertThat(receivedEvent.getOutState()).isNotNull();
  assertThat(receivedEvent.getOutState().getString("hello")).isEqualTo("seattle");
}
项目:RIBs    文件:RibActivityTest.java   
@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");
}
项目:rental-calc    文件:PictureViewActivityTest.java   
@Test
public void startWithoutTitle()
{
    Intent intent = new Intent();

    final Bundle bundle = new Bundle();
    intent.putExtras(bundle);

    ActivityController controller = Robolectric.buildActivity(PictureViewActivity.class, intent).create();
    Activity activity = (Activity)controller.get();

    controller.start();
    assertTrue(activity.isFinishing());

    String latestToast = ShadowToast.getTextOfLatestToast();
    assertNotNull(latestToast);
}
项目:rental-calc    文件:PictureViewActivityTest.java   
private ActivityController startWithFile(File file) throws IOException
{
    Intent intent = new Intent();

    final Bundle bundle = new Bundle();
    bundle.putString("file", file.getAbsolutePath());
    intent.putExtras(bundle);

    ActivityController controller = Robolectric.buildActivity(PictureViewActivity.class, intent).create();
    Activity activity = (Activity)controller.get();

    controller.start();
    controller.visible();
    controller.resume();
    assertTrue(activity.isFinishing() == false);

    String latestToast = ShadowToast.getTextOfLatestToast();
    assertNull(latestToast);

    return controller;
}
项目:rental-calc    文件:PictureViewActivityTest.java   
@Test
public void clickBackFinishes() throws IOException
{
    File file = new File(Environment.getExternalStorageDirectory(), "test.jpg");
    file.createNewFile();

    ActivityController controller = startWithFile(file);
    Activity activity = (Activity)controller.get();
    ShadowActivity shadowActivity = shadowOf(activity);

    assertTrue(shadowActivity.isFinishing() == false);
    shadowActivity.clickMenuItem(android.R.id.home);
    assertTrue(shadowActivity.isFinishing());

    // Check that can finish out the lifecycle
    controller.pause();
    controller.stop();
    controller.destroy();

    // The done menu item was not clicked, so the result should be that
    // the activity was canceled
    assertEquals(Activity.RESULT_CANCELED, shadowActivity.getResultCode());
    assertNull(shadowActivity.getResultIntent());
}
项目:rental-calc    文件:ItemizationActivityTest.java   
@Test
public void doneNoItems()
{
    HashMap<String, Integer> emptyMap = new HashMap<>();
    ActivityController controller = startWithMap(emptyMap);
    Activity activity = (Activity)controller.get();
    ShadowActivity shadowActivity = shadowOf(activity);

    assertTrue(shadowActivity.isFinishing() == false);
    shadowActivity.clickMenuItem(R.id.action_done);
    assertTrue(shadowActivity.isFinishing());

    // Check that can finish out the lifecycle
    controller.pause();
    controller.stop();
    controller.destroy();

    checkReturnedMap(activity, emptyMap);
}
项目:rental-calc    文件:PropertyOverviewActivityTest.java   
@Test
public void startWithoutProperty()
{
    Intent intent = new Intent();
    final Bundle bundle = new Bundle();
    intent.putExtras(bundle);

    ActivityController controller = Robolectric.buildActivity(PropertyOverviewActivity.class, intent).create();
    Activity activity = (Activity)controller.get();

    controller.start();
    controller.visible();
    controller.resume();
    assertTrue(activity.isFinishing());

    String latestToast = ShadowToast.getTextOfLatestToast();
    assertNotNull(latestToast);
}
项目:rental-calc    文件:PropertyOverviewActivityTest.java   
@Test
public void startWithMissingProperty()
{
    Intent intent = new Intent();
    final Bundle bundle = new Bundle();
    bundle.putLong("id", 0);
    intent.putExtras(bundle);

    ActivityController controller = Robolectric.buildActivity(PropertyOverviewActivity.class, intent).create();
    Activity activity = (Activity)controller.get();

    controller.start();
    controller.visible();
    controller.resume();
    assertTrue(activity.isFinishing());

    String latestToast = ShadowToast.getTextOfLatestToast();
    assertNotNull(latestToast);
}
项目:rental-calc    文件:PropertyOverviewActivityTest.java   
private void checkOpenActivity(int viewId, String nextActivity)
{
    ActivityController controller = startWithProperty(new Property());
    Activity activity = (Activity)controller.get();

    View propertyView = activity.findViewById(viewId);
    propertyView.performClick();

    assertTrue(activity.isFinishing() == false);
    Intent next = shadowOf(activity).getNextStartedActivity();

    ComponentName componentName = next.getComponent();
    String name = componentName.flattenToShortString();
    assertEquals(nextActivity, name);

    Bundle extras = next.getExtras();
    assertNotNull(extras);
    assertTrue(extras.containsKey("id"));
    long id = extras.getLong("id", -1);
    assertEquals(DatabaseTestHelper.FIRST_ID, id);
}
项目:rental-calc    文件:PropertySummaryActivityTest.java   
@Test
public void clickBackFinishes()
{
    ActivityController controller = startWithProperty(new Property());
    Activity activity = (Activity)controller.get();

    controller.start();
    controller.visible();
    controller.resume();

    assertTrue(shadowOf(activity).isFinishing() == false);
    shadowOf(activity).clickMenuItem(android.R.id.home);
    assertTrue(shadowOf(activity).isFinishing());

    // Check that can finish out the lifecycle
    controller.pause();
    controller.stop();
    controller.destroy();
}
项目:rental-calc    文件:PropertySummaryActivityTest.java   
@Test
public void startWithMissingProperty()
{
    Intent intent = new Intent();
    final Bundle bundle = new Bundle();
    bundle.putLong("id", 0);
    intent.putExtras(bundle);

    ActivityController controller = Robolectric.buildActivity(PropertySummaryActivity.class, intent).create();
    Activity activity = (Activity)controller.get();

    controller.start();
    controller.visible();
    controller.resume();
    assertTrue(activity.isFinishing());

    String latestToast = ShadowToast.getTextOfLatestToast();
    assertNotNull(latestToast);
}
项目:rental-calc    文件:PropertySummaryActivityTest.java   
private ActivityController startWithProperty(Property property)
{
    long id = db.insertProperty(property);

    Intent intent = new Intent();
    final Bundle bundle = new Bundle();
    bundle.putLong("id", id);
    intent.putExtras(bundle);

    ActivityController controller = Robolectric.buildActivity(PropertySummaryActivity.class, intent).create();
    Activity activity = (Activity)controller.get();

    controller.start();
    controller.visible();
    controller.resume();
    assertTrue(activity.isFinishing() == false);

    String latestToast = ShadowToast.getTextOfLatestToast();
    assertNull(latestToast);

    return controller;
}
项目:rental-calc    文件:PropertyPicturesActivityTest.java   
private ActivityController startWithProperty(Property property)
{
    long id = db.insertProperty(property);

    Intent intent = new Intent();
    final Bundle bundle = new Bundle();
    bundle.putLong("id", id);
    intent.putExtras(bundle);

    ActivityController controller = Robolectric.buildActivity(PropertyPicturesActivity.class, intent).create();
    Activity activity = (Activity)controller.get();

    controller.start();
    controller.visible();
    controller.resume();
    assertTrue(activity.isFinishing() == false);

    String latestToast = ShadowToast.getTextOfLatestToast();
    assertNull(latestToast);

    return controller;
}
项目:rental-calc    文件:PropertyPicturesActivityTest.java   
@Test
public void startWithoutProperty()
{
    Intent intent = new Intent();
    final Bundle bundle = new Bundle();
    intent.putExtras(bundle);

    ActivityController controller = Robolectric.buildActivity(PropertyPicturesActivity.class, intent).create();
    Activity activity = (Activity)controller.get();

    controller.start();
    assertTrue(activity.isFinishing());

    String latestToast = ShadowToast.getTextOfLatestToast();
    assertNotNull(latestToast);
}
项目:rental-calc    文件:PropertyPicturesActivityTest.java   
@Test
public void startWithMissingProperty()
{
    Intent intent = new Intent();
    final Bundle bundle = new Bundle();
    bundle.putLong("id", 0);
    intent.putExtras(bundle);

    ActivityController controller = Robolectric.buildActivity(PropertyPicturesActivity.class, intent).create();
    Activity activity = (Activity)controller.get();

    controller.start();
    assertTrue(activity.isFinishing());

    String latestToast = ShadowToast.getTextOfLatestToast();
    assertNotNull(latestToast);
}
项目:rental-calc    文件:PropertiesListActivityTest.java   
@Test
public void clickAddLaunchesActivity()
{
    ActivityController controller = Robolectric.buildActivity(PropertiesListActivity.class).create();
    Activity activity = (Activity)controller.get();

    controller.start();
    controller.visible();
    controller.resume();

    shadowOf(activity).clickMenuItem(R.id.action_add);
    assertTrue(activity.isFinishing() == false);

    Intent next = shadowOf(activity).getNextStartedActivity();

    ComponentName componentName = next.getComponent();
    String name = componentName.flattenToShortString();
    assertEquals("protect.rentalcalc/.PropertyViewActivity", name);

    Bundle extras = next.getExtras();
    assertNull(extras);
}
项目:rental-calc    文件:PropertyViewActivityTest.java   
@Test
public void startWithPropertyAndSave() throws Exception
{
    Property property = new Property();

    ActivityController controller = startWithProperty(property);
    Activity activity = (Activity)controller.get();

    checkFields(activity, property);

    preloadProperty(property);
    setFields(activity, property);
    checkFields(activity, property);

    assertNotNull(shadowOf(activity).getOptionsMenu().findItem(R.id.action_save));
    shadowOf(activity).clickMenuItem(R.id.action_save);
    assertTrue(activity.isFinishing());

    Intent next = shadowOf(activity).getNextStartedActivity();
    assertNull(next);

    Property updatedProperty = db.getProperty(DatabaseTestHelper.FIRST_ID);

    compareRelevantPropertyFields(property, updatedProperty);
}
项目:rental-calc    文件:PropertiesListActivityTest.java   
@Test
public void checkNoProperties()
{
    ActivityController controller = Robolectric.buildActivity(PropertiesListActivity.class).create();
    Activity activity = (Activity)controller.get();

    controller.start();
    controller.visible();
    controller.resume();

    View helpText = activity.findViewById(R.id.helpText);
    assertEquals(View.VISIBLE, helpText.getVisibility());

    View list = activity.findViewById(R.id.list);
    assertEquals(View.GONE, list.getVisibility());
}
项目:rental-calc    文件:PropertiesListActivityTest.java   
@Test
public void testFirstRunStartsIntro()
{
    prefs.edit().remove("firstrun").commit();

    ActivityController controller = Robolectric.buildActivity(PropertiesListActivity.class).create();
    Activity activity = (Activity)controller.get();

    assertTrue(activity.isFinishing() == false);

    Intent next = shadowOf(activity).getNextStartedActivity();

    ComponentName componentName = next.getComponent();
    String name = componentName.flattenToShortString();
    assertEquals("protect.rentalcalc/.IntroActivity", name);

    Bundle extras = next.getExtras();
    assertNull(extras);

    assertEquals(false, prefs.getBoolean("firstrun", true));
}
项目:rental-calc    文件:ItemizationActivityTest.java   
@Test
public void clickBackFinishes()
{
    ActivityController controller = startWithMap(new HashMap<String, Integer>());
    Activity activity = (Activity)controller.get();
    ShadowActivity shadowActivity = shadowOf(activity);

    assertTrue(shadowActivity.isFinishing() == false);
    shadowActivity.clickMenuItem(android.R.id.home);
    assertTrue(shadowActivity.isFinishing());

    // Check that can finish out the lifecycle
    controller.pause();
    controller.stop();
    controller.destroy();

    // The done menu item was not clicked, so the result should be that
    // the activity was canceled
    assertEquals(Activity.RESULT_CANCELED, shadowActivity.getResultCode());
    assertNull(shadowActivity.getResultIntent());
}
项目:rental-calc    文件:PropertyViewActivityTest.java   
@Test
public void startWithPropertyChangeValues() throws Exception
{
    Property property = new Property();
    preloadProperty(property);

    ActivityController controller = startWithProperty(property);
    Activity activity = (Activity)controller.get();

    checkFields(activity, property);

    property = new Property();
    setFields(activity, property);

    // Check that the values are still valid after a pause and resume.
    controller.pause();
    controller.resume();

    checkFields(activity, property);
}
项目:rental-calc    文件:DictionaryActivityTest.java   
@Test
public void startWithoutRequest()
{
    Intent intent = new Intent();
    final Bundle bundle = new Bundle();
    intent.putExtras(bundle);

    ActivityController controller = Robolectric.buildActivity(DictionaryActivity.class, intent).create();
    Activity activity = (Activity)controller.get();

    controller.start();
    controller.visible();
    controller.resume();
    assertTrue(activity.isFinishing());

    String latestToast = ShadowToast.getTextOfLatestToast();
    assertNotNull(latestToast);
}
项目:rental-calc    文件:DictionaryActivityTest.java   
private ActivityController startWithRequest(DictionaryItem item)
{
    Intent intent = new Intent();
    final Bundle bundle = new Bundle();
    bundle.putInt("title", item.titleId);
    bundle.putInt("definition", item.definitionId);
    if(item.formulaId != null)
    {
        bundle.putInt("formula", item.formulaId);
    }
    intent.putExtras(bundle);

    ActivityController controller = Robolectric.buildActivity(DictionaryActivity.class, intent).create();
    Activity activity = (Activity)controller.get();

    controller.start();
    controller.visible();
    controller.resume();
    assertTrue(activity.isFinishing() == false);

    String latestToast = ShadowToast.getTextOfLatestToast();
    assertNull(latestToast);

    return controller;
}
项目:rental-calc    文件:PropertyProjectionsActivityTest.java   
@Test
public void clickBackFinishes()
{
    ActivityController controller = startWithProperty(new Property());
    Activity activity = (Activity)controller.get();

    controller.start();
    controller.visible();
    controller.resume();

    assertTrue(shadowOf(activity).isFinishing() == false);
    shadowOf(activity).clickMenuItem(android.R.id.home);
    assertTrue(shadowOf(activity).isFinishing());

    // Check that can finish out the lifecycle
    controller.pause();
    controller.stop();
    controller.destroy();
}
项目:rental-calc    文件:PropertyProjectionsActivityTest.java   
private ActivityController startWithProperty(Property property)
{
    long id = db.insertProperty(property);

    Intent intent = new Intent();
    final Bundle bundle = new Bundle();
    bundle.putLong("id", id);
    intent.putExtras(bundle);

    ActivityController controller = Robolectric.buildActivity(PropertyProjectionsActivity.class, intent).create();
    Activity activity = (Activity)controller.get();

    controller.start();
    controller.visible();
    controller.resume();
    assertTrue(activity.isFinishing() == false);

    String latestToast = ShadowToast.getTextOfLatestToast();
    assertNull(latestToast);

    return controller;
}
项目:rental-calc    文件:PropertyProjectionsActivityTest.java   
@Test
public void startWithDefaultProperty() throws Exception
{
    Property property = new Property();

    ActivityController controller = startWithProperty(property);
    Activity activity = (Activity)controller.get();
    SeekBar yearSeeker = (SeekBar)activity.findViewById(R.id.yearSeeker);

    // The first shown year should be year 1, or index 0.
    assertEquals(0, yearSeeker.getProgress());

    Map<Integer, String> expectedValues = new ImmutableMap.Builder<Integer, String>()
            .put(R.id.rentValue, "0")
            .put(R.id.vancancyValue, "0")
            .put(R.id.operatingIncomeValue, "0")
            .put(R.id.operatingExpensesValue, "0")
            .put(R.id.netOperatingIncomeValue, "0")
            .put(R.id.mortgageValue, "0")
            .put(R.id.cashFlowValue, "0")
            .put(R.id.afterTaxCashFlowValue, "0")
            .put(R.id.propertyValueValue, "0")
            .put(R.id.loanBalanceValue, "0")
            .put(R.id.totalEquityValue, "0")
            .put(R.id.depreciationValue, "0")
            .put(R.id.mortgageInterestValue, "0")
            .put(R.id.capitalizationRateValue, "0.0")
            .put(R.id.cashOnCashValue, "0.0")
            .put(R.id.rentToValueValue, "0.0")
            .put(R.id.grossRentMultiplierValue, "0.0")
            .build();

    checkFields(activity, expectedValues);
}
项目:rental-calc    文件:ItemizationActivityTest.java   
@Test
public void startWithoutMap()
{
    Intent intent = new Intent();

    final Bundle bundle = new Bundle();
    bundle.putInt("title", R.string.app_name);
    bundle.putInt("description", R.string.app_name);
    intent.putExtras(bundle);

    ActivityController controller = Robolectric.buildActivity(ItemizeActivity.class, intent).create();
    Activity activity = (Activity)controller.get();

    controller.start();
    assertTrue(activity.isFinishing());

    String latestToast = ShadowToast.getTextOfLatestToast();
    assertNotNull(latestToast);
}
项目:rental-calc    文件:PropertyViewActivityTest.java   
@Test
public void startAsAddCheckActionBar() throws Exception
{
    ActivityController controller = Robolectric.buildActivity(PropertyViewActivity.class).create();
    Activity activity = (Activity)controller.get();

    controller.start();
    controller.visible();
    controller.resume();

    final Menu menu = shadowOf(activity).getOptionsMenu();
    assertNotNull(menu);

    assertEquals(menu.size(), 1);

    MenuItem item = menu.findItem(R.id.action_save);
    assertNotNull(item);
    assertEquals("Save", item.getTitle().toString());
}
项目:rental-calc    文件:PropertyNotesActivityTest.java   
@Test
public void startWithMissingProperty()
{
    Intent intent = new Intent();
    final Bundle bundle = new Bundle();
    bundle.putLong("id", 0);
    intent.putExtras(bundle);

    ActivityController controller = Robolectric.buildActivity(PropertyNotesActivity.class, intent).create();
    Activity activity = (Activity)controller.get();

    assertTrue(activity.isFinishing());

    String latestToast = ShadowToast.getTextOfLatestToast();
    assertNotNull(latestToast);
}
项目:rental-calc    文件:PropertyNotesActivityTest.java   
private ActivityController startWithNotes(String notes)
{
    Property property = new Property();
    property.notes = notes;

    long id = db.insertProperty(property);

    Intent intent = new Intent();
    final Bundle bundle = new Bundle();
    bundle.putLong("id", id);
    intent.putExtras(bundle);

    ActivityController controller = Robolectric.buildActivity(PropertyNotesActivity.class, intent).create();
    Activity activity = (Activity)controller.get();

    assertTrue(activity.isFinishing() == false);

    controller.start();
    controller.visible();
    controller.resume();

    String latestToast = ShadowToast.getTextOfLatestToast();
    assertNull(latestToast);

    return controller;
}
项目:rental-calc    文件:ItemizationActivityTest.java   
private ActivityController startWithMap(Map<String, Integer> map)
{
    Intent intent = new Intent();

    final Bundle bundle = new Bundle();
    bundle.putInt("title", R.string.app_name);
    bundle.putInt("description", R.string.app_name);
    bundle.putSerializable("items", new HashMap<>(map));
    intent.putExtras(bundle);

    ActivityController controller = Robolectric.buildActivity(ItemizeActivity.class, intent).create();
    Activity activity = (Activity)controller.get();

    controller.start();
    controller.visible();
    controller.resume();
    assertTrue(activity.isFinishing() == false);

    String latestToast = ShadowToast.getTextOfLatestToast();
    assertNull(latestToast);

    return controller;
}
项目:rental-calc    文件:PropertyNotesActivityTest.java   
@Test
public void updateNotes()
{
    final String ORIGINAL_MESSAGE = "Multi\nLine\nMessage\n";
    ActivityController controller = startWithNotes(ORIGINAL_MESSAGE);
    Activity activity = (Activity)controller.get();

    EditText notes = (EditText)activity.findViewById(R.id.notes);
    final String NEW_MESSAGE = "This is the new message";
    notes.setText(NEW_MESSAGE);

    assertNotNull(shadowOf(activity).getOptionsMenu().findItem(R.id.action_save));
    shadowOf(activity).clickMenuItem(R.id.action_save);

    assertTrue(activity.isFinishing());

    Property property = db.getProperty(DatabaseTestHelper.FIRST_ID);
    assertNotNull(property);
    assertEquals(NEW_MESSAGE, property.notes);
}
项目:rental-calc    文件:PropertyNotesActivityTest.java   
@Test
public void cancelDoesNotUpdateNotes()
{
    final String ORIGINAL_MESSAGE = "Multi\nLine\nMessage\n";
    ActivityController controller = startWithNotes(ORIGINAL_MESSAGE);
    Activity activity = (Activity)controller.get();

    EditText notes = (EditText)activity.findViewById(R.id.notes);
    final String NEW_MESSAGE = "This is the new message";
    notes.setText(NEW_MESSAGE);

    shadowOf(activity).clickMenuItem(android.R.id.home);

    assertTrue(activity.isFinishing());

    Property property = db.getProperty(DatabaseTestHelper.FIRST_ID);
    assertNotNull(property);
    assertEquals(ORIGINAL_MESSAGE, property.notes);
}
项目:rental-calc    文件:PropertyViewActivityTest.java   
@Test
public void clickBackFinishes()
{
    ActivityController controller = Robolectric.buildActivity(PropertyViewActivity.class).create();
    Activity activity = (Activity)controller.get();

    controller.start();
    controller.visible();
    controller.resume();

    assertTrue(shadowOf(activity).isFinishing() == false);
    shadowOf(activity).clickMenuItem(android.R.id.home);
    assertTrue(shadowOf(activity).isFinishing());

    // Check that can finish out the lifecycle
    controller.pause();
    controller.stop();
    controller.destroy();
}
项目:rental-calc    文件:PropertyWorksheetActivityTest.java   
@Test
public void startWithoutProperty()
{
    Intent intent = new Intent();
    final Bundle bundle = new Bundle();
    intent.putExtras(bundle);

    ActivityController controller = Robolectric.buildActivity(PropertyWorksheetActivity.class, intent).create();
    Activity activity = (Activity)controller.get();

    controller.start();
    assertTrue(activity.isFinishing());

    String latestToast = ShadowToast.getTextOfLatestToast();
    assertNotNull(latestToast);
}
项目:rental-calc    文件:PropertyWorksheetActivityTest.java   
private ActivityController startWithProperty(Property property)
{
    long id = db.insertProperty(property);

    Intent intent = new Intent();
    final Bundle bundle = new Bundle();
    bundle.putLong("id", id);
    intent.putExtras(bundle);

    ActivityController controller = Robolectric.buildActivity(PropertyWorksheetActivity.class, intent).create();
    Activity activity = (Activity)controller.get();

    controller.start();
    controller.visible();
    controller.resume();
    assertTrue(activity.isFinishing() == false);

    String latestToast = ShadowToast.getTextOfLatestToast();
    assertNull(latestToast);

    return controller;
}