本文整理匯總了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());
}
}
示例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());
}
示例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();
}
}
示例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));
}
示例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));
}
示例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);
}
示例7: setUp
import org.robolectric.shadows.ShadowApplication; //導入方法依賴的package包/類
@Before
public void setUp() throws Exception {
application = ShadowApplication.getInstance();
BinaryTempFileBody.setTempDirectory(RuntimeEnvironment.application.getCacheDir());
}
示例8: getShadowApplication
import org.robolectric.shadows.ShadowApplication; //導入方法依賴的package包/類
private ShadowApplication getShadowApplication() {
return ShadowApplication.getInstance();
}
示例9: getShadowApplication
import org.robolectric.shadows.ShadowApplication; //導入方法依賴的package包/類
public ShadowApplication getShadowApplication() {
return ShadowApplication.getInstance();
}