本文整理汇总了Java中org.robolectric.android.controller.ActivityController类的典型用法代码示例。如果您正苦于以下问题:Java ActivityController类的具体用法?Java ActivityController怎么用?Java ActivityController使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ActivityController类属于org.robolectric.android.controller包,在下文中一共展示了ActivityController类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testBindActivity
import org.robolectric.android.controller.ActivityController; //导入依赖的package包/类
@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);
}
示例2: testActivityObservableBindLifecycle
import org.robolectric.android.controller.ActivityController; //导入依赖的package包/类
@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();
}
示例3: onCreate_withSaveInstanceState_shouldForwardToRootRiblet
import org.robolectric.android.controller.ActivityController; //导入依赖的package包/类
@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);
}
示例4: rxActivity_shouldCallback_onLowMemory
import org.robolectric.android.controller.ActivityController; //导入依赖的package包/类
@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));
}
示例5: ribActivity_onSaveInstanceStateAndCallbackFlagEnabled_shouldEmitToCallbacks
import org.robolectric.android.controller.ActivityController; //导入依赖的package包/类
@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");
}
示例6: rxActivity_shouldCallback_onActivityResult
import org.robolectric.android.controller.ActivityController; //导入依赖的package包/类
@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");
}
示例7: startWithoutTitle
import org.robolectric.android.controller.ActivityController; //导入依赖的package包/类
@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);
}
示例8: startWithFile
import org.robolectric.android.controller.ActivityController; //导入依赖的package包/类
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;
}
示例9: clickBackFinishes
import org.robolectric.android.controller.ActivityController; //导入依赖的package包/类
@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());
}
示例10: doneNoItems
import org.robolectric.android.controller.ActivityController; //导入依赖的package包/类
@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);
}
示例11: startWithoutProperty
import org.robolectric.android.controller.ActivityController; //导入依赖的package包/类
@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);
}
示例12: startWithMissingProperty
import org.robolectric.android.controller.ActivityController; //导入依赖的package包/类
@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);
}
示例13: checkOpenActivity
import org.robolectric.android.controller.ActivityController; //导入依赖的package包/类
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);
}
示例14: clickBackFinishes
import org.robolectric.android.controller.ActivityController; //导入依赖的package包/类
@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();
}
示例15: startWithMissingProperty
import org.robolectric.android.controller.ActivityController; //导入依赖的package包/类
@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);
}