Skip to content

Commit 44db927

Browse files
committed
Skip null check when creating main scheduler
This is a tradeoff to allow replacing the main scheduler in tests without needing Robolectric.
1 parent 22638e1 commit 44db927

File tree

2 files changed

+9
-3
lines changed

2 files changed

+9
-3
lines changed

rxandroid/build.gradle

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,10 @@ android {
1212
sourceCompatibility rootProject.ext.sourceCompatibility
1313
targetCompatibility rootProject.ext.sourceCompatibility
1414
}
15+
16+
testOptions {
17+
unitTests.returnDefaultValues = true
18+
}
1519
}
1620

1721
dependencies {

rxandroid/src/main/java/io/reactivex/rxjava3/android/schedulers/AndroidSchedulers.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,7 @@
2525
public final class AndroidSchedulers {
2626

2727
private static final class MainHolder {
28-
static final Scheduler DEFAULT
29-
= from(Looper.getMainLooper());
28+
static final Scheduler DEFAULT = internalFrom(Looper.getMainLooper(), true);
3029
}
3130

3231
private static final Scheduler MAIN_THREAD =
@@ -61,10 +60,13 @@ public static Scheduler from(Looper looper) {
6160
* locking. On API < 16 this value is ignored.
6261
* @see Message#setAsynchronous(boolean)
6362
*/
64-
@SuppressLint("NewApi") // Checking for an @hide API.
6563
public static Scheduler from(Looper looper, boolean async) {
6664
if (looper == null) throw new NullPointerException("looper == null");
65+
return internalFrom(looper, async);
66+
}
6767

68+
@SuppressLint("NewApi") // Checking for an @hide API.
69+
private static Scheduler internalFrom(Looper looper, boolean async) {
6870
// Below code exists in androidx-core as well, but is left here rather than include an
6971
// entire extra dependency.
7072
// https://developer.android.com/reference/kotlin/androidx/core/os/MessageCompat?hl=en#setAsynchronous(android.os.Message,%20kotlin.Boolean)

0 commit comments

Comments
 (0)