當前位置: 首頁>>代碼示例>>Java>>正文


Java Robolectric類代碼示例

本文整理匯總了Java中org.robolectric.Robolectric的典型用法代碼示例。如果您正苦於以下問題:Java Robolectric類的具體用法?Java Robolectric怎麽用?Java Robolectric使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


Robolectric類屬於org.robolectric包,在下文中一共展示了Robolectric類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: testWindowsFocusChanged

import org.robolectric.Robolectric; //導入依賴的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);
}
 
開發者ID:lizhangqu,項目名稱:chromium-net-for-android,代碼行數:19,代碼來源:BaseChromiumApplicationTest.java

示例2: startWithMissingProperty

import org.robolectric.Robolectric; //導入依賴的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(PropertyPicturesActivity.class, intent).create();
    Activity activity = (Activity)controller.get();

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

    String latestToast = ShadowToast.getTextOfLatestToast();
    assertNotNull(latestToast);
}
 
開發者ID:brarcher,項目名稱:rental-calc,代碼行數:18,代碼來源:PropertyPicturesActivityTest.java

示例3: startWithoutProperty

import org.robolectric.Robolectric; //導入依賴的package包/類
@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);
}
 
開發者ID:brarcher,項目名稱:rental-calc,代碼行數:17,代碼來源:PropertyPicturesActivityTest.java

示例4: testBindActivity

import org.robolectric.Robolectric; //導入依賴的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);
}
 
開發者ID:ezhome,項目名稱:Android-RxPresenter,代碼行數:19,代碼來源:RxPresenterTest.java

示例5: setUp

import org.robolectric.Robolectric; //導入依賴的package包/類
@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);
}
 
開發者ID:savvisingh,項目名稱:DateRangePickerLibrary,代碼行數:20,代碼來源:CalendarPickerViewTest.java

示例6: setUp

import org.robolectric.Robolectric; //導入依賴的package包/類
@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);
}
 
開發者ID:philipwhiuk,項目名稱:q-mail,代碼行數:22,代碼來源:RecipientPresenterTest.java

示例7: setUp

import org.robolectric.Robolectric; //導入依賴的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);
}
 
開發者ID:micromasterandroid,項目名稱:androidadvanced,代碼行數:19,代碼來源:RecipeMainActivityTest.java

示例8: startWithProperty

import org.robolectric.Robolectric; //導入依賴的package包/類
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;
}
 
開發者ID:brarcher,項目名稱:rental-calc,代碼行數:23,代碼來源:PropertyProjectionsActivityTest.java

示例9: startWithoutProperty

import org.robolectric.Robolectric; //導入依賴的package包/類
@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);
}
 
開發者ID:brarcher,項目名稱:rental-calc,代碼行數:17,代碼來源:PropertyWorksheetActivityTest.java

示例10: startWithMissingProperty

import org.robolectric.Robolectric; //導入依賴的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(PropertyProjectionsActivity.class, intent).create();
    Activity activity = (Activity)controller.get();

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

    String latestToast = ShadowToast.getTextOfLatestToast();
    assertNotNull(latestToast);
}
 
開發者ID:brarcher,項目名稱:rental-calc,代碼行數:20,代碼來源:PropertyProjectionsActivityTest.java

示例11: testFirstRunStartsIntro

import org.robolectric.Robolectric; //導入依賴的package包/類
@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));
}
 
開發者ID:brarcher,項目名稱:rental-calc,代碼行數:22,代碼來源:PropertiesListActivityTest.java

示例12: testSetResize

import org.robolectric.Robolectric; //導入依賴的package包/類
@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);
}
 
開發者ID:weexext,項目名稱:ucar-weex-core,代碼行數:10,代碼來源:WXImageTest.java

示例13: testSetResizeMode

import org.robolectric.Robolectric; //導入依賴的package包/類
@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);

}
 
開發者ID:weexext,項目名稱:ucar-weex-core,代碼行數:12,代碼來源:WXImageTest.java

示例14: startWithoutProperty

import org.robolectric.Robolectric; //導入依賴的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);
}
 
開發者ID:brarcher,項目名稱:rental-calc,代碼行數:19,代碼來源:PropertyOverviewActivityTest.java

示例15: testSetImageBitmap

import org.robolectric.Robolectric; //導入依賴的package包/類
@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());
}
 
開發者ID:erguotou520,項目名稱:weex-uikit,代碼行數:13,代碼來源:WXImageTest.java


注:本文中的org.robolectric.Robolectric類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。