48
48
import org .junit .runner .RunWith ;
49
49
import org .robolectric .Robolectric ;
50
50
import org .robolectric .RobolectricTestRunner ;
51
+ import org .robolectric .RuntimeEnvironment ;
51
52
import org .robolectric .android .controller .ActivityController ;
52
53
import org .robolectric .annotation .Config ;
53
- import org .robolectric .shadows . ShadowApplication ;
54
+ import org .robolectric .annotation . LooperMode ;
54
55
import org .robolectric .shadows .ShadowLog ;
55
56
56
57
import java .lang .reflect .Method ;
@@ -146,7 +147,7 @@ public static void afterEverything() throws Exception {
146
147
@ Test
147
148
@ Config (shadows = {ShadowGoogleApiClientBuilder .class , ShadowGoogleApiClientCompatProxy .class , ShadowFusedLocationApiWrapper .class })
148
149
public void shouldUpdateAllLocationFieldsWhenTimeStampChanges () throws Exception {
149
- ShadowApplication . getInstance ( ).grantPermissions ("android.permission.ACCESS_COARSE_LOCATION" );
150
+ shadowOf ( RuntimeEnvironment . application ).grantPermissions ("android.permission.ACCESS_COARSE_LOCATION" );
150
151
OneSignalInit ();
151
152
threadAndTaskWait ();
152
153
assertEquals (1.0 , ShadowOneSignalRestClient .lastPost .getDouble ("lat" ));
@@ -195,7 +196,7 @@ public void testLocationTimeout() throws Exception {
195
196
ShadowFusedLocationApiWrapper .class },
196
197
sdk = 19 )
197
198
public void testLocationSchedule () throws Exception {
198
- ShadowApplication . getInstance ( ).grantPermissions ("android.permission.ACCESS_FINE_LOCATION" );
199
+ shadowOf ( RuntimeEnvironment . application ).grantPermissions ("android.permission.ACCESS_FINE_LOCATION" );
199
200
ShadowFusedLocationApiWrapper .lat = 1.0d ;
200
201
ShadowFusedLocationApiWrapper .log = 2.0d ;
201
202
ShadowFusedLocationApiWrapper .accuracy = 3.0f ;
@@ -256,7 +257,7 @@ public void testLocationSchedule() throws Exception {
256
257
ShadowFusedLocationApiWrapper .class },
257
258
sdk = 19 )
258
259
public void testLocationFromSyncAlarm () throws Exception {
259
- ShadowApplication . getInstance ( ).grantPermissions ("android.permission.ACCESS_COARSE_LOCATION" );
260
+ shadowOf ( RuntimeEnvironment . application ).grantPermissions ("android.permission.ACCESS_COARSE_LOCATION" );
260
261
261
262
ShadowFusedLocationApiWrapper .lat = 1.1d ;
262
263
ShadowFusedLocationApiWrapper .log = 2.1d ;
@@ -301,7 +302,7 @@ public void testLocationFromSyncAlarm() throws Exception {
301
302
@ Test
302
303
@ Config (shadows = {ShadowGoogleApiClientBuilder .class , ShadowGoogleApiClientCompatProxy .class , ShadowFusedLocationApiWrapper .class })
303
304
public void shouldSendLocationToEmailRecord () throws Exception {
304
- ShadowApplication . getInstance ( ).grantPermissions ("android.permission.ACCESS_COARSE_LOCATION" );
305
+ shadowOf ( RuntimeEnvironment . application ).grantPermissions ("android.permission.ACCESS_COARSE_LOCATION" );
305
306
306
307
OneSignalInit ();
307
308
OneSignal .setEmail ("josh@onesignal.com" );
@@ -318,7 +319,7 @@ public void shouldSendLocationToEmailRecord() throws Exception {
318
319
@ Test
319
320
@ Config (shadows = {ShadowGoogleApiClientBuilder .class , ShadowGoogleApiClientCompatProxy .class , ShadowFusedLocationApiWrapper .class })
320
321
public void shouldSendLocationToSMSRecord () throws Exception {
321
- ShadowApplication . getInstance ( ).grantPermissions ("android.permission.ACCESS_COARSE_LOCATION" );
322
+ shadowOf ( RuntimeEnvironment . application ).grantPermissions ("android.permission.ACCESS_COARSE_LOCATION" );
322
323
323
324
OneSignalInit ();
324
325
OneSignal .setSMSNumber ("123456789" );
@@ -335,7 +336,7 @@ public void shouldSendLocationToSMSRecord() throws Exception {
335
336
@ Test
336
337
@ Config (shadows = {ShadowGoogleApiClientBuilder .class , ShadowGoogleApiClientCompatProxy .class , ShadowFusedLocationApiWrapper .class })
337
338
public void shouldRegisterWhenPromptingAfterInit () throws Exception {
338
- ShadowApplication . getInstance ( ).grantPermissions ("android.permission.ACCESS_COARSE_LOCATION" );
339
+ shadowOf ( RuntimeEnvironment . application ).grantPermissions ("android.permission.ACCESS_COARSE_LOCATION" );
339
340
ShadowGoogleApiClientCompatProxy .skipOnConnected = true ;
340
341
341
342
// Test promptLocation right after init race condition
@@ -354,7 +355,7 @@ public void shouldRegisterWhenPromptingAfterInit() throws Exception {
354
355
@ Test
355
356
@ Config (shadows = {ShadowGoogleApiClientBuilder .class , ShadowGoogleApiClientCompatProxy .class , ShadowFusedLocationApiWrapper .class })
356
357
public void shouldCallOnSessionEvenIfSyncJobStarted () throws Exception {
357
- ShadowApplication . getInstance ( ).grantPermissions ("android.permission.ACCESS_COARSE_LOCATION" );
358
+ shadowOf ( RuntimeEnvironment . application ).grantPermissions ("android.permission.ACCESS_COARSE_LOCATION" );
358
359
359
360
OneSignalInit ();
360
361
threadAndTaskWait ();
@@ -381,7 +382,7 @@ public void shouldCallOnSessionEvenIfSyncJobStarted() throws Exception {
381
382
@ Config (shadows = {ShadowHMSFusedLocationProviderClient .class })
382
383
public void shouldUpdateAllLocationFieldsWhenTimeStampChanges_Huawei () throws Exception {
383
384
ShadowOSUtils .supportsHMS (true );
384
- ShadowApplication . getInstance ( ).grantPermissions ("android.permission.ACCESS_COARSE_LOCATION" );
385
+ shadowOf ( RuntimeEnvironment . application ).grantPermissions ("android.permission.ACCESS_COARSE_LOCATION" );
385
386
OneSignalInit ();
386
387
threadAndTaskWait ();
387
388
assertEquals (1.0 , ShadowOneSignalRestClient .lastPost .getDouble ("lat" ));
@@ -411,7 +412,7 @@ public void shouldUpdateAllLocationFieldsWhenTimeStampChanges_Huawei() throws Ex
411
412
}, sdk = 19 )
412
413
public void testLocationSchedule_Huawei () throws Exception {
413
414
ShadowOSUtils .supportsHMS (true );
414
- ShadowApplication . getInstance ( ).grantPermissions ("android.permission.ACCESS_FINE_LOCATION" );
415
+ shadowOf ( RuntimeEnvironment . application ).grantPermissions ("android.permission.ACCESS_FINE_LOCATION" );
415
416
ShadowHMSFusedLocationProviderClient .lat = 1.0d ;
416
417
ShadowHMSFusedLocationProviderClient .log = 2.0d ;
417
418
ShadowHMSFusedLocationProviderClient .accuracy = 3.0f ;
@@ -475,7 +476,7 @@ public void testLocationSchedule_Huawei() throws Exception {
475
476
}, sdk = 19 )
476
477
public void testLocationFromSyncAlarm_Huawei () throws Exception {
477
478
ShadowOSUtils .supportsHMS (true );
478
- ShadowApplication . getInstance ( ).grantPermissions ("android.permission.ACCESS_COARSE_LOCATION" );
479
+ shadowOf ( RuntimeEnvironment . application ).grantPermissions ("android.permission.ACCESS_COARSE_LOCATION" );
479
480
480
481
ShadowHMSFusedLocationProviderClient .lat = 1.1d ;
481
482
ShadowHMSFusedLocationProviderClient .log = 2.1d ;
@@ -520,7 +521,7 @@ public void testLocationFromSyncAlarm_Huawei() throws Exception {
520
521
@ Config (shadows = {ShadowHMSFusedLocationProviderClient .class })
521
522
public void shouldSendLocationToEmailRecord_Huawei () throws Exception {
522
523
ShadowOSUtils .supportsHMS (true );
523
- ShadowApplication . getInstance ( ).grantPermissions ("android.permission.ACCESS_COARSE_LOCATION" );
524
+ shadowOf ( RuntimeEnvironment . application ).grantPermissions ("android.permission.ACCESS_COARSE_LOCATION" );
524
525
525
526
OneSignalInit ();
526
527
OneSignal .setEmail ("josh@onesignal.com" );
@@ -538,7 +539,7 @@ public void shouldSendLocationToEmailRecord_Huawei() throws Exception {
538
539
@ Config (shadows = {ShadowHMSFusedLocationProviderClient .class })
539
540
public void shouldSendLocationToSMSRecord_Huawei () throws Exception {
540
541
ShadowOSUtils .supportsHMS (true );
541
- ShadowApplication . getInstance ( ).grantPermissions ("android.permission.ACCESS_COARSE_LOCATION" );
542
+ shadowOf ( RuntimeEnvironment . application ).grantPermissions ("android.permission.ACCESS_COARSE_LOCATION" );
542
543
543
544
OneSignalInit ();
544
545
OneSignal .setSMSNumber ("123456789" );
@@ -557,7 +558,7 @@ public void shouldSendLocationToSMSRecord_Huawei() throws Exception {
557
558
public void shouldRegisterWhenPromptingAfterInit_Huawei () throws Exception {
558
559
ShadowOSUtils .supportsHMS (true );
559
560
ShadowHMSFusedLocationProviderClient .skipOnGetLocation = true ;
560
- ShadowApplication . getInstance ( ).grantPermissions ("android.permission.ACCESS_COARSE_LOCATION" );
561
+ shadowOf ( RuntimeEnvironment . application ).grantPermissions ("android.permission.ACCESS_COARSE_LOCATION" );
561
562
562
563
// Test promptLocation right after init race condition
563
564
OneSignalInit ();
@@ -578,7 +579,7 @@ public void shouldCallOnSessionEvenIfSyncJobStarted_Huawei() throws Exception {
578
579
ShadowOSUtils .supportsHMS (true );
579
580
ShadowHMSFusedLocationProviderClient .shadowTask = true ;
580
581
ShadowHuaweiTask .result = ShadowHMSFusedLocationProviderClient .getLocation ();
581
- ShadowApplication . getInstance ( ).grantPermissions ("android.permission.ACCESS_COARSE_LOCATION" );
582
+ shadowOf ( RuntimeEnvironment . application ).grantPermissions ("android.permission.ACCESS_COARSE_LOCATION" );
582
583
583
584
OneSignalInit ();
584
585
threadAndTaskWait ();
0 commit comments