本文整理匯總了Java中org.robolectric.util.ActivityController類的典型用法代碼示例。如果您正苦於以下問題:Java ActivityController類的具體用法?Java ActivityController怎麽用?Java ActivityController使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
ActivityController類屬於org.robolectric.util包,在下文中一共展示了ActivityController類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: testWindowsFocusChanged
import org.robolectric.util.ActivityController; //導入依賴的package包/類
@Test
public void testWindowsFocusChanged() throws Exception {
BaseChromiumApplication app = (BaseChromiumApplication) Robolectric.application;
WindowFocusChangedListener mock = mock(WindowFocusChangedListener.class);
app.registerWindowFocusChangedListener(mock);
ActivityController<Activity> controller =
Robolectric.buildActivity(Activity.class).create().start().visible();
TrackingShadowActivity shadow =
(TrackingShadowActivity) Robolectric.shadowOf(controller.get());
controller.get().getWindow().getCallback().onWindowFocusChanged(true);
// Assert that listeners were notified.
verify(mock).onWindowFocusChanged(controller.get(), true);
// Also ensure that the original activity is forwarded the notification.
Assert.assertEquals(1, shadow.mWindowFocusCalls);
}
示例2: setUp
import org.robolectric.util.ActivityController; //導入依賴的package包/類
@Override
public void setUp() throws Exception {
super.setUp();
RecipeListActivity recipeListActivity = new RecipeListActivity() {
@Override
public void setTheme(int resid) {
super.setTheme(R.style.AppTheme_NoActionBar);
}
public RecipesAdapter getAdapter() {
return adapter;
}
public RecipeListPresenter getPresenter() {
return presenter;
}
};
controller = ActivityController.of(Robolectric.getShadowsAdapter(), recipeListActivity).create().visible();
activity = controller.get();
view = (RecipeListView)activity;
onItemClickListener = (OnItemClickListener)activity;
shadowActivity = shadowOf(activity);
}
示例3: setUp
import org.robolectric.util.ActivityController; //導入依賴的package包/類
@Override
public void setUp() throws Exception {
super.setUp();
RecipeMainActivity recipeMainActivity = new RecipeMainActivity() {
public ImageLoader getImageLoader() {
return imageLoader;
}
public RecipeMainPresenter getPresenter() {
return presenter;
}
};
controller = ActivityController.of(Robolectric.getShadowsAdapter(), recipeMainActivity).create().visible();
activity = controller.get();
view = (RecipeMainView) activity;
shadowAcivity = shadowOf(activity);
}
示例4: testLifecycle
import org.robolectric.util.ActivityController; //導入依賴的package包/類
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
);
}
示例5: testBindUntilEvent
import org.robolectric.util.ActivityController; //導入依賴的package包/類
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();
}
示例6: testLifecycle
import org.robolectric.util.ActivityController; //導入依賴的package包/類
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
);
}
示例7: testBindUntilEvent
import org.robolectric.util.ActivityController; //導入依賴的package包/類
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();
}
示例8: testLifecycle
import org.robolectric.util.ActivityController; //導入依賴的package包/類
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
);
}
示例9: testBindUntilEvent
import org.robolectric.util.ActivityController; //導入依賴的package包/類
private void testBindUntilEvent(ActivityController<? extends LifecycleProvider<ActivityEvent>> controller) {
LifecycleProvider<ActivityEvent> activity = controller.get();
TestObserver<Object> testObserver = observable.compose(activity.bindUntilEvent(STOP)).test();
controller.create();
testObserver.assertNotComplete();
controller.start();
testObserver.assertNotComplete();
controller.resume();
testObserver.assertNotComplete();
controller.pause();
testObserver.assertNotComplete();
controller.stop();
testObserver.assertComplete();
}
示例10: LoadReceipt
import org.robolectric.util.ActivityController; //導入依賴的package包/類
@Test
public void LoadReceipt()
{
Intent intent = new Intent();
final Bundle bundle = new Bundle();
bundle.putString("receipt", "receipt");
intent.putExtras(bundle);
ActivityController activityController = Robolectric.buildActivity(
ReceiptViewActivity.class).withIntent(intent).create();
activityController.start();
activityController.resume();
Activity activity = (Activity)activityController.get();
WebView receiptView = (WebView)activity.findViewById(R.id.imageView);
ShadowWebView.LoadDataWithBaseURL loadedData = shadowOf(receiptView).getLastLoadDataWithBaseURL();
assertEquals("", loadedData.baseUrl);
assertEquals("text/html", loadedData.mimeType);
assertEquals("utf-8", loadedData.encoding);
assertNull(loadedData.historyUrl);
assertTrue(loadedData.data.contains("src=\"file://receipt\""));
}
示例11: applyState
import org.robolectric.util.ActivityController; //導入依賴的package包/類
private void applyState(ActivityState state,
ActivityController controller) {
switch (state) {
case STARTED:
controller.start();
break;
case RESUMED:
controller.resume();
break;
case PAUSED:
controller.pause();
break;
case STOPPED:
controller.stop();
break;
case DESTROYED:
controller.destroy();
break;
case CREATED:
default:
controller.create();
break;
}
}
示例12: testPresenterReceivesPermissionWhenRequestedFromActivity
import org.robolectric.util.ActivityController; //導入依賴的package包/類
@Test
public void testPresenterReceivesPermissionWhenRequestedFromActivity() {
TodayWeatherPresenterBuilder builder = new TodayWeatherPresenterBuilder(
new TodayWeatherFragmentController(new TodayWeatherFragment(), MainActivity.class), provider)
.in(R.id.container);
TodayWeatherPresenterBuilder.BindingResult bindingResult = configurePresenter(builder, ViewType.REAL, PresenterType.MOCK);
TodayWeatherPresenter presenter = bindingResult.presenter();
ActivityController<MainActivity> controller = Robolectric.buildActivity(MainActivity.class);
controller.setup();
String[] permissions = {Manifest.permission.ACCESS_COARSE_LOCATION};
int[] grantResults = {PackageManager.PERMISSION_GRANTED};
MainActivity mainActivity = controller.get();
mainActivity.onRequestPermissionsResult(1, permissions, grantResults);
verify(presenter).onEventPermissionsResult(eq(new PermissionEvent(1, permissions, grantResults)));
}
示例13: testOpenExternalComment
import org.robolectric.util.ActivityController; //導入依賴的package包/類
@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();
}
示例14: whenTheActivityIsStoppedThenTheGroceryLocatorServiceIsStartedWithoutGPSExtra
import org.robolectric.util.ActivityController; //導入依賴的package包/類
@Test
public void whenTheActivityIsStoppedThenTheGroceryLocatorServiceIsStartedWithoutGPSExtra() {
ActivityController<GroceryStoresActivity> activityController = Robolectric.buildActivity(GroceryStoresActivity.class);;
activityController.create().start().get();
ShadowLocation.setDistanceBetween(new float[]{(float) GroceryReminderConstants.LOCATION_SEARCH_RADIUS_METERS});
activityController.pause().stop();
ShadowActivity shadowActivity = (ShadowActivity)Shadows.shadowOf(activity);
Intent serviceIntent = shadowActivity.peekNextStartedService();
assertEquals(GroceryLocatorService.class.getCanonicalName(), serviceIntent.getComponent().getClassName());
assertFalse(serviceIntent.getBooleanExtra(GroceryReminderConstants.LISTEN_FOR_GPS_EXTRA, false));
activityController.destroy();
}
示例15: onLoginLoad_withEmptyScopes_shouldReturnErrorResultIntent
import org.robolectric.util.ActivityController; //導入依賴的package包/類
@Test
public void onLoginLoad_withEmptyScopes_shouldReturnErrorResultIntent() {
Intent intent = new Intent();
intent.putExtra(LoginActivity.EXTRA_SESSION_CONFIGURATION, new SessionConfiguration.Builder().setClientId("clientId").build());
ActivityController<LoginActivity> controller = Robolectric.buildActivity(LoginActivity.class)
.withIntent(intent)
.create();
ShadowActivity shadowActivity = shadowOf(controller.get());
assertThat(shadowActivity.getResultCode()).isEqualTo(Activity.RESULT_CANCELED);
assertThat(shadowActivity.getResultIntent()).isNotNull();
assertThat(getScopeFromIntent(shadowActivity.getResultIntent()))
.isEqualTo(AuthenticationError.INVALID_SCOPE);
assertThat(shadowActivity.isFinishing()).isTrue();
}