Java 类org.robolectric.util.ActivityController 实例源码

项目:chromium-net-for-android    文件:BaseChromiumApplicationTest.java   
@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);
}
项目:androidadvanced    文件:RecipeListActivityTest.java   
@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);
}
项目:androidadvanced    文件:RecipeMainActivityTest.java   
@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);
}
项目:RxLifeCycle    文件:AndroidLifecycleActivityTest.java   
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
    );
}
项目:RxLifeCycle    文件:AndroidLifecycleActivityTest.java   
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();
}
项目:RxLifeCycle    文件:AndroidLifecycleFragmentTest.java   
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
    );
}
项目:RxLifeCycle    文件:AndroidLifecycleFragmentTest.java   
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();
}
项目:RxLifeCycle    文件:RxActivityLifecycleTest.java   
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
    );
}
项目:RxLifeCycle    文件:RxActivityLifecycleTest.java   
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();
}
项目:gift-card-guard    文件:ReceiptViewActivityTest.java   
@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\""));
}
项目:AndroidUnitTest    文件:ControllerActivity.java   
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;
    }
}
项目:annotated-mvp    文件:PermissionTest.java   
@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)));
}
项目:materialistic    文件:AppUtilsTest.java   
@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();
}
项目:grocery-reminder    文件:GroceryStoresActivityTest.java   
@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();
}
项目:rides-android-sdk    文件:LoginActivityTest.java   
@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();
}
项目:rides-android-sdk    文件:OAuthWebViewClientTest.java   
@Test
public void onLoadLoginView_withNoRedirectUrl_shouldReturnError() {
    SessionConfiguration config = new SessionConfiguration.Builder().setClientId("clientId").build();
    Intent intent = new Intent();
    intent.putExtra(LoginActivity.EXTRA_SESSION_CONFIGURATION, config);
    final ActivityController<LoginActivity> controller = Robolectric.buildActivity(LoginActivity.class)
            .withIntent(intent);
    final ShadowActivity shadowActivity = Shadows.shadowOf(controller.get());

    controller.create();

    assertThat(shadowActivity.isFinishing()).isTrue();
    assertThat(shadowActivity.getResultCode()).isEqualTo(Activity.RESULT_CANCELED);
    assertThat(shadowActivity.getResultIntent()).isNotNull();
    assertThat(shadowActivity.getResultIntent().getStringExtra(LoginManager.EXTRA_ERROR)).isNotEmpty();
}
项目:bikeon-android-app    文件:LoginActivityTest.java   
@Test
public void itShouldVerifySessionOnResume() {
    // given
    LoginPresenter loginPresenter = mock(LoginPresenter.class);

    ActivityController<LoginActivity> controller = Robolectric.buildActivity(LoginActivity.class);

    LoginActivity activity = controller.create().get();
    activity.presenter = loginPresenter;

    // when
    controller.resume();

    //then
    verify(loginPresenter).verifySession();
}
项目:bikeon-android-app    文件:LoginActivityTest.java   
@Test
public void itShouldRequestFacebookLoginWhenClickFacebookButton() {
    // given
    LoginPresenter loginPresenter = mock(LoginPresenter.class);

    ActivityController<LoginActivity> controller = Robolectric.buildActivity(LoginActivity.class);

    LoginActivity activity = controller.create().get();
    activity.presenter = loginPresenter;
    controller.resume();

    // when
    activity.btnFacebookLogin.callOnClick();

    // then
    verify(loginPresenter).requestLogin(any(LoginStrategyChooser.class),
            eq(LoginStrategy.FACEBOOK), eq(activity));
}
项目:bikeon-android-app    文件:LoginActivityTest.java   
@Test
public void itShouldFinishWhenGoToMain() {
    // given
    LoginPresenter loginPresenter = mock(LoginPresenter.class);

    ActivityController<LoginActivity> controller = Robolectric.buildActivity(LoginActivity.class);

    LoginActivity activity = controller.create().get();
    activity.presenter = loginPresenter;
    controller.resume();

    // when
    activity.gotoMainActivity();

    // then
    assertTrue(activity.isFinishing());
}
项目:openwebnet-android    文件:MainActivityTest.java   
@Test
public void shouldVerifyInstance_stateTitle() {
    when(environmentService.findAll()).thenReturn(Observable.<List<EnvironmentModel>>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());
}
项目:Fabric-Example-App-Android    文件:MoPubActivityTest.java   
@Before
public void setUp() throws Exception {
    htmlInterstitialWebView = TestHtmlInterstitialWebViewFactory.getSingletonMock();
    resetMockedView(htmlInterstitialWebView);

    Context context = Robolectric.buildActivity(Activity.class).create().get();
    Intent moPubActivityIntent = MoPubActivity.createIntent(context,
            EXPECTED_HTML_DATA, mockAdReport, EXPECTED_IS_SCROLLABLE,
            EXPECTED_REDIRECT_URL,
            EXPECTED_CLICKTHROUGH_URL, EXPECTED_ORIENTATION, testBroadcastIdentifier);

    final ActivityController<MoPubActivity> subjectController = Robolectric.buildActivity(MoPubActivity.class).withIntent(moPubActivityIntent);
    subject = subjectController.get();
    ShadowLocalBroadcastManager.getInstance(subject).registerReceiver(broadcastReceiver, getHtmlInterstitialIntentFilter());
    subjectController.create();

    customEventInterstitialListener = mock(CustomEventInterstitialListener.class);
}
项目:edx-app-android    文件:CourseBaseActivityTest.java   
/**
 * Testing initialization
 */
@Test
@SuppressLint("RtlHardcoded")
public void initializeTest() {
    ActivityController<? extends CourseBaseActivity> controller =
            Robolectric.buildActivity(getActivityClass()).withIntent(getIntent());
    CourseBaseActivity activity = controller.get();

    controller.create();
    assertNotNull(activity.findViewById(R.id.last_accessed_bar));
    DrawerLayout drawerLayout = (DrawerLayout)
            activity.findViewById(R.id.drawer_layout);
    if (drawerLayout != null) {
        assertEquals(DrawerLayout.LOCK_MODE_LOCKED_CLOSED,
                drawerLayout.getDrawerLockMode(Gravity.LEFT));
        assertEquals(DrawerLayout.LOCK_MODE_LOCKED_CLOSED,
                drawerLayout.getDrawerLockMode(Gravity.RIGHT));
    }

    controller.postCreate(null).resume().postResume().visible();
}
项目:edx-app-android    文件:CourseBaseActivityTest.java   
/**
 * Testing process start and finish method functionality
 */
@Test
public void processLifecycleTest() {
    // We need to retrieve the progressWheel view before calling visible(), since that
    // initializes fragment views as well, which might add other views with the same id
    ActivityController<? extends CourseBaseActivity> controller =
            Robolectric.buildActivity(getActivityClass()).withIntent(getIntent())
                    .create().start().postCreate(null).resume();
    CourseBaseActivity activity = controller.get();
    ProgressBar progressWheel = (ProgressBar)
            activity.findViewById(R.id.loading_indicator);
    controller.visible();
    if (progressWheel == null) {
        activity.startProcess();
        activity.finishProcess();
    } else {
        assertThat(progressWheel).isNotVisible();
        activity.startProcess();
        assertThat(progressWheel).isVisible();
        activity.finishProcess();
        assertThat(progressWheel).isNotVisible();
    }
}
项目:edx-app-android    文件:CourseOutlineActivityTest.java   
/**
 * Generic method for running the initialization tests and returning the
 * controller.
 *
 * @param intent The {@link Intent} to start the {@link CourseOutlineActivity} with
 * @return The {@link ActivityController} instance used to initialize the
 *         {@link CourseOutlineActivity}
 */
private ActivityController<? extends CourseOutlineActivity> initialize(Intent intent) {
    ActivityController<? extends CourseOutlineActivity> controller =
            Robolectric.buildActivity(getActivityClass()).withIntent(intent);
    CourseOutlineActivity activity = controller.create(null).postCreate(null).get();
    // TODO: Write a comprehensive and isolated test suite for the Fragment
    Fragment fragment = activity.getSupportFragmentManager()
            .findFragmentByTag(CourseOutlineFragment.TAG);
    assertNotNull(fragment);
    assertThat(fragment).isInstanceOf(CourseOutlineFragment.class);
    assertTrue(fragment.getRetainInstance());
    Bundle args = fragment.getArguments();
    assertNotNull(args);
    Bundle data = intent.getBundleExtra(Router.EXTRA_BUNDLE);
    assertEquals(data.getSerializable(Router.EXTRA_COURSE_DATA),
            args.getSerializable(Router.EXTRA_COURSE_DATA));
    if (provideCourseId) {
        assertEquals(data.getString(Router.EXTRA_COURSE_COMPONENT_ID),
                args.getString(Router.EXTRA_COURSE_COMPONENT_ID));
    }
    return controller;
}
项目:pocketknife    文件:KeyGenTest.java   
@Test
public void testArgKeyGeneration() {
    String s = UUID.randomUUID().toString();
    int i = new Random(42).nextInt();

    Bundle bundle = new Bundle();
    bundle.putString("ARG_A_STRING", s);
    bundle.putInt("ARG_AN_INT", i);

    ActivityController<SimpleFragmentActivity> initialController = Robolectric.buildActivity(SimpleFragmentActivity.class).create();
    SimpleFragmentActivity simpleActivity = initialController.start().restart().visible().get();
    KeyGenFragment fragment = KeyGenFragment.newInstance();
    fragment.setArguments(bundle);
    simpleActivity.replaceFragment(fragment);

    assertEquals(s, fragment.aString);
    assertEquals(i, fragment.anInt);
}
项目:pocketknife    文件:MultiAnnotationTest.java   
@Test
public void testMultiAnnotationActivity() throws Exception {
    Random random = new Random();

    Intent intent = new Intent(RuntimeEnvironment.application, MultiAnnotationActivity.class);
    int extraInt = random.nextInt();
    intent.putExtra(MultiAnnotationActivity.EXTRA_INT, extraInt);

    ActivityController<MultiAnnotationActivity> saveController = Robolectric.buildActivity(MultiAnnotationActivity.class).withIntent(intent).create();
    MultiAnnotationActivity activity = saveController.start().restart().visible().get();

    assertEquals(extraInt, activity.i);

    int activityInt = random.nextInt();
    activity.i = activityInt;


    Bundle saveState = new Bundle();
    saveController.saveInstanceState(saveState);

    ActivityController<MultiAnnotationActivity> restoreController = Robolectric.buildActivity(MultiAnnotationActivity.class).withIntent(intent)
            .create(saveState);
    activity = restoreController.start().restart().visible().get();

    assertEquals(activityInt, activity.i);
}
项目:binding-tc    文件:LoginFillRobolectricTest.java   
@Test
public void test_00_MainActivity_FullLifecycle() {
  final ActivityController<MainActivity> controller = Robolectric.buildActivity(MainActivity.class);
  final MainActivity activity = controller.get();

  assertThat(activity, notNullValue());

  fullLifecycle(controller, new Runnable() {
    @Override
    public void run() {
      // binding manager instance should be available
      assertThat(activity.getBindingsManager(), notNullValue());

      // main activity does not have any bindings
      assertThat(activity.getBindingsManager().getBindings(), hasSize(0));
    }
  });
}
项目:binding-tc    文件:PinRobolectricTest.java   
@Test
public void test_00_FullLifeCycle_WithIntent() {
  final Intent intent = MainActivity.showPin(RuntimeEnvironment.application);
  final ActivityController<MainActivity> controller = Robolectric.buildActivity(MainActivity.class).withIntent(intent);
  final MainActivity activity = controller.get();

  assertThat(activity, notNullValue());

  fullLifecycle(controller, new Runnable() {
    @Override
    public void run() {
      final TextView tv = (TextView) activity.findViewById(R.id.tv_feedback);

      // tv_feedback is available only on PinFragment
      assertThat(tv, notNullValue());

      trace("PinFragment found");
    }
  });
}
项目:Yarrn    文件:AbstractRavelryActivityUnitTest.java   
@Before
public void prepare() {
    MockitoAnnotations.initMocks(this);

    ActivityController<MainActivity_> activityController = Robolectric.buildActivity(MainActivity_.class);
    activityController.create();
    activity = activityController.get();

    activity.service = oauthService;
    activity.networkHelper = networkHelper;

    TestUtil.mockBackgroundExecutor();
    TestUtil.mockValidUser(activity.prefs);

    AQUtility.setExceptionHandler(exceptionHandler);
}
项目:Yarrn    文件:ProjectFragmentUnitTest.java   
@Before
public void prepare() {
    MockitoAnnotations.initMocks(this);
    TestUtil.mockBackgroundExecutor();

    projectFragment = new ProjectFragment_();
    projectFragment.spiceManager = this.spiceManager;
    ActivityController<MainActivity_> activityController = Robolectric.buildActivity(MainActivity_.class).create();
    MainActivity activity = activityController.get();
    TestUtil.mockValidUser(activity.prefs);
    activity.fragmentFactory = this.fragmentFactory;
    given(fragmentFactory.getProjectsFragment()).willReturn(projectsFragment);
    given(fragmentFactory.getProjectFragment()).willReturn(projectFragment);
    activityController.start().resume();

    activity.onProjectSelected(PROJECT_ID, USERNAME);
}
项目:Yarrn    文件:FavoritesFragmentUnitTest.java   
@Before
public void prepare() {
    MockitoAnnotations.initMocks(this);
    TestUtil.mockBackgroundExecutor();
    favoritesFragment = new FavoritesFragment_();
    favoritesFragment.spiceManager = this.spiceManager;
    ActivityController<MainActivity_> activityController = Robolectric.buildActivity(MainActivity_.class).create();
    activity = activityController.get();
    favoritesFragment.prefs = activity.prefs;
    TestUtil.mockValidUser(activity.prefs);
    activity.fragmentFactory = this.fragmentFactory;
    given(fragmentFactory.getProjectsFragment()).willReturn(projectsFragment);
    given(fragmentFactory.getFavoritesFragment()).willReturn(favoritesFragment);
    activityController.start().resume();
    activity.menuMyFavoritesClicked();
}
项目:HoebApp    文件:PreferencesActivityTest.java   
@Before
public void setUp() {
    MockitoAnnotations.initMocks(this);

    ActivityController<PreferencesActivity_> activityController = Robolectric.buildActivity(PreferencesActivity_.class);
    activityController.create();
    activity = activityController.get();

    prefs = activity.prefs;

    doAutoUpdate = (CheckBox) activity.findViewById(R.id.doAutoUpdate);
    doAutoUpdateWifiOnly = (CheckBox) activity
            .findViewById(R.id.doAutoUpdateWifiOnly);
    accountList = (ListView) activity.findViewById(R.id.accountList);
    addAccount = (Button) activity.findViewById(R.id.addAccount);
}
项目:RxActivityResults    文件:RxActivityResultsTest.java   
@Before
public void setUp() {

    ActivityController<Activity> activityController =
            Robolectric.buildActivity(Activity.class);
    activity = spy(activityController.setup().get());

    rxActivityResults = spy(new RxActivityResults(activity));
    rxActivityResults.mRxActivityResultsFragment =
            spy(rxActivityResults.mRxActivityResultsFragment);

    when(rxActivityResults.mRxActivityResultsFragment.getActivity())
            .thenReturn(activity);

}
项目:andcoachmark    文件:CoachmarkViewTest.java   
@Before
public void init() {
    ActivityController<Activity> activityController = Robolectric.buildActivity(Activity.class).create().start().resume()
            .visible();

    mActivity = activityController.get();

    mView = new CoachmarkView(mActivity);
}
项目:RxLifeCycle    文件:AndroidLifecycleActivityTest.java   
private void testBindToLifecycle(ActivityController<? extends LifecycleOwner> controller) {
    LifecycleProvider<Lifecycle.Event> provider = AndroidLifecycle.createLifecycleProvider(controller.get());

    controller.create();
    TestObserver<Object> createObserver = observable.compose(provider.bindToLifecycle()).test();

    controller.start();
    createObserver.assertNotComplete();
    TestObserver<Object> startObserver = observable.compose(provider.bindToLifecycle()).test();

    controller.resume();
    createObserver.assertNotComplete();
    startObserver.assertNotComplete();
    TestObserver<Object> resumeObserver = observable.compose(provider.bindToLifecycle()).test();

    controller.pause();
    createObserver.assertNotComplete();
    startObserver.assertNotComplete();
    resumeObserver.assertComplete();
    TestObserver<Object> pauseObserver = observable.compose(provider.bindToLifecycle()).test();

    controller.stop();
    createObserver.assertNotComplete();
    startObserver.assertComplete();
    pauseObserver.assertComplete();
    TestObserver<Object> stopObserver = observable.compose(provider.bindToLifecycle()).test();

    controller.destroy();
    createObserver.assertComplete();
    stopObserver.assertComplete();
}
项目:RxLifeCycle    文件:AndroidLifecycleFragmentTest.java   
private void testBindToLifecycle(LifecycleOwner owner) {
    Fragment fragment = (Fragment) owner;
    LifecycleProvider<Lifecycle.Event> provider = AndroidLifecycle.createLifecycleProvider(owner);
    ActivityController<?> controller = startFragment(fragment);

    TestObserver<Object> createObserver = observable.compose(provider.bindToLifecycle()).test();

    controller.start();
    createObserver.assertNotComplete();
    TestObserver<Object> startObserver = observable.compose(provider.bindToLifecycle()).test();

    controller.resume();
    createObserver.assertNotComplete();
    startObserver.assertNotComplete();
    TestObserver<Object> resumeObserver = observable.compose(provider.bindToLifecycle()).test();

    controller.pause();
    createObserver.assertNotComplete();
    startObserver.assertNotComplete();
    resumeObserver.assertComplete();
    TestObserver<Object> pauseObserver = observable.compose(provider.bindToLifecycle()).test();

    controller.stop();
    createObserver.assertNotComplete();
    startObserver.assertComplete();
    pauseObserver.assertComplete();
    TestObserver<Object> stopObserver = observable.compose(provider.bindToLifecycle()).test();

    controller.destroy();
    createObserver.assertComplete();
    stopObserver.assertComplete();
}
项目:RxLifeCycle    文件:AndroidLifecycleFragmentTest.java   
private ActivityController<FragmentActivity> startFragment(Fragment fragment) {
    ActivityController<FragmentActivity> controller = Robolectric.buildActivity(FragmentActivity.class);
    controller.create();
    controller.get().getSupportFragmentManager()
            .beginTransaction()
            .add(android.R.id.content, fragment)
            .commitNow();
    return controller;
}
项目:RxLifeCycle    文件:RxActivityLifecycleTest.java   
private void testBindToLifecycle(ActivityController<? extends LifecycleProvider<ActivityEvent>> controller) {
    LifecycleProvider<ActivityEvent> activity = controller.get();

    controller.create();
    TestObserver<Object> createObserver = observable.compose(activity.bindToLifecycle()).test();

    controller.start();
    createObserver.assertNotComplete();
    TestObserver<Object> startObserver = observable.compose(activity.bindToLifecycle()).test();

    controller.resume();
    createObserver.assertNotComplete();
    startObserver.assertNotComplete();
    TestObserver<Object> resumeObserver = observable.compose(activity.bindToLifecycle()).test();

    controller.pause();
    createObserver.assertNotComplete();
    startObserver.assertNotComplete();
    resumeObserver.assertComplete();
    TestObserver<Object> pauseObserver = observable.compose(activity.bindToLifecycle()).test();

    controller.stop();
    createObserver.assertNotComplete();
    startObserver.assertComplete();
    pauseObserver.assertComplete();
    TestObserver<Object> stopObserver = observable.compose(activity.bindToLifecycle()).test();

    controller.destroy();
    createObserver.assertComplete();
    stopObserver.assertComplete();
}
项目:gift-card-guard    文件:MainActivityTest.java   
@Test
public void addOneGiftCard()
{
    ActivityController activityController = Robolectric.buildActivity(MainActivity.class).create();

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

    TextView helpText = (TextView)mainActivity.findViewById(R.id.helpText);
    ListView list = (ListView)mainActivity.findViewById(R.id.list);

    assertEquals(0, list.getCount());

    DBHelper db = new DBHelper(mainActivity);
    db.insertGiftCard("store", "cardId", "value", "receipt");

    assertEquals(View.VISIBLE, helpText.getVisibility());
    assertEquals(View.GONE, list.getVisibility());

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

    assertEquals(View.GONE, helpText.getVisibility());
    assertEquals(View.VISIBLE, list.getVisibility());

    assertEquals(1, list.getAdapter().getCount());
    Cursor cursor = (Cursor)list.getAdapter().getItem(0);
    assertNotNull(cursor);
}
项目:android-auth    文件:LoginActivityTest.java   
@Test
public void shouldFinishLoginActivityWhenCompleted() {

    Activity context = Robolectric
            .buildActivity(Activity.class)
            .create()
            .get();

    AuthenticationRequest request = new AuthenticationRequest.Builder("test", AuthenticationResponse.Type.TOKEN, "test://test").build();
    AuthenticationResponse response = new AuthenticationResponse.Builder()
            .setType(AuthenticationResponse.Type.TOKEN)
            .setAccessToken("test_token")
            .setExpiresIn(3600)
            .build();

    Bundle bundle = new Bundle();
    bundle.putParcelable(LoginActivity.REQUEST_KEY, request);

    Intent intent = new Intent(context, LoginActivity.class);
    intent.putExtra(LoginActivity.EXTRA_AUTH_REQUEST, bundle);

    ActivityController<LoginActivity> loginActivityActivityController = buildActivity(LoginActivity.class)
            .withIntent(intent);

    final LoginActivity loginActivity = loginActivityActivityController.get();

    final ShadowActivity shadowLoginActivity = shadowOf(loginActivity);
    shadowLoginActivity.setCallingActivity(context.getComponentName());

    loginActivityActivityController.create();

    assertFalse(loginActivity.isFinishing());

    loginActivity.onClientComplete(response);

    assertTrue(loginActivity.isFinishing());
    assertEquals(Activity.RESULT_OK, shadowLoginActivity.getResultCode());
    assertEquals(response, shadowLoginActivity.getResultIntent().getBundleExtra(LoginActivity.EXTRA_AUTH_RESPONSE).get(LoginActivity.RESPONSE_KEY));
}