Skip to content

Commit 5b9a5af

Browse files
authored
Merge pull request #891 from OneSignal/upgrade/robolectric4_3_1
Updated to Robolectric 4.3.1
2 parents 0508d7e + ec099a7 commit 5b9a5af

File tree

4 files changed

+22
-17
lines changed

4 files changed

+22
-17
lines changed

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

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@
3535
import android.support.annotation.NonNull;
3636
import android.support.annotation.Nullable;
3737

38-
import java.util.Collection;
3938
import java.util.HashMap;
4039
import java.util.Set;
4140

@@ -111,11 +110,14 @@ public static class WritePrefHandlerThread extends HandlerThread {
111110

112111
WritePrefHandlerThread(String name) {
113112
super(name);
114-
start();
115-
mHandler = new Handler(getLooper());
116113
}
117114

118115
void startDelayedWrite() {
116+
if (mHandler == null) {
117+
start();
118+
mHandler = new Handler(getLooper());
119+
}
120+
119121
synchronized (mHandler) {
120122
mHandler.removeCallbacksAndMessages(null);
121123
if (lastSyncTime == 0)

OneSignalSDK/unittest/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,6 @@ dependencies {
4747
implementation 'com.google.firebase:firebase-core:16.0.4'
4848

4949
testImplementation 'junit:junit:4.12'
50-
testImplementation 'org.robolectric:robolectric:4.0'
50+
testImplementation 'org.robolectric:robolectric:4.3.1'
5151
testImplementation 'org.awaitility:awaitility:3.1.5'
5252
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,6 @@ public void tesWriteWithNullContextAndSavesAfterSetting() throws Exception {
6666

6767
final SharedPreferences prefs = blankActivity.getSharedPreferences(OneSignalPrefs.PREFS_ONESIGNAL, Context.MODE_PRIVATE);
6868
String value = prefs.getString("key", "");
69-
assertEquals(value, "value");
69+
assertEquals("value", value);
7070
}
7171
}

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

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -67,11 +67,11 @@ static void beforeTestInitAndCleanup() throws Exception {
6767
ShadowOneSignalRestClient.resetStatics();
6868

6969
ShadowPushRegistratorGCM.resetStatics();
70-
70+
7171
ShadowNotificationManagerCompat.enabled = true;
7272

7373
ShadowOSUtils.subscribableStatus = 1;
74-
74+
7575
ShadowCustomTabsClient.resetStatics();
7676
ShadowGcmBroadcastReceiver.resetStatics();
7777

@@ -125,7 +125,12 @@ static void stopAllOSThreads() {
125125
static void flushBufferedSharedPrefs() {
126126
OneSignalPrefs.WritePrefHandlerThread handlerThread = OneSignalPackagePrivateHelper.OneSignalPrefs.prefsHandler;
127127

128+
if (handlerThread.mHandler == null)
129+
return;
130+
128131
synchronized (handlerThread.mHandler) {
132+
if (handlerThread.getLooper() == null)
133+
return;
129134
Scheduler scheduler = shadowOf(handlerThread.getLooper()).getScheduler();
130135
while (scheduler.runOneTask());
131136
}
@@ -141,16 +146,16 @@ static boolean runOSThreads() throws Exception {
141146
Set<Thread> threadSet = Thread.getAllStackTraces().keySet();
142147

143148
for (Thread thread : threadSet) {
144-
if (thread.getName().startsWith("OS_")) {
145-
if (ShadowOneSignalRestClient.isAFrozenThread(thread))
146-
continue;
149+
if (!thread.getName().startsWith("OS_"))
150+
continue;
151+
if (ShadowOneSignalRestClient.isAFrozenThread(thread))
152+
continue;
147153

148-
thread.join(0, 1);
154+
thread.join(0, 1);
149155

150-
if (lastException != null)
151-
throw lastException;
152-
joinedAThread = createdNewThread = true;
153-
}
156+
if (lastException != null)
157+
throw lastException;
158+
joinedAThread = createdNewThread = true;
154159
}
155160
} while (joinedAThread);
156161

@@ -194,8 +199,6 @@ static void beforeTestSuite() throws Exception {
194199

195200
StaticResetHelper.load();
196201

197-
Looper.prepareMainLooper();
198-
199202
beforeTestInitAndCleanup();
200203

201204
System.out.println("beforeTestSuite!!!!!!");

0 commit comments

Comments
 (0)