Java 类org.robolectric.Robolectric 实例源码

项目: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    文件: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);
}
项目: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);
}
项目:DateRangePickerLibrary    文件:CalendarPickerViewTest.java   
@Before public void setUp() throws Exception {
  activity = Robolectric.buildActivity(Activity.class).create().start().resume().get();
  timeZone = TimeZone.getTimeZone("GMT+06:00");
  locale = Locale.US;
  view = new CalendarPickerView(activity, null);
  today = Calendar.getInstance(timeZone, locale);
  today.set(2012, NOVEMBER, 16, 0, 0);
  minDate = today.getTime();
  today.set(2013, NOVEMBER, 16, 0, 0);
  maxDate = today.getTime();
  today.set(2012, NOVEMBER, 16, 0, 0);
  Date startDate = today.getTime();
  view.init(minDate, maxDate, timeZone, locale) //
      .inMode(SINGLE) //
      .withSelectedDate(startDate);

  // Do not change the internal state of the CalendarPickerView until init() has run.
  view.today.setTime(startDate);
}
项目:q-mail    文件:RecipientPresenterTest.java   
@Before
public void setUp() throws Exception {
    Context context = ShadowApplication.getInstance().getApplicationContext();
    Robolectric.getBackgroundThreadScheduler().pause();

    recipientMvpView = mock(RecipientMvpView.class);
    account = mock(Account.class);
    composePgpInlineDecider = mock(ComposePgpInlineDecider.class);
    composePgpEnableByDefaultDecider = mock(ComposePgpEnableByDefaultDecider.class);
    autocryptStatusInteractor = mock(AutocryptStatusInteractor.class);
    replyToParser = mock(ReplyToParser.class);
    LoaderManager loaderManager = mock(LoaderManager.class);
    listener = mock(RecipientPresenter.RecipientsChangedListener.class);

    recipientPresenter = new RecipientPresenter(
            context, loaderManager, recipientMvpView, account, composePgpInlineDecider,
            composePgpEnableByDefaultDecider, autocryptStatusInteractor, replyToParser, listener);
    runBackgroundTask();

    noRecipientsAutocryptResult = new RecipientAutocryptStatus(RecipientAutocryptStatusType.NO_RECIPIENTS, null);
}
项目: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);
}
项目: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    文件: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    文件:PropertyProjectionsActivityTest.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(PropertyProjectionsActivity.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    文件: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));
}
项目:ucar-weex-core    文件:WXImageTest.java   
@Test
public void testSetResize() throws Exception {
  ImageView imageView = mWXImage.initComponentHostView(Robolectric.setupActivity(TestActivity.class));
  mWXImage.mHost = imageView;

  mWXImage.setResize("cover");
  ImageView.ScaleType scaleType = mWXImage.getHostView().getScaleType();
  assertEquals(scaleType, ImageView.ScaleType.CENTER_CROP);
}
项目:ucar-weex-core    文件:WXImageTest.java   
@Test
public void testSetResizeMode() throws Exception {

  ImageView imageView = mWXImage.initComponentHostView(Robolectric.setupActivity(TestActivity.class));
  mWXImage.mHost = imageView;

  mWXImage.setResizeMode("cover");
  ImageView.ScaleType scaleType = mWXImage.getHostView().getScaleType();
  assertEquals(scaleType, ImageView.ScaleType.CENTER_CROP);

}
项目: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);
}
项目:weex-uikit    文件:WXImageTest.java   
@Test
public void testSetImageBitmap(){
  ImageView imageView = mWXImage.initComponentHostView(Robolectric.setupActivity(TestActivity.class));
  imageView.setLayoutParams(new ViewGroup.LayoutParams(
      ViewGroup.LayoutParams.WRAP_CONTENT,
      ViewGroup.LayoutParams.WRAP_CONTENT));
  imageView.setImageBitmap(null);
  assertNull(imageView.getDrawable());

  imageView.setImageBitmap(Bitmap.createBitmap(100, 100, Bitmap.Config.RGB_565));
  assertNotNull(imageView.getDrawable());
}
项目:Stage    文件:ActivityProxy.java   
public ActivityProxy restoreFromSavedState() {
  if (!isCreated) {
    throw new IllegalStateException("The activity isn't created");
  }

  savedInstanceState = new Bundle();
  controller.saveInstanceState(savedInstanceState);

  if (isResumed) {
    pause();
  }
  if (isStarted) {
    stop();
  }
  destroy();

  controller = Robolectric.buildActivity(TestActivity.class);

  create();

  return this;
}
项目:Nird2    文件:SetupActivityTest.java   
@Before
public void setUp() {
    MockitoAnnotations.initMocks(this);
    setupActivity = Robolectric.setupActivity(TestSetupActivity.class);
    nicknameEntryWrapper = (TextInputLayout) setupActivity
            .findViewById(R.id.nickname_entry_wrapper);
    passwordConfirmationWrapper = (TextInputLayout) setupActivity
            .findViewById(R.id.password_confirm_wrapper);
    nicknameEntry =
            (EditText) setupActivity.findViewById(R.id.nickname_entry);
    passwordEntry =
            (EditText) setupActivity.findViewById(R.id.password_entry);
    passwordConfirmation =
            (EditText) setupActivity.findViewById(R.id.password_confirm);
    strengthMeter =
            (StrengthMeter) setupActivity.findViewById(R.id.strength_meter);
    createAccountButton =
            (Button) setupActivity.findViewById(R.id.create_account);
}
项目:Nird2    文件:ChangePasswordActivityTest.java   
@Before
public void setUp() {
    MockitoAnnotations.initMocks(this);
    changePasswordActivity =
            Robolectric.setupActivity(TestChangePasswordActivity.class);
    passwordConfirmationWrapper = (TextInputLayout) changePasswordActivity
            .findViewById(R.id.new_password_confirm_wrapper);
    currentPassword = (EditText) changePasswordActivity
            .findViewById(R.id.current_password_entry);
    newPassword = (EditText) changePasswordActivity
            .findViewById(R.id.new_password_entry);
    newPasswordConfirmation = (EditText) changePasswordActivity
            .findViewById(R.id.new_password_confirm);
    strengthMeter = (StrengthMeter) changePasswordActivity
            .findViewById(R.id.strength_meter);
    changePasswordButton = (Button) changePasswordActivity
            .findViewById(R.id.change_password);
}
项目:rental-calc    文件:PropertyProjectionsActivityTest.java   
@Test
public void startWithoutProperty()
{
    Intent intent = new Intent();
    final Bundle bundle = new Bundle();
    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());

    String latestToast = ShadowToast.getTextOfLatestToast();
    assertNotNull(latestToast);
}
项目:Nird2    文件:ChangePasswordActivityTest.java   
@Before
public void setUp() {
    MockitoAnnotations.initMocks(this);
    changePasswordActivity =
            Robolectric.setupActivity(TestChangePasswordActivity.class);
    passwordConfirmationWrapper = (TextInputLayout) changePasswordActivity
            .findViewById(R.id.new_password_confirm_wrapper);
    currentPassword = (EditText) changePasswordActivity
            .findViewById(R.id.current_password_entry);
    newPassword = (EditText) changePasswordActivity
            .findViewById(R.id.new_password_entry);
    newPasswordConfirmation = (EditText) changePasswordActivity
            .findViewById(R.id.new_password_confirm);
    strengthMeter = (StrengthMeter) changePasswordActivity
            .findViewById(R.id.strength_meter);
    changePasswordButton = (Button) changePasswordActivity
            .findViewById(R.id.change_password);
}
项目: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);
}
项目: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);
}
项目:MobileAppForPatient    文件:DeviceActivityTest.java   
@Before
public void setUp() {

    context = RuntimeEnvironment.application.getBaseContext();
    CognitoHelper.setUser("sneha03");
    cognitoUserSession  = Mockito.mock(CognitoUserSession.class);
    Mockito.when(cognitoUserSession.getRefreshToken()).thenReturn(new CognitoRefreshToken("refresh_token"));
    Mockito.when(cognitoUserSession.getAccessToken()).thenReturn(new CognitoAccessToken("access_token"));
    Mockito.when(cognitoUserSession.getIdToken()).thenReturn(new CognitoIdToken("id_token"));
    CognitoHelper.setCurrSession(cognitoUserSession);
    activity = Robolectric.buildActivity(DeviceListActivity2.class)
            .create()
            .resume()
            .visible()
            .get();
}
项目: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());
}
项目:RNLearn_Project1    文件:DialogModuleTest.java   
@Before
public void setUp() throws Exception {
  mActivityController = Robolectric.buildActivity(Activity.class);
  mActivity = mActivityController
      .create()
      .start()
      .resume()
      .get();

  final ReactApplicationContext context = PowerMockito.mock(ReactApplicationContext.class);
  PowerMockito.when(context.hasActiveCatalystInstance()).thenReturn(true);
  PowerMockito.when(context, "getCurrentActivity").thenReturn(mActivity);

  mDialogModule = new DialogModule(context);
  mDialogModule.onHostResume();
}
项目: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);
}
项目:prebid-mobile-android    文件:BidManagerTest.java   
@Test
public void testNoBidForUnregisteredAd() throws Exception {
    // Cache a bid
    ArrayList<BidResponse> bids = new ArrayList<>();
    BidResponse testBid = new BidResponse(TestConstants.cpm3, ServerResponses.ut_url);
    testBid.addCustomKeyword("pb_cache_id", "14y3834yq5iu5");
    testBid.addCustomKeyword("hb_pb", "0.54");
    testBid.addCustomKeyword("hb_bidder", "mock_bidder");
    bids.add(testBid);
    MockServer.addTestSetup(TestConstants.configID1, bids);
    ArrayList<AdUnit> adUnits = new ArrayList<AdUnit>();
    adUnits.add(adUnit1);
    Prebid.init(activity.getApplicationContext(), adUnits, TestConstants.accountId);
    Robolectric.flushBackgroundThreadScheduler();
    Robolectric.flushForegroundThreadScheduler();
    ArrayList<BidResponse> bidForAdUnit = BidManager.getWinningBids(adUnit1.getCode());
    assertNotNull(bidForAdUnit);
    BannerAdUnit randomAdUnit = new BannerAdUnit("Random", TestConstants.configID1);
    bidForAdUnit = BidManager.getWinningBids(randomAdUnit.getCode());
    assertNull(bidForAdUnit);
}
项目:ActivityDiary    文件:GraphicsHelperUnitTest.java   
@Before
public void setUp() throws Exception
{
    activity = Robolectric.buildActivity( MainActivity.class )
            .create()
            .resume()
            .get();
}
项目:Phial    文件:ExpandedViewTest.java   
@Before
public void setUp() throws Exception {
    activityController = Robolectric.buildActivity(Activity.class);
    activityController.create();
    view = new ExpandedView(activityController.get());
    activityController.get().setContentView(view);
}
项目:Lyra    文件:AutomaticSaveStateManagerTest.java   
@Test
public void testActivityAutomaticRestoreState() {
    Bundle stateBundle = new Bundle();
    TestModels.SaveStateActivity activity = Robolectric.buildActivity(TestModels.SaveStateActivity.class)
            .create(stateBundle)
            .get();

    verify(mListener, only()).onRestoreState(activity, stateBundle);
}
项目:q-mail    文件:AccountsTest.java   
@Test
public void withNoAccounts_showWelcomeMessage() throws Exception {
    controller = Robolectric.buildActivity( Accounts.class ).create();

    Accounts activity = controller.get();
    Intent expectedIntent = new Intent(activity, WelcomeMessage.class);
    Intent actual = shadowApplication.getNextStartedActivity();
    assertEquals(expectedIntent.getComponent(), actual.getComponent());
}
项目:weex-uikit    文件:WXGestureTest.java   
@Before
public void setUp() throws Exception {
  component = WXDivTest.create();
  ComponentTest.create(component);

  component.addEvent(WXGestureType.LowLevelGesture.ACTION_CANCEL.toString());
  component.addEvent(WXGestureType.LowLevelGesture.ACTION_DOWN.toString());
  component.addEvent(WXGestureType.LowLevelGesture.ACTION_MOVE.toString());
  component.addEvent(WXGestureType.LowLevelGesture.ACTION_UP.toString());

  TestActivity activity = Robolectric.setupActivity(TestActivity.class);
  mGesture = new WXGesture(component, activity);

}
项目:q-mail    文件:AccountsTest.java   
@Test
public void with1Account_showsMessageList() throws Exception {
    preferences.newAccount();
    QMail.setDatabasesUpToDate(true);

    controller = Robolectric.buildActivity( Accounts.class ).create();

    Accounts activity = controller.get();
    Intent expectedIntent = new Intent(activity, MessageList.class);
    Intent actual = shadowApplication.getNextStartedActivity();
    assertEquals(expectedIntent.getComponent(), actual.getComponent());
}
项目:q-mail    文件:AccountsTest.java   
@Test
public void with2Accounts_startsNoActivity() throws Exception {
    preferences.newAccount();
    preferences.newAccount();

    QMail.setDatabasesUpToDate(true);

    controller = Robolectric.buildActivity( Accounts.class ).create();

    Intent nextStartedActivity = shadowApplication.getNextStartedActivity();
    assertNull(nextStartedActivity);
}
项目:Leanplum-Android-SDK    文件:ActivityTest.java   
@Test
public void testLeanplumListActivity() throws Exception {
  LeanplumListActivity activity = Robolectric.buildActivity(LeanplumListActivity.class).
      create().start().resume().pause().stop().visible().get();
  setActivityVisibility(activity);

  Resources resources = activity.getResources();
  assertNotNull(resources);

  resetViews(activity);
}
项目:MobileAppForPatient    文件:ForgotPasswordActivityTest.java   
@Before
public void setUp() throws Exception {
    activity = Robolectric.buildActivity(ForgotPasswordActivity.class)
            .create()
            .resume()
            .visible()
            .get();
    initUI();
    CognitoHelper.init(activity);
}
项目:GitHub    文件:RequestManagerRetrieverTest.java   
@Test
public void testCanGetRequestManagerFromFragment() {
  Activity activity = Robolectric.buildActivity(Activity.class).create().start().resume().get();
  android.app.Fragment fragment = new android.app.Fragment();
  activity.getFragmentManager().beginTransaction().add(fragment, PARENT_TAG).commit();
  activity.getFragmentManager().executePendingTransactions();

  RequestManager manager = retriever.get(fragment);
  assertEquals(manager, retriever.get(fragment));
}
项目:GitHub    文件:RequestManagerRetrieverTest.java   
@Test
public void testSupportCanGetRequestManagerFromFragment() {
  FragmentActivity activity =
      Robolectric.buildActivity(FragmentActivity.class).create().start().resume().get();
  Fragment fragment = new Fragment();
  activity.getSupportFragmentManager().beginTransaction().add(fragment, PARENT_TAG).commit();
  activity.getSupportFragmentManager().executePendingTransactions();

  RequestManager manager = retriever.get(fragment);
  assertEquals(manager, retriever.get(fragment));
}
项目:GitHub    文件:RequestManagerRetrieverTest.java   
private void helpTestCanGetRequestManagerFromDetachedFragment() {
  Activity activity = Robolectric.buildActivity(Activity.class).create().start().resume().get();
  android.app.Fragment fragment = new android.app.Fragment();
  activity.getFragmentManager().beginTransaction().add(fragment, PARENT_TAG).detach(fragment)
      .commit();
  activity.getFragmentManager().executePendingTransactions();

  assertTrue(fragment.isDetached());
  retriever.get(fragment);
}
项目:GitHub    文件:RequestManagerRetrieverTest.java   
@Test
@TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR1)
public void testDoesNotThrowIfAskedToGetManagerForFragmentPreJellyBeanMr1() {
  Util.setSdkVersionInt(Build.VERSION_CODES.JELLY_BEAN);
  Activity activity = Robolectric.buildActivity(Activity.class).create().start().resume().get();
  android.app.Fragment fragment = new android.app.Fragment();

  activity.getFragmentManager().beginTransaction().add(fragment, "test").commit();
  android.app.Fragment spyFragment = Mockito.spy(fragment);
  when(spyFragment.getChildFragmentManager()).thenThrow(new NoSuchMethodError());

  assertNotNull(retriever.get(spyFragment));
}
项目:GitHub    文件:RequestManagerFragmentTest.java   
public RequestManagerHarness() {
  fragment = new RequestManagerFragment(lifecycle);
  controller = Robolectric.buildActivity(Activity.class).create();
  controller.get()
      .getFragmentManager()
      .beginTransaction()
      .add(fragment, TAG)
      .commit();
  controller.get()
      .getFragmentManager()
      .executePendingTransactions();
}