Skip to content

Commit 1910e3a

Browse files
committed
Unit test fixes for O changes
1 parent c2f79fa commit 1910e3a

File tree

6 files changed

+42
-29
lines changed

6 files changed

+42
-29
lines changed

OneSignalSDK/onesignal/src/main/java/com/onesignal/BundleCompat.java

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,9 @@
66
import android.os.PersistableBundle;
77
import android.support.annotation.RequiresApi;
88

9-
interface BundleCompat<T> {
9+
public interface BundleCompat<T> {
1010
void putString(String key, String value);
11+
void putInt(String key, Integer value);
1112
void putLong(String key, Long value);
1213
void putBoolean(String key, Boolean value);
1314

@@ -39,6 +40,11 @@ public void putString(String key, String value) {
3940
mBundle.putString(key, value);
4041
}
4142

43+
@Override
44+
public void putInt(String key, Integer value) {
45+
mBundle.putInt(key, value);
46+
}
47+
4248
@Override
4349
public void putLong(String key, Long value) {
4450
mBundle.putLong(key, value);
@@ -104,6 +110,11 @@ class BundleCompatBundle implements BundleCompat<Bundle> {
104110
public void putString(String key, String value) {
105111
mBundle.putString(key, value);
106112
}
113+
114+
@Override
115+
public void putInt(String key, Integer value) {
116+
mBundle.putInt(key, value);
117+
}
107118

108119
@Override
109120
public void putLong(String key, Long value) {

OneSignalSDK/onesignal/src/main/java/com/onesignal/NotificationRestorer.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ class NotificationRestorer {
5151
};
5252

5353
// Notifications will never be force removed when the app's process is running.
54-
private static boolean restored;
54+
public static boolean restored;
5555

5656
static void asyncRestore(final Context context) {
5757
new Thread(new Runnable() {

OneSignalSDK/unittest/build.gradle

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -54,19 +54,19 @@ dependencies {
5454

5555
// Test with 7.0.0 to make sure there are no breaking changes in Google's libraries.
5656
// This insure that the SDK will work if an app developer is using an older version of GMS.
57-
compile "com.google.android.gms:play-services-gcm:10.0.1"
57+
compile "com.google.android.gms:play-services-gcm:11.0.2"
5858

5959
// play-services-analytics is required for AdvertisingIdClient when using GMS 8.1.0 or lower.
6060
// 8.3.0 it is included in 'basement' which is required by 'base'.
6161
//compile "com.google.android.gms:play-services-analytics:7.0.0"
62-
compile "com.google.android.gms:play-services-location:10.0.1"
62+
compile "com.google.android.gms:play-services-location:11.0.2"
6363

6464
// compile 'com.google.android.gms:play-services-analytics:7.0.0'
6565

66-
compile 'com.android.support:customtabs:24.0.0'
66+
compile 'com.android.support:customtabs:26.0.0-beta2'
6767

6868
testCompile 'junit:junit:4.12'
69-
testCompile('org.robolectric:robolectric:3.3.2') {
69+
testCompile('org.robolectric:robolectric:3.4-rc5') {
7070
exclude group: 'commons-logging', module: 'commons-logging'
7171
exclude group: 'org.apache.httpcomponents', module: 'httpclient'
7272
}

OneSignalSDK/unittest/src/test/java/com/onesignal/OneSignalPackagePrivateHelper.java

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import android.database.sqlite.SQLiteDatabase;
77
import android.os.Bundle;
88
import android.os.Looper;
9+
import android.support.v4.app.*;
910

1011
import org.json.JSONObject;
1112
import org.robolectric.util.Scheduler;
@@ -55,8 +56,8 @@ public static JSONObject bundleAsJSONObject(Bundle bundle) {
5556
return NotificationBundleProcessor.bundleAsJSONObject(bundle);
5657
}
5758

58-
public static Bundle createInternalPayloadBundle(Bundle bundle) {
59-
Bundle retBundle = new Bundle();
59+
public static BundleCompat createInternalPayloadBundle(Bundle bundle) {
60+
BundleCompat retBundle = BundleCompatFactory.getInstance();
6061
retBundle.putString("json_payload", OneSignalPackagePrivateHelper.bundleAsJSONObject(bundle).toString());
6162
return retBundle;
6263
}
@@ -65,7 +66,7 @@ public static void NotificationBundleProcessor_ProcessFromGCMIntentService(Conte
6566
NotificationBundleProcessor.ProcessFromGCMIntentService(context, createInternalPayloadBundle(bundle), overrideSettings);
6667
}
6768

68-
public static void NotificationBundleProcessor_ProcessFromGCMIntentService_NoWrap(Context context, Bundle bundle, NotificationExtenderService.OverrideSettings overrideSettings) {
69+
public static void NotificationBundleProcessor_ProcessFromGCMIntentService_NoWrap(Context context, BundleCompat bundle, NotificationExtenderService.OverrideSettings overrideSettings) {
6970
NotificationBundleProcessor.ProcessFromGCMIntentService(context, bundle, overrideSettings);
7071
}
7172

@@ -88,6 +89,8 @@ public static class NotificationGenerationJob extends com.onesignal.Notification
8889
super(context);
8990
}
9091
}
92+
93+
// public interface BundleCompat<T> extends com.onesignal.BundleCompat {}
9194

9295

9396
public static void OneSignalRestClientPublic_getSync(final String url, final OneSignalRestClient.ResponseHandler responseHandler) {

OneSignalSDK/unittest/src/test/java/com/test/onesignal/GenerateNotificationRunner.java

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/**
22
* Modified MIT License
33
*
4-
* Copyright 2016 OneSignal
4+
* Copyright 2017 OneSignal
55
*
66
* Permission is hereby granted, free of charge, to any person obtaining a copy
77
* of this software and associated documentation files (the "Software"), to deal
@@ -42,6 +42,7 @@
4242
import android.support.v4.app.NotificationCompat;
4343

4444
import com.onesignal.BuildConfig;
45+
import com.onesignal.BundleCompat;
4546
import com.onesignal.GcmBroadcastReceiver;
4647
import com.onesignal.GcmIntentService;
4748
import com.onesignal.NotificationExtenderService;
@@ -80,8 +81,8 @@
8081
import org.robolectric.annotation.Config;
8182
import org.robolectric.shadows.ShadowLog;
8283
import org.robolectric.shadows.ShadowSystemClock;
83-
import org.robolectric.util.ActivityController;
84-
import org.robolectric.util.ServiceController;
84+
import org.robolectric.android.controller.ActivityController;
85+
import org.robolectric.android.controller.ServiceController;
8586

8687
import java.math.BigInteger;
8788
import java.util.Iterator;
@@ -180,7 +181,7 @@ public void shouldSetTitleCorrectly() throws Exception {
180181

181182
@Test
182183
public void shouldProcessRestore() throws Exception {
183-
Bundle bundle = createInternalPayloadBundle(getBaseNotifBundle());
184+
BundleCompat bundle = createInternalPayloadBundle(getBaseNotifBundle());
184185
bundle.putInt("android_notif_id", 0);
185186
bundle.putBoolean("restoring", true);
186187

@@ -407,12 +408,10 @@ public void shouldUpdateNormalNotificationDisplayWhenReplacingANotification() th
407408
ShadowRoboNotificationManager.notifications.clear();
408409

409410
// Setup - Restore
410-
bundle = getBaseNotifBundle("UUID2");
411-
bundle.putString("grp", "test1");
412-
bundle = createInternalPayloadBundle(bundle);
411+
BundleCompat bundle2 = createInternalPayloadBundle(bundle);
413412
bundle.putInt("android_notif_id", lastNotifId);
414413
bundle.putBoolean("restoring", true);
415-
NotificationBundleProcessor_ProcessFromGCMIntentService_NoWrap(blankActivity, bundle, null);
414+
NotificationBundleProcessor_ProcessFromGCMIntentService_NoWrap(blankActivity, bundle2, null);
416415

417416
// Test - Restored notifications display exactly the same as they did when recevied.
418417
postedNotifs = ShadowRoboNotificationManager.notifications;
@@ -803,11 +802,11 @@ private void testNotificationExtenderServiceOverridePropertiesWithSummary() thro
803802
}
804803

805804

806-
private NotificationExtenderServiceTestBase startNotificationExtender(Bundle bundlePayload, Class serviceClass) {
805+
private NotificationExtenderServiceTestBase startNotificationExtender(BundleCompat bundlePayload, Class serviceClass) {
807806
ServiceController<NotificationExtenderServiceTestBase> controller = Robolectric.buildService(serviceClass);
808-
NotificationExtenderServiceTestBase service = controller.attach().create().get();
807+
NotificationExtenderServiceTestBase service = controller.create().get();
809808
Intent testIntent = new Intent(RuntimeEnvironment.application, NotificationExtenderServiceTestReturnFalse.class);
810-
testIntent.putExtras(bundlePayload);
809+
testIntent.putExtras((Bundle)bundlePayload.getBundle());
811810
controller.withIntent(testIntent).startCommand(0, 0);
812811

813812
return service;
@@ -825,7 +824,7 @@ public void shouldFireNotificationExtenderService() throws Exception {
825824
ResolveInfo resolveInfo = new ResolveInfo();
826825
resolveInfo.serviceInfo = new ServiceInfo();
827826
resolveInfo.serviceInfo.name = "com.onesignal.example.NotificationExtenderServiceTest";
828-
RuntimeEnvironment.getRobolectricPackageManager().addResolveInfoForIntent(serviceIntent, resolveInfo);
827+
shadowOf(blankActivity.getPackageManager()).addResolveInfoForIntent(serviceIntent, resolveInfo);
829828

830829
boolean ret = OneSignalPackagePrivateHelper.GcmBroadcastReceiver_processBundle(blankActivity, bundle);
831830
Assert.assertTrue(ret);

OneSignalSDK/unittest/src/test/java/com/test/onesignal/MainOneSignalClassRunner.java

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@
8888
import org.robolectric.shadows.ShadowConnectivityManager;
8989
import org.robolectric.shadows.ShadowLog;
9090
import org.robolectric.shadows.ShadowSystemClock;
91-
import org.robolectric.util.ActivityController;
91+
import org.robolectric.android.controller.ActivityController;
9292

9393
import java.lang.reflect.Field;
9494
import java.lang.reflect.Method;
@@ -1459,7 +1459,7 @@ public void testLocationFromSyncAlarm() throws Exception {
14591459
@Test
14601460
public void testAppl() throws Exception {
14611461
AddLauncherIntentFilter();
1462-
RuntimeEnvironment.getRobolectricPackageManager().addPackage("org.robolectric.default");
1462+
shadowOf(blankActivity.getPackageManager()).addPackage("org.robolectric.default");
14631463

14641464
OneSignalInit();
14651465
threadAndTaskWait();
@@ -1477,14 +1477,14 @@ public void testAppl() throws Exception {
14771477

14781478
restartAppAndElapseTimeToNextSession();
14791479
ShadowOneSignalRestClient.lastPost = null;
1480-
RuntimeEnvironment.getRobolectricPackageManager().addPackage("org.test.app2");
1480+
shadowOf(blankActivity.getPackageManager()).addPackage("org.test.app2");
14811481
OneSignalInit();
14821482
threadAndTaskWait();
14831483
Assert.assertEquals(1, ShadowOneSignalRestClient.lastPost.getJSONArray(baseKey + "_a").length());
14841484

14851485
restartAppAndElapseTimeToNextSession();
14861486
ShadowOneSignalRestClient.lastPost = null;
1487-
RuntimeEnvironment.getRobolectricPackageManager().removePackage("org.test.app2");
1487+
shadowOf(blankActivity.getPackageManager()).removePackage("org.test.app2");
14881488
OneSignalInit();
14891489
threadAndTaskWait();
14901490
Assert.assertEquals(1, ShadowOneSignalRestClient.lastPost.getJSONArray(baseKey + "_d").length());
@@ -1868,18 +1868,18 @@ private static void AddLauncherIntentFilter() {
18681868
resolveInfo.activityInfo.packageName = "com.onesignal.example";
18691869
resolveInfo.activityInfo.name = "MainActivity";
18701870

1871-
RuntimeEnvironment.getRobolectricPackageManager().addResolveInfoForIntent(launchIntent, resolveInfo);
1872-
RuntimeEnvironment.getRobolectricPackageManager().addManifest(shadowOf(RuntimeEnvironment.application).getAppManifest(), 0);
1871+
shadowOf(blankActivity.getPackageManager()).addResolveInfoForIntent(launchIntent, resolveInfo);
1872+
shadowOf(blankActivity.getPackageManager()).addManifest(shadowOf(RuntimeEnvironment.application).getAppManifest());
18731873
}
18741874

18751875
private static void AddDisableNotificationOpenedToManifest() {
18761876
ShadowApplication.getInstance().getAppManifest().getApplicationMetaData().put("com.onesignal.NotificationOpened.DEFAULT", "DISABLE");
1877-
RuntimeEnvironment.getRobolectricPackageManager().addManifest(shadowOf(RuntimeEnvironment.application).getAppManifest(), 0);
1877+
shadowOf(blankActivity.getPackageManager()).addManifest(shadowOf(RuntimeEnvironment.application).getAppManifest());
18781878
}
18791879

18801880
private static void RemoveDisableNotificationOpenedToManifest() {
18811881
ShadowApplication.getInstance().getAppManifest().getApplicationMetaData().remove("com.onesignal.NotificationOpened.DEFAULT");
1882-
RuntimeEnvironment.getRobolectricPackageManager().addManifest(shadowOf(RuntimeEnvironment.application).getAppManifest(), 0);
1882+
shadowOf(blankActivity.getPackageManager()).addManifest(shadowOf(RuntimeEnvironment.application).getAppManifest());
18831883
}
18841884

18851885
private static int sessionCountOffset = 1;

0 commit comments

Comments
 (0)