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


Java ShadowApplication.getInstance方法代碼示例

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


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

示例1: 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

示例2: 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

示例3: removeStickyBroadcast

import org.robolectric.shadows.ShadowApplication; //導入方法依賴的package包/類
@Implementation
public void removeStickyBroadcast(Intent intent) {
    try {
        ShadowApplication application = ShadowApplication.getInstance();
        Field field = org.robolectric.shadows.ShadowApplication.class.getDeclaredField("stickyIntents");
        field.setAccessible(true);
        @SuppressWarnings("unchecked")
        Map<String, Intent> stickyIntents = (Map<String, Intent>) field.get(application);
        stickyIntents.remove(intent.getAction());
    } catch (Exception e) {
        e.printStackTrace();
    }
}
 
開發者ID:Doist,項目名稱:JobSchedulerCompat,代碼行數:14,代碼來源:ShadowContextImpl.java

示例4: registersReceiverForDeviceRegistered

import org.robolectric.shadows.ShadowApplication; //導入方法依賴的package包/類
@Test
public void registersReceiverForDeviceRegistered() throws Exception {
    List<ShadowApplication.Wrapper> registeredReceivers = ShadowApplication.getInstance().getRegisteredReceivers();

    Assert.assertEquals(false, registeredReceivers.isEmpty());
    Intent intent = new Intent(ElloPreferences.REGISTRATION_COMPLETE);
    ShadowApplication shadowApplication = ShadowApplication.getInstance();
    assertTrue("is registered for REGISTRATION_COMPLETE", shadowApplication.hasReceiverForIntent(intent));
}
 
開發者ID:ello,項目名稱:ello-android,代碼行數:10,代碼來源:MainActivityTest.java

示例5: registersReceiverForPushNotifications

import org.robolectric.shadows.ShadowApplication; //導入方法依賴的package包/類
@Test
public void registersReceiverForPushNotifications() throws Exception {
    List<ShadowApplication.Wrapper> registeredReceivers = ShadowApplication.getInstance().getRegisteredReceivers();

    Assert.assertEquals(false, registeredReceivers.isEmpty());

    Intent intent = new Intent(ElloPreferences.PUSH_RECEIVED);
    ShadowApplication shadowApplication = ShadowApplication.getInstance();
    assertTrue("is registered for PUSH_RECEIVED", shadowApplication.hasReceiverForIntent(intent));
}
 
開發者ID:ello,項目名稱:ello-android,代碼行數:11,代碼來源:MainActivityTest.java

示例6: clickingPositiveButton_should_startProcessOfEnablingLocServices

import org.robolectric.shadows.ShadowApplication; //導入方法依賴的package包/類
@Test
public void clickingPositiveButton_should_startProcessOfEnablingLocServices(){
    ShadowApplication app = ShadowApplication.getInstance();
    mAlert.getButton(BUTTON_POSITIVE).performClick();

    ShadowIntent si = shadowOf(app.getNextStartedActivity());
    assertThat(si.getAction()).isEqualTo(Settings.ACTION_LOCATION_SOURCE_SETTINGS);
}
 
開發者ID:whereat,項目名稱:whereat-android,代碼行數:9,代碼來源:LocServicesAlertFragmentTest.java

示例7: setUp

import org.robolectric.shadows.ShadowApplication; //導入方法依賴的package包/類
@Before
public void setUp() throws Exception {
    application = ShadowApplication.getInstance();
    BinaryTempFileBody.setTempDirectory(RuntimeEnvironment.application.getCacheDir());
}
 
開發者ID:philipwhiuk,項目名稱:q-mail,代碼行數:6,代碼來源:AutocryptHeaderParserTest.java

示例8: getShadowApplication

import org.robolectric.shadows.ShadowApplication; //導入方法依賴的package包/類
private ShadowApplication getShadowApplication() {
    return ShadowApplication.getInstance();
}
 
開發者ID:ParaskP7,項目名稱:sample-code-posts,代碼行數:4,代碼來源:RobolectricGeneralTestHelper.java

示例9: getShadowApplication

import org.robolectric.shadows.ShadowApplication; //導入方法依賴的package包/類
public ShadowApplication getShadowApplication() {
    return ShadowApplication.getInstance();
}
 
開發者ID:nightscout,項目名稱:lasso,代碼行數:4,代碼來源:AlarmTest.java


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