Java Code Examples for org.robolectric.shadows.ShadowApplication#getInstance()

The following examples show how to use org.robolectric.shadows.ShadowApplication#getInstance() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: BluetoothCentralTest.java    From blessed-android with MIT License 6 votes vote down vote up
@Before
public void setUp() throws Exception {
    initMocks(this);

    application = ShadowApplication.getInstance();

    bluetoothAdapter = Shadow.extract(ShadowBluetoothLEAdapter.getDefaultAdapter());
    bluetoothAdapter.setEnabled(true);
    bluetoothAdapter.setBluetoothLeScanner(scanner);

    context = application.getApplicationContext();

    // Setup hardware features
    PackageManager packageManager = context.getPackageManager();
    ShadowPackageManager shadowPackageManager = shadowOf(packageManager);
    shadowPackageManager.setSystemFeature(PackageManager.FEATURE_BLUETOOTH_LE, true);

    central = new BluetoothCentral(context, callback, handler);
}
 
Example 2
Source File: LaunchAnalyzerReceiverTest.java    From analyzer-of-android-for-Apache-Weex with Apache License 2.0 6 votes vote down vote up
@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());
}
 
Example 3
Source File: MainActivityTest.java    From ello-android with MIT License 5 votes vote down vote up
@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));
}
 
Example 4
Source File: MainActivityTest.java    From ello-android with MIT License 5 votes vote down vote up
@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));
}
 
Example 5
Source File: MyReceiverTest.java    From Awesome-WanAndroid with Apache License 2.0 4 votes vote down vote up
@Test
public void registerReceiver() {
    ShadowApplication application = ShadowApplication.getInstance();
    Assert.assertNotNull(application.hasReceiverForIntent(intent));
}