From d18cc6ad8a10ba11946811873f8f943eac2a0eab Mon Sep 17 00:00:00 2001 From: Peter Tackage Date: Thu, 6 Oct 2016 00:57:35 +0200 Subject: [PATCH 01/10] Add lazy loading of default main Scheduler --- .../android/plugins/RxAndroidPlugins.java | 50 +++++--- .../android/schedulers/AndroidSchedulers.java | 15 ++- .../android/plugins/RxAndroidPluginsTest.java | 116 +++++++++++++++--- 3 files changed, 144 insertions(+), 37 deletions(-) diff --git a/rxandroid/src/main/java/io/reactivex/android/plugins/RxAndroidPlugins.java b/rxandroid/src/main/java/io/reactivex/android/plugins/RxAndroidPlugins.java index a8607b83..54029025 100644 --- a/rxandroid/src/main/java/io/reactivex/android/plugins/RxAndroidPlugins.java +++ b/rxandroid/src/main/java/io/reactivex/android/plugins/RxAndroidPlugins.java @@ -13,31 +13,32 @@ */ package io.reactivex.android.plugins; +import java.util.concurrent.Callable; + import io.reactivex.Scheduler; -import io.reactivex.exceptions.Exceptions; import io.reactivex.functions.Function; +import io.reactivex.internal.functions.ObjectHelper; +import io.reactivex.internal.util.ExceptionHelper; /** * Utility class to inject handlers to certain standard RxAndroid operations. */ public final class RxAndroidPlugins { - private static volatile Function onInitMainThreadHandler; + + private static volatile Function, Scheduler> onInitMainThreadHandler; private static volatile Function onMainThreadHandler; - public static void setInitMainThreadSchedulerHandler(Function handler) { + public static void setInitMainThreadSchedulerHandler(Function, Scheduler> handler) { onInitMainThreadHandler = handler; } - public static Scheduler initMainThreadScheduler(Scheduler scheduler) { - Function f = onInitMainThreadHandler; + public static Scheduler initMainThreadScheduler(Callable scheduler) { + ObjectHelper.requireNonNull(scheduler, "Scheduler Callable can't be null"); + Function, Scheduler> f = onInitMainThreadHandler; if (f == null) { - return scheduler; - } - try { - return f.apply(scheduler); - } catch (Exception e) { - throw Exceptions.propagate(e); + return callRequireNonNull(scheduler); } + return applyRequireNonNull(f, scheduler); } public static void setMainThreadSchedulerHandler(Function handler) { @@ -45,15 +46,12 @@ public static void setMainThreadSchedulerHandler(Function } public static Scheduler onMainThreadScheduler(Scheduler scheduler) { + ObjectHelper.requireNonNull(scheduler, "Scheduler can't be null"); Function f = onMainThreadHandler; if (f == null) { return scheduler; } - try { - return f.apply(scheduler); - } catch (Exception e) { - throw Exceptions.propagate(e); - } + return apply(f, scheduler); } /** @@ -64,6 +62,26 @@ public static void reset() { setMainThreadSchedulerHandler(null); } + static Scheduler callRequireNonNull(Callable s) { + try { + return ObjectHelper.requireNonNull(s.call(), "Scheduler Callable result can't be null"); + } catch (Throwable ex) { + throw ExceptionHelper.wrapOrThrow(ex); + } + } + + static Scheduler applyRequireNonNull(Function, Scheduler> f, Callable s) { + return ObjectHelper.requireNonNull(apply(f, s), "Scheduler Callable result can't be null"); + } + + static R apply(Function f, T t) { + try { + return f.apply(t); + } catch (Throwable ex) { + throw ExceptionHelper.wrapOrThrow(ex); + } + } + private RxAndroidPlugins() { throw new AssertionError("No instances."); } diff --git a/rxandroid/src/main/java/io/reactivex/android/schedulers/AndroidSchedulers.java b/rxandroid/src/main/java/io/reactivex/android/schedulers/AndroidSchedulers.java index 2241cee1..5601d40f 100644 --- a/rxandroid/src/main/java/io/reactivex/android/schedulers/AndroidSchedulers.java +++ b/rxandroid/src/main/java/io/reactivex/android/schedulers/AndroidSchedulers.java @@ -15,13 +15,26 @@ import android.os.Handler; import android.os.Looper; + +import java.util.concurrent.Callable; + import io.reactivex.Scheduler; import io.reactivex.android.plugins.RxAndroidPlugins; /** Android-specific Schedulers. */ public final class AndroidSchedulers { + + private static final class MainHolder { + + static final Scheduler DEFAULT = new HandlerScheduler(new Handler(Looper.getMainLooper())); + } + private static final Scheduler MAIN_THREAD = RxAndroidPlugins.initMainThreadScheduler( - new HandlerScheduler(new Handler(Looper.getMainLooper()))); + new Callable() { + @Override public Scheduler call() throws Exception { + return MainHolder.DEFAULT; + } + }); /** A {@link Scheduler} which executes actions on the Android main thread. */ public static Scheduler mainThread() { diff --git a/rxandroid/src/test/java/io/reactivex/android/plugins/RxAndroidPluginsTest.java b/rxandroid/src/test/java/io/reactivex/android/plugins/RxAndroidPluginsTest.java index 4a38e8c8..61947332 100644 --- a/rxandroid/src/test/java/io/reactivex/android/plugins/RxAndroidPluginsTest.java +++ b/rxandroid/src/test/java/io/reactivex/android/plugins/RxAndroidPluginsTest.java @@ -13,10 +13,6 @@ */ package io.reactivex.android.plugins; -import io.reactivex.Scheduler; -import io.reactivex.android.testutil.EmptyScheduler; -import io.reactivex.functions.Function; -import java.util.concurrent.atomic.AtomicReference; import org.junit.After; import org.junit.Before; import org.junit.Test; @@ -24,6 +20,16 @@ import org.robolectric.RobolectricTestRunner; import org.robolectric.annotation.Config; +import java.util.concurrent.Callable; +import java.util.concurrent.atomic.AtomicReference; + +import io.reactivex.Scheduler; +import io.reactivex.android.testutil.EmptyScheduler; +import io.reactivex.functions.Function; +import io.reactivex.schedulers.Schedulers; + +import static junit.framework.TestCase.fail; +import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertSame; @RunWith(RobolectricTestRunner.class) @@ -67,32 +73,102 @@ public void resetClearsMainThreadHandler() { @Test public void initMainThreadHandlerCalled() { - final AtomicReference schedulerRef = new AtomicReference<>(); + final AtomicReference> schedulerRef = new AtomicReference<>(); final Scheduler newScheduler = new EmptyScheduler(); - RxAndroidPlugins.setInitMainThreadSchedulerHandler(new Function() { - @Override public Scheduler apply(Scheduler scheduler) { - schedulerRef.set(scheduler); - return newScheduler; - } - }); + RxAndroidPlugins + .setInitMainThreadSchedulerHandler(new Function, Scheduler>() { + @Override public Scheduler apply(Callable scheduler) { + schedulerRef.set(scheduler); + return newScheduler; + } + }); - Scheduler scheduler = new EmptyScheduler(); + Callable scheduler = new Callable() { + @Override public Scheduler call() throws Exception { + return new EmptyScheduler(); + } + }; Scheduler actual = RxAndroidPlugins.initMainThreadScheduler(scheduler); assertSame(newScheduler, actual); assertSame(scheduler, schedulerRef.get()); } @Test - public void resetClearsInitMainThreadHandler() { - RxAndroidPlugins.setInitMainThreadSchedulerHandler(new Function() { - @Override public Scheduler apply(Scheduler scheduler) { - throw new RuntimeException(); + public void resetClearsInitMainThreadHandler() throws Exception { + RxAndroidPlugins + .setInitMainThreadSchedulerHandler(new Function, Scheduler>() { + @Override public Scheduler apply(Callable scheduler) { + throw new RuntimeException(); + } + }); + + final Scheduler scheduler = new EmptyScheduler(); + Callable schedulerCallable = new Callable() { + @Override public Scheduler call() throws Exception { + return scheduler; } - }); + }; + RxAndroidPlugins.reset(); - Scheduler scheduler = new EmptyScheduler(); - Scheduler actual = RxAndroidPlugins.initMainThreadScheduler(scheduler); - assertSame(scheduler, actual); + Scheduler actual = RxAndroidPlugins.initMainThreadScheduler(schedulerCallable); + assertSame(schedulerCallable.call(), actual); + } + + @Test + public void defaultMainThreadSchedulerIsInitializedLazily() { + final Function, Scheduler> safeOverride = new Function, Scheduler>() { + @Override public Scheduler apply(Callable __) { + return Schedulers.single(); + } + }; + final Callable unsafeDefault = new Callable() { + @Override public Scheduler call() throws Exception { + throw new AssertionError( + "Default Scheduler instance should not have been evaluated"); + } + }; + + // unsafe default Scheduler Callable should not be evaluated when overriding + try { + RxAndroidPlugins.setInitMainThreadSchedulerHandler(safeOverride); + RxAndroidPlugins.initMainThreadScheduler(unsafeDefault); + } finally { + RxAndroidPlugins.reset(); + } } + + @Test + public void overrideInitMainSchedulerThrowsWhenSchedulerCallableIsNull() { + // fail when Callable is null + try { + RxAndroidPlugins.initMainThreadScheduler(null); + fail("Should have thrown NullPointerException"); + + } catch (NullPointerException npe) { + assertEquals("Scheduler Callable can't be null", npe.getMessage()); + } + } + + @Test + public void overrideInitMainSchedulerThrowsWhenSchedulerCallableReturnsNull() { + + Callable nullResultCallable = new Callable() { + @Override public Scheduler call() throws Exception { + return null; + } + }; + + // fail when Callable result is null + try { + RxAndroidPlugins.initMainThreadScheduler(nullResultCallable); + fail("Should have thrown NullPointerException"); + + } catch (NullPointerException npe) { + assertEquals("Scheduler Callable result can't be null", npe.getMessage()); + + } + + } + } From 0810d071c81e5b4695aa1dd1d614cfdb2e67b8fd Mon Sep 17 00:00:00 2001 From: Peter Tackage Date: Thu, 6 Oct 2016 01:04:56 +0200 Subject: [PATCH 02/10] Tidy formatting --- .../java/io/reactivex/android/plugins/RxAndroidPluginsTest.java | 2 -- 1 file changed, 2 deletions(-) diff --git a/rxandroid/src/test/java/io/reactivex/android/plugins/RxAndroidPluginsTest.java b/rxandroid/src/test/java/io/reactivex/android/plugins/RxAndroidPluginsTest.java index 61947332..4449a11b 100644 --- a/rxandroid/src/test/java/io/reactivex/android/plugins/RxAndroidPluginsTest.java +++ b/rxandroid/src/test/java/io/reactivex/android/plugins/RxAndroidPluginsTest.java @@ -152,7 +152,6 @@ public void overrideInitMainSchedulerThrowsWhenSchedulerCallableIsNull() { @Test public void overrideInitMainSchedulerThrowsWhenSchedulerCallableReturnsNull() { - Callable nullResultCallable = new Callable() { @Override public Scheduler call() throws Exception { return null; @@ -168,7 +167,6 @@ public void overrideInitMainSchedulerThrowsWhenSchedulerCallableReturnsNull() { assertEquals("Scheduler Callable result can't be null", npe.getMessage()); } - } } From 1857cf63c4199d1827019e37856927d58409e811 Mon Sep 17 00:00:00 2001 From: Peter Tackage Date: Thu, 6 Oct 2016 01:10:19 +0200 Subject: [PATCH 03/10] More tidy formatting --- .../java/io/reactivex/android/plugins/RxAndroidPluginsTest.java | 1 - 1 file changed, 1 deletion(-) diff --git a/rxandroid/src/test/java/io/reactivex/android/plugins/RxAndroidPluginsTest.java b/rxandroid/src/test/java/io/reactivex/android/plugins/RxAndroidPluginsTest.java index 4449a11b..eed0eaff 100644 --- a/rxandroid/src/test/java/io/reactivex/android/plugins/RxAndroidPluginsTest.java +++ b/rxandroid/src/test/java/io/reactivex/android/plugins/RxAndroidPluginsTest.java @@ -165,7 +165,6 @@ public void overrideInitMainSchedulerThrowsWhenSchedulerCallableReturnsNull() { } catch (NullPointerException npe) { assertEquals("Scheduler Callable result can't be null", npe.getMessage()); - } } From a7101492cfecc53966accef5336a97276ae227cd Mon Sep 17 00:00:00 2001 From: Peter Tackage Date: Thu, 6 Oct 2016 10:38:10 +0200 Subject: [PATCH 04/10] Remove unnecessary dependency --- .../io/reactivex/android/plugins/RxAndroidPluginsTest.java | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/rxandroid/src/test/java/io/reactivex/android/plugins/RxAndroidPluginsTest.java b/rxandroid/src/test/java/io/reactivex/android/plugins/RxAndroidPluginsTest.java index eed0eaff..53023651 100644 --- a/rxandroid/src/test/java/io/reactivex/android/plugins/RxAndroidPluginsTest.java +++ b/rxandroid/src/test/java/io/reactivex/android/plugins/RxAndroidPluginsTest.java @@ -26,7 +26,6 @@ import io.reactivex.Scheduler; import io.reactivex.android.testutil.EmptyScheduler; import io.reactivex.functions.Function; -import io.reactivex.schedulers.Schedulers; import static junit.framework.TestCase.fail; import static org.junit.Assert.assertEquals; @@ -119,7 +118,7 @@ public void resetClearsInitMainThreadHandler() throws Exception { public void defaultMainThreadSchedulerIsInitializedLazily() { final Function, Scheduler> safeOverride = new Function, Scheduler>() { @Override public Scheduler apply(Callable __) { - return Schedulers.single(); + return new EmptyScheduler(); } }; final Callable unsafeDefault = new Callable() { From ee5d34bd32750c5dc1e61466b99cb3e1fca28d6d Mon Sep 17 00:00:00 2001 From: Peter Tackage Date: Fri, 7 Oct 2016 20:50:25 +0200 Subject: [PATCH 05/10] Address some review comments --- .../android/plugins/RxAndroidPlugins.java | 27 +++++++++++----- .../android/plugins/RxAndroidPluginsTest.java | 31 +++++++------------ 2 files changed, 31 insertions(+), 27 deletions(-) diff --git a/rxandroid/src/main/java/io/reactivex/android/plugins/RxAndroidPlugins.java b/rxandroid/src/main/java/io/reactivex/android/plugins/RxAndroidPlugins.java index 54029025..ce44757c 100644 --- a/rxandroid/src/main/java/io/reactivex/android/plugins/RxAndroidPlugins.java +++ b/rxandroid/src/main/java/io/reactivex/android/plugins/RxAndroidPlugins.java @@ -16,9 +16,8 @@ import java.util.concurrent.Callable; import io.reactivex.Scheduler; +import io.reactivex.exceptions.Exceptions; import io.reactivex.functions.Function; -import io.reactivex.internal.functions.ObjectHelper; -import io.reactivex.internal.util.ExceptionHelper; /** * Utility class to inject handlers to certain standard RxAndroid operations. @@ -33,7 +32,9 @@ public static void setInitMainThreadSchedulerHandler(Function scheduler) { - ObjectHelper.requireNonNull(scheduler, "Scheduler Callable can't be null"); + if(scheduler == null) { + throw new NullPointerException("scheduler == null"); + } Function, Scheduler> f = onInitMainThreadHandler; if (f == null) { return callRequireNonNull(scheduler); @@ -46,7 +47,9 @@ public static void setMainThreadSchedulerHandler(Function } public static Scheduler onMainThreadScheduler(Scheduler scheduler) { - ObjectHelper.requireNonNull(scheduler, "Scheduler can't be null"); + if(scheduler == null) { + throw new NullPointerException("scheduler == null"); + } Function f = onMainThreadHandler; if (f == null) { return scheduler; @@ -64,21 +67,29 @@ public static void reset() { static Scheduler callRequireNonNull(Callable s) { try { - return ObjectHelper.requireNonNull(s.call(), "Scheduler Callable result can't be null"); + Scheduler scheduler = s.call(); + if(scheduler == null) { + throw new NullPointerException("Scheduler Callable returned null"); + } + return scheduler; } catch (Throwable ex) { - throw ExceptionHelper.wrapOrThrow(ex); + throw Exceptions.propagate(ex); } } static Scheduler applyRequireNonNull(Function, Scheduler> f, Callable s) { - return ObjectHelper.requireNonNull(apply(f, s), "Scheduler Callable result can't be null"); + Scheduler scheduler = apply(f,s); + if(scheduler == null) { + throw new NullPointerException("Scheduler Callable returned null"); + } + return scheduler; } static R apply(Function f, T t) { try { return f.apply(t); } catch (Throwable ex) { - throw ExceptionHelper.wrapOrThrow(ex); + throw Exceptions.propagate(ex); } } diff --git a/rxandroid/src/test/java/io/reactivex/android/plugins/RxAndroidPluginsTest.java b/rxandroid/src/test/java/io/reactivex/android/plugins/RxAndroidPluginsTest.java index 53023651..e215db34 100644 --- a/rxandroid/src/test/java/io/reactivex/android/plugins/RxAndroidPluginsTest.java +++ b/rxandroid/src/test/java/io/reactivex/android/plugins/RxAndroidPluginsTest.java @@ -84,7 +84,7 @@ public void initMainThreadHandlerCalled() { Callable scheduler = new Callable() { @Override public Scheduler call() throws Exception { - return new EmptyScheduler(); + throw new AssertionError(); } }; Scheduler actual = RxAndroidPlugins.initMainThreadScheduler(scheduler); @@ -116,36 +116,30 @@ public void resetClearsInitMainThreadHandler() throws Exception { @Test public void defaultMainThreadSchedulerIsInitializedLazily() { - final Function, Scheduler> safeOverride = new Function, Scheduler>() { + final Function, Scheduler> safeOverride = + new Function, Scheduler>() { @Override public Scheduler apply(Callable __) { return new EmptyScheduler(); } }; final Callable unsafeDefault = new Callable() { @Override public Scheduler call() throws Exception { - throw new AssertionError( - "Default Scheduler instance should not have been evaluated"); + throw new AssertionError(); } }; - // unsafe default Scheduler Callable should not be evaluated when overriding - try { - RxAndroidPlugins.setInitMainThreadSchedulerHandler(safeOverride); - RxAndroidPlugins.initMainThreadScheduler(unsafeDefault); - } finally { - RxAndroidPlugins.reset(); - } + RxAndroidPlugins.setInitMainThreadSchedulerHandler(safeOverride); + RxAndroidPlugins.initMainThreadScheduler(unsafeDefault); } @Test public void overrideInitMainSchedulerThrowsWhenSchedulerCallableIsNull() { - // fail when Callable is null try { RxAndroidPlugins.initMainThreadScheduler(null); - fail("Should have thrown NullPointerException"); + fail(); - } catch (NullPointerException npe) { - assertEquals("Scheduler Callable can't be null", npe.getMessage()); + } catch (NullPointerException e) { + assertEquals("scheduler == null", e.getMessage()); } } @@ -157,13 +151,12 @@ public void overrideInitMainSchedulerThrowsWhenSchedulerCallableReturnsNull() { } }; - // fail when Callable result is null try { RxAndroidPlugins.initMainThreadScheduler(nullResultCallable); - fail("Should have thrown NullPointerException"); + fail(); - } catch (NullPointerException npe) { - assertEquals("Scheduler Callable result can't be null", npe.getMessage()); + } catch (NullPointerException e) { + assertEquals("Scheduler Callable returned null", e.getMessage()); } } From 9e3d91110b57f2ee9a5c8ae02410d3ec30207eb0 Mon Sep 17 00:00:00 2001 From: Peter Tackage Date: Fri, 7 Oct 2016 21:39:58 +0200 Subject: [PATCH 06/10] Formatting --- .../java/io/reactivex/android/plugins/RxAndroidPluginsTest.java | 1 - 1 file changed, 1 deletion(-) diff --git a/rxandroid/src/test/java/io/reactivex/android/plugins/RxAndroidPluginsTest.java b/rxandroid/src/test/java/io/reactivex/android/plugins/RxAndroidPluginsTest.java index e215db34..5200b8ba 100644 --- a/rxandroid/src/test/java/io/reactivex/android/plugins/RxAndroidPluginsTest.java +++ b/rxandroid/src/test/java/io/reactivex/android/plugins/RxAndroidPluginsTest.java @@ -154,7 +154,6 @@ public void overrideInitMainSchedulerThrowsWhenSchedulerCallableReturnsNull() { try { RxAndroidPlugins.initMainThreadScheduler(nullResultCallable); fail(); - } catch (NullPointerException e) { assertEquals("Scheduler Callable returned null", e.getMessage()); } From 9521b90afd0f741fd96782329a1a9fca4ec63a63 Mon Sep 17 00:00:00 2001 From: Peter Tackage Date: Fri, 7 Oct 2016 23:08:08 +0200 Subject: [PATCH 07/10] Tidying and some address some review comments --- .../io/reactivex/android/plugins/RxAndroidPlugins.java | 8 ++++---- .../reactivex/android/plugins/RxAndroidPluginsTest.java | 6 +++--- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/rxandroid/src/main/java/io/reactivex/android/plugins/RxAndroidPlugins.java b/rxandroid/src/main/java/io/reactivex/android/plugins/RxAndroidPlugins.java index ce44757c..11ca46dc 100644 --- a/rxandroid/src/main/java/io/reactivex/android/plugins/RxAndroidPlugins.java +++ b/rxandroid/src/main/java/io/reactivex/android/plugins/RxAndroidPlugins.java @@ -32,7 +32,7 @@ public static void setInitMainThreadSchedulerHandler(Function scheduler) { - if(scheduler == null) { + if (scheduler == null) { throw new NullPointerException("scheduler == null"); } Function, Scheduler> f = onInitMainThreadHandler; @@ -47,7 +47,7 @@ public static void setMainThreadSchedulerHandler(Function } public static Scheduler onMainThreadScheduler(Scheduler scheduler) { - if(scheduler == null) { + if (scheduler == null) { throw new NullPointerException("scheduler == null"); } Function f = onMainThreadHandler; @@ -68,7 +68,7 @@ public static void reset() { static Scheduler callRequireNonNull(Callable s) { try { Scheduler scheduler = s.call(); - if(scheduler == null) { + if (scheduler == null) { throw new NullPointerException("Scheduler Callable returned null"); } return scheduler; @@ -79,7 +79,7 @@ static Scheduler callRequireNonNull(Callable s) { static Scheduler applyRequireNonNull(Function, Scheduler> f, Callable s) { Scheduler scheduler = apply(f,s); - if(scheduler == null) { + if (scheduler == null) { throw new NullPointerException("Scheduler Callable returned null"); } return scheduler; diff --git a/rxandroid/src/test/java/io/reactivex/android/plugins/RxAndroidPluginsTest.java b/rxandroid/src/test/java/io/reactivex/android/plugins/RxAndroidPluginsTest.java index 5200b8ba..a9234970 100644 --- a/rxandroid/src/test/java/io/reactivex/android/plugins/RxAndroidPluginsTest.java +++ b/rxandroid/src/test/java/io/reactivex/android/plugins/RxAndroidPluginsTest.java @@ -97,7 +97,7 @@ public void resetClearsInitMainThreadHandler() throws Exception { RxAndroidPlugins .setInitMainThreadSchedulerHandler(new Function, Scheduler>() { @Override public Scheduler apply(Callable scheduler) { - throw new RuntimeException(); + throw new AssertionError(); } }); @@ -116,13 +116,13 @@ public void resetClearsInitMainThreadHandler() throws Exception { @Test public void defaultMainThreadSchedulerIsInitializedLazily() { - final Function, Scheduler> safeOverride = + Function, Scheduler> safeOverride = new Function, Scheduler>() { @Override public Scheduler apply(Callable __) { return new EmptyScheduler(); } }; - final Callable unsafeDefault = new Callable() { + Callable unsafeDefault = new Callable() { @Override public Scheduler call() throws Exception { throw new AssertionError(); } From 936731987477ddb38a1155157fe14266b4ff760e Mon Sep 17 00:00:00 2001 From: Peter Tackage Date: Fri, 7 Oct 2016 23:09:02 +0200 Subject: [PATCH 08/10] Formatting nit --- .../java/io/reactivex/android/plugins/RxAndroidPluginsTest.java | 1 - 1 file changed, 1 deletion(-) diff --git a/rxandroid/src/test/java/io/reactivex/android/plugins/RxAndroidPluginsTest.java b/rxandroid/src/test/java/io/reactivex/android/plugins/RxAndroidPluginsTest.java index a9234970..15ff9eea 100644 --- a/rxandroid/src/test/java/io/reactivex/android/plugins/RxAndroidPluginsTest.java +++ b/rxandroid/src/test/java/io/reactivex/android/plugins/RxAndroidPluginsTest.java @@ -137,7 +137,6 @@ public void overrideInitMainSchedulerThrowsWhenSchedulerCallableIsNull() { try { RxAndroidPlugins.initMainThreadScheduler(null); fail(); - } catch (NullPointerException e) { assertEquals("scheduler == null", e.getMessage()); } From 495d8c45db61803415b8249b562a7302758cc84c Mon Sep 17 00:00:00 2001 From: Peter Tackage Date: Fri, 7 Oct 2016 23:09:50 +0200 Subject: [PATCH 09/10] Use AssertionError for consistency --- .../java/io/reactivex/android/plugins/RxAndroidPluginsTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rxandroid/src/test/java/io/reactivex/android/plugins/RxAndroidPluginsTest.java b/rxandroid/src/test/java/io/reactivex/android/plugins/RxAndroidPluginsTest.java index 15ff9eea..b5a26654 100644 --- a/rxandroid/src/test/java/io/reactivex/android/plugins/RxAndroidPluginsTest.java +++ b/rxandroid/src/test/java/io/reactivex/android/plugins/RxAndroidPluginsTest.java @@ -60,7 +60,7 @@ public void mainThreadHandlerCalled() { public void resetClearsMainThreadHandler() { RxAndroidPlugins.setMainThreadSchedulerHandler(new Function() { @Override public Scheduler apply(Scheduler scheduler) { - throw new RuntimeException(); + throw new AssertionError(); } }); RxAndroidPlugins.reset(); From cb8265f72e746e6b1ab1cbdf9b1f1f62b3f8650b Mon Sep 17 00:00:00 2001 From: Peter Tackage Date: Fri, 7 Oct 2016 23:53:55 +0200 Subject: [PATCH 10/10] Don't use __ parameter --- .../java/io/reactivex/android/plugins/RxAndroidPluginsTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rxandroid/src/test/java/io/reactivex/android/plugins/RxAndroidPluginsTest.java b/rxandroid/src/test/java/io/reactivex/android/plugins/RxAndroidPluginsTest.java index b5a26654..3d4fb776 100644 --- a/rxandroid/src/test/java/io/reactivex/android/plugins/RxAndroidPluginsTest.java +++ b/rxandroid/src/test/java/io/reactivex/android/plugins/RxAndroidPluginsTest.java @@ -118,7 +118,7 @@ public void resetClearsInitMainThreadHandler() throws Exception { public void defaultMainThreadSchedulerIsInitializedLazily() { Function, Scheduler> safeOverride = new Function, Scheduler>() { - @Override public Scheduler apply(Callable __) { + @Override public Scheduler apply(Callable scheduler) { return new EmptyScheduler(); } };