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


Java ShadowApplication類代碼示例

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


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

示例1: setUp

import org.robolectric.shadows.ShadowApplication; //導入依賴的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

示例2: testBootReceiverRegistered

import org.robolectric.shadows.ShadowApplication; //導入依賴的package包/類
@Test
public void testBootReceiverRegistered() {
    Intent intent = new Intent(Intent.ACTION_BOOT_COMPLETED);
    AndroidManifest manifest = ShadowApplication.getInstance().getAppManifest();
    List<BroadcastReceiver> receivers = ShadowApplication.getInstance().getReceiversForIntent(intent);
    assertThat(receivers, hasItem(isA(JobGcReceiver.class)));
}
 
開發者ID:Doist,項目名稱:JobSchedulerCompat,代碼行數:8,代碼來源:JobGcReceiverTest.java

示例3: testObserversFire

import org.robolectric.shadows.ShadowApplication; //導入依賴的package包/類
@Test
public void testObserversFire() {
    Uri[] uris = new Uri[]{Uri.parse("doist.com"), Uri.parse("todoist.com"), Uri.parse("twistapp.com")};

    for (int i = 0; i < uris.length; i++) {
        jobStore.add(JobStatus.createFromJobInfo(
                JobCreator.create(context, i, 5000)
                          .addTriggerContentUri(new JobInfo.TriggerContentUri(uris[i], 0))
                          .build(),
                AlarmScheduler.TAG));
    }
    service.startCommand(0, 0);

    ShadowApplication application = ShadowApplication.getInstance();
    ShadowContentResolver contentResolver = shadowOf(context.getContentResolver());
    for (Uri uri : uris) {
        assertEquals(0, application.getBoundServiceConnections().size());
        assertEquals(1, contentResolver.getContentObservers(uri).size());
        contentResolver.notifyChange(uri, null);
        DeviceTestUtils.advanceTime(JobStatus.DEFAULT_TRIGGER_MAX_DELAY);
        assertEquals(1, contentResolver.getContentObservers(uri).size());
        assertEquals(AlarmJobService.class.getCanonicalName(),
                     application.getNextStartedService().getComponent().getClassName());
    }
}
 
開發者ID:Doist,項目名稱:JobSchedulerCompat,代碼行數:26,代碼來源:AlarmContentObserverServiceTest.java

示例4: testReceiversStartService

import org.robolectric.shadows.ShadowApplication; //導入依賴的package包/類
@Test
public void testReceiversStartService() {
    new AlarmReceiver().onReceive(context, new Intent(Intent.ACTION_BOOT_COMPLETED));

    assertEquals(ShadowApplication.getInstance().getNextStartedService().getComponent().getClassName(),
                 AlarmJobService.class.getName());

    new AlarmReceiver.BatteryReceiver().onReceive(context, new Intent(Intent.ACTION_POWER_CONNECTED));

    assertEquals(ShadowApplication.getInstance().getNextStartedService().getComponent().getClassName(),
                 AlarmJobService.class.getName());

    new AlarmReceiver.StorageReceiver().onReceive(context, new Intent(Intent.ACTION_DEVICE_STORAGE_LOW));

    assertEquals(ShadowApplication.getInstance().getNextStartedService().getComponent().getClassName(),
                 AlarmJobService.class.getName());

    new AlarmReceiver.ConnectivityReceiver().onReceive(
            context, new Intent(ConnectivityManager.CONNECTIVITY_ACTION));

    assertEquals(ShadowApplication.getInstance().getNextStartedService().getComponent().getClassName(),
                 AlarmJobService.class.getName());
}
 
開發者ID:Doist,項目名稱:JobSchedulerCompat,代碼行數:24,代碼來源:AlarmReceiverTest.java

示例5: onReceive

import org.robolectric.shadows.ShadowApplication; //導入依賴的package包/類
@Test
public void onReceive() throws Exception {

    //one
    ShadowApplication application = ShadowApplication.getInstance();
    Intent intent = new Intent(ACTION);
    boolean result = application.hasReceiverForIntent(intent);
    assertTrue(result);

    //only one
    List<BroadcastReceiver> receivers = application.getReceiversForIntent(intent);
    assertEquals(1,receivers.size());

    //test onReceive
    intent.putExtra("c","off");
    BroadcastReceiver targetReceiver = receivers.get(0);
    targetReceiver.onReceive(application.getApplicationContext(),intent);

    Intent serviceIntent = application.getNextStoppedService();
    assertEquals(serviceIntent.getComponent().getClassName(),AnalyzerService.class.getCanonicalName());
}
 
開發者ID:weexteam,項目名稱:weex-analyzer-android,代碼行數:22,代碼來源:LaunchAnalyzerReceiverTest.java

示例6: testSendSignalDirectly

import org.robolectric.shadows.ShadowApplication; //導入依賴的package包/類
@Test
public void testSendSignalDirectly() {
    DeviceEventHandler handler = new DeviceEventHandler();
    DeviceEvent event = new DeviceEvent();
    event.setName("device1");
    event.setData("key1", "value1");
    event.setData("key2", 2);
    handler.sendSignal(event);

    List<Intent> intents = ShadowApplication.getInstance().getBroadcastIntents();
    Assert.assertEquals(1, intents.size());
    Intent intent = intents.get(0);
    Assert.assertEquals("com.mocircle.flow.actions.ACTION_SEND_DEVICE_EVENT", intent.getAction());
    Assert.assertEquals("device1", intent.getStringExtra("extra_event_name"));
    HashMap<String, Object> data = (HashMap) intent.getSerializableExtra("extra_event_data");
    Assert.assertEquals("value1", data.get("key1"));
    Assert.assertEquals(2, data.get("key2"));
}
 
開發者ID:mocircle,項目名稱:circleflow-android,代碼行數:19,代碼來源:DeviceEventHandlerTest.java

示例7: cancelClosesCursorIfLoading

import org.robolectric.shadows.ShadowApplication; //導入依賴的package包/類
@Test
public void cancelClosesCursorIfLoading() {
    CursorLoader loader = new CursorLoader.Builder(resolver, CONTENT_URI).build();
    Loader.Callbacks<Cursor> callbacks = mock(Loader.Callbacks.class);
    loader.setCallbacks(callbacks);

    background.pause();

    loader.start();
    loader.cancel();

    background.unPause();
    ShadowApplication.runBackgroundTasks();

    assertTrue(cursor.isClosed());
}
 
開發者ID:evant,項目名稱:loadie,代碼行數:17,代碼來源:CursorLoaderTest.java

示例8: testSetTextWithLinks

import org.robolectric.shadows.ShadowApplication; //導入依賴的package包/類
@Test
public void testSetTextWithLinks() {
    TestApplication.addResolver(new Intent(Intent.ACTION_VIEW, Uri.parse("http://example.com")));
    Preferences.set(RuntimeEnvironment.application, R.string.pref_custom_tab, false);
    TextView textView = new TextView(RuntimeEnvironment.application);
    AppUtils.setTextWithLinks(textView, AppUtils.fromHtml("<a href=\"http://example.com\">http://example.com</a>"));
    MotionEvent event = mock(MotionEvent.class);
    when(event.getAction()).thenReturn(MotionEvent.ACTION_DOWN);
    when(event.getX()).thenReturn(0f);
    when(event.getY()).thenReturn(0f);
    assertTrue(shadowOf(textView).getOnTouchListener().onTouch(textView, event));
    when(event.getAction()).thenReturn(MotionEvent.ACTION_UP);
    when(event.getX()).thenReturn(0f);
    when(event.getY()).thenReturn(0f);
    assertTrue(shadowOf(textView).getOnTouchListener().onTouch(textView, event));
    assertNotNull(ShadowApplication.getInstance().getNextStartedActivity());
}
 
開發者ID:hidroh,項目名稱:materialistic,代碼行數:18,代碼來源:AppUtilsTest.java

示例9: testSetTextWithLinksOpenChromeCustomTabs

import org.robolectric.shadows.ShadowApplication; //導入依賴的package包/類
@Test
public void testSetTextWithLinksOpenChromeCustomTabs() {
    TestApplication.addResolver(new Intent(Intent.ACTION_VIEW, Uri.parse("http://example.com")));
    TextView textView = new TextView(new ContextThemeWrapper(RuntimeEnvironment.application, R.style.AppTheme));
    AppUtils.setTextWithLinks(textView, AppUtils.fromHtml("<a href=\"http://example.com\">http://example.com</a>"));
    MotionEvent event = mock(MotionEvent.class);
    when(event.getAction()).thenReturn(MotionEvent.ACTION_DOWN);
    when(event.getX()).thenReturn(0f);
    when(event.getY()).thenReturn(0f);
    assertTrue(shadowOf(textView).getOnTouchListener().onTouch(textView, event));
    when(event.getAction()).thenReturn(MotionEvent.ACTION_UP);
    when(event.getX()).thenReturn(0f);
    when(event.getY()).thenReturn(0f);
    assertTrue(shadowOf(textView).getOnTouchListener().onTouch(textView, event));
    assertNotNull(ShadowApplication.getInstance().getNextStartedActivity());
}
 
開發者ID:hidroh,項目名稱:materialistic,代碼行數:17,代碼來源:AppUtilsTest.java

示例10: init

import org.robolectric.shadows.ShadowApplication; //導入依賴的package包/類
@Before
public void init() {
  context = Robolectric.setupActivity(Activity.class);
  shadowContext = Shadows.shadowOf(context);

  testingQueues = new TestingQueues();
  serviceInstance = spy(new Goro.GoroImpl(testingQueues));

  serviceCompName = new ComponentName(context, GoroService.class);
  GoroService service = new GoroService();
  binder = new GoroService.GoroBinderImpl(serviceInstance, service.new GoroTasksListener());
  ShadowApplication.getInstance()
      .setComponentNameAndServiceForBindService(
          serviceCompName,
          binder
      );
  reset(serviceInstance);
}
 
開發者ID:stanfy,項目名稱:goro,代碼行數:19,代碼來源:BaseBindingGoroTest.java

示例11: whenANotificationIsSentThenTheTheNotificationIncludesTheStoreName

import org.robolectric.shadows.ShadowApplication; //導入依賴的package包/類
@Test
public void whenANotificationIsSentThenTheTheNotificationIncludesTheStoreName() {
    ShadowApplication shadowApplication = (ShadowApplication) Shadows.shadowOf(RuntimeEnvironment.application);

    insertStoreLocation(shadowApplication);

    ShadowLocation.setDistanceBetween(new float[]{(float) GroceryReminderConstants.LOCATION_GEOFENCE_RADIUS_METERS});

    long currentTime = System.currentTimeMillis();
    groceryStoreNotificationManager.sendPotentialNotification(new Location(LocationManager.GPS_PROVIDER), currentTime);

    ShadowNotificationManager shadowNotificationManager = getShadowNotificationManager();
    Notification notification = shadowNotificationManager.getNotification(GroceryReminderConstants.NOTIFICATION_PROXIMITY_ALERT);
    ShadowNotification shadowNotification = (ShadowNotification)Shadows.shadowOf(notification);
    assertTrue(((String) shadowNotification.getContentTitle()).contains(ARBITRARY_STORE_NAME));
}
 
開發者ID:jameskbride,項目名稱:grocery-reminder,代碼行數:17,代碼來源:GroceryStoreNotificationManagerTest.java

示例12: insertStoreLocation

import org.robolectric.shadows.ShadowApplication; //導入依賴的package包/類
@Test
 public void givenAStoreNotificationHasBeenStoredWhenARequestToSendANotificationWithTheTheSameStoreIsReceivedBeforeTheMinimumUpdateTimeForTheSameStoreThenTheNotificationIsNotSent() {
    ShadowApplication shadowApplication = (ShadowApplication) Shadows.shadowOf(RuntimeEnvironment.application);

    insertStoreLocation(shadowApplication);
    SharedPreferences sharedPreferences = shadowApplication.getSharedPreferences(shadowApplication.getString(R.string.reminder_pref_key), Context.MODE_PRIVATE);
    sharedPreferences.edit().putString(GroceryReminderConstants.LAST_NOTIFIED_STORE_KEY, ARBITRARY_STORE_NAME)
            .putLong(GroceryReminderConstants.LAST_NOTIFICATION_TIME_FOR_SAME_STORE, System.currentTimeMillis() - 1)
            .commit();

    ShadowLocation.setDistanceBetween(new float[]{(float) GroceryReminderConstants.LOCATION_GEOFENCE_RADIUS_METERS});

    ShadowNotificationManager shadowNotificationManager = getShadowNotificationManager();

    groceryStoreNotificationManager.sendPotentialNotification(new Location(LocationManager.GPS_PROVIDER), System.currentTimeMillis());

    Notification notification = shadowNotificationManager.getNotification(GroceryReminderConstants.NOTIFICATION_PROXIMITY_ALERT);
    assertNull(notification);
}
 
開發者ID:jameskbride,項目名稱:grocery-reminder,代碼行數:20,代碼來源:GroceryStoreNotificationManagerTest.java

示例13: cancelClosesCursorIfLoading

import org.robolectric.shadows.ShadowApplication; //導入依賴的package包/類
@Test
public void cancelClosesCursorIfLoading() {
    CursorLoader loader = new CursorLoader.Builder(resolver, CONTENT_URI).build();
    Loader.Callbacks<Cursor> callbacks = mock(Loader.Callbacks.class);
    loader.setCallbacks(callbacks);
    
    background.pause();
    
    loader.start();
    loader.cancel();

    background.unPause();
    ShadowApplication.runBackgroundTasks();

    assertTrue(cursor.isClosed());
}
 
開發者ID:evant,項目名稱:retain-state,代碼行數:17,代碼來源:CursorLoaderTest.java

示例14: shouldStartVIAHistoryWhenBtnClickedWithTypeHistory

import org.robolectric.shadows.ShadowApplication; //導入依賴的package包/類
@Test
public void shouldStartVIAHistoryWhenBtnClickedWithTypeHistory() throws Exception {
    View view = mock(View.class);

    intent.putExtra(Constants.PARAM_PROGRAM_CODE, Constants.VIA_PROGRAM_CODE);
    rnRFormListActivity = Robolectric.buildActivity(RnRFormListActivity.class).withIntent(intent).create().get();

    RnRFormViewModel viewModel = generateRnRFormViewModel("ESS_MEDS", RnRFormViewModel.TYPE_SYNCED_HISTORICAL);
    viewModel.setId(999L);
    rnRFormListActivity.rnRFormItemClickListener.clickBtnView(viewModel, view);

    Intent nextStartedIntent = ShadowApplication.getInstance().getNextStartedActivity();

    assertNotNull(nextStartedIntent);
    assertEquals(nextStartedIntent.getComponent().getClassName(), VIARequisitionActivity.class.getName());
    assertEquals(nextStartedIntent.getLongExtra(Constants.PARAM_FORM_ID, 0), 999L);
}
 
開發者ID:SIGLUS,項目名稱:lmis-moz-mobile,代碼行數:18,代碼來源:RnRFormListActivityTest.java

示例15: shouldNotLoadSameFormIdAfterLoadedViaHistoryForm

import org.robolectric.shadows.ShadowApplication; //導入依賴的package包/類
@Test
public void shouldNotLoadSameFormIdAfterLoadedViaHistoryForm() throws Exception {
    View view = mock(View.class);

    RnRFormViewModel historyViewModel = generateRnRFormViewModel("MMIA", RnRFormViewModel.TYPE_SYNCED_HISTORICAL);
    historyViewModel.setId(1L);
    rnRFormListActivity.rnRFormItemClickListener.clickBtnView(historyViewModel, view);

    Intent startedIntentWhenIsHistory = ShadowApplication.getInstance().getNextStartedActivity();

    assertNotNull(startedIntentWhenIsHistory);
    assertEquals(startedIntentWhenIsHistory.getComponent().getClassName(), MMIARequisitionActivity.class.getName());
    assertEquals(1L, startedIntentWhenIsHistory.getLongExtra(Constants.PARAM_FORM_ID, 0));

    RnRFormViewModel defaultViewModel = generateRnRFormViewModel("MMIA", RnRFormViewModel.TYPE_CREATED_BUT_UNCOMPLETED);
    rnRFormListActivity.rnRFormItemClickListener.clickBtnView(defaultViewModel, view);

    Intent startedIntentWhenIsDefault = ShadowApplication.getInstance().getNextStartedActivity();

    assertNotNull(startedIntentWhenIsDefault);
    assertEquals(startedIntentWhenIsDefault.getComponent().getClassName(), MMIARequisitionActivity.class.getName());
    assertEquals(0L, startedIntentWhenIsDefault.getLongExtra(Constants.PARAM_FORM_ID, 0));
}
 
開發者ID:SIGLUS,項目名稱:lmis-moz-mobile,代碼行數:24,代碼來源:RnRFormListActivityTest.java


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