-
Notifications
You must be signed in to change notification settings - Fork 7.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement LambdaConsumerIntrospection (#5590)
* Implement HasDefaultErrorConsumer Followup from #5569, and allows you to introspect if the resulting observer has missing error consumption and subsequently supplies a default (throwing) one. * Add `@since` * Add tests * Add support in relevant completable observers * Add support in ConsumerSingleObserver * Add support in MaybeCallbackObserverTest * Add support in LambdaSubscriber * Switch to CompositeObserver and onErrorImplemented() * Update wording to use Introspection * Update tests and flip implementation logic to match naming
- Loading branch information
Showing
13 changed files
with
208 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
23 changes: 23 additions & 0 deletions
23
src/main/java/io/reactivex/observers/LambdaConsumerIntrospection.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package io.reactivex.observers; | ||
|
||
import io.reactivex.annotations.Experimental; | ||
|
||
/** | ||
* An interface that indicates that the implementing type is composed of individual components and exposes information | ||
* about their behavior. | ||
* | ||
* <p><em>NOTE:</em> This is considered a read-only public API and is not intended to be implemented externally. | ||
* | ||
* @since 2.1.4 - experimental | ||
*/ | ||
@Experimental | ||
public interface LambdaConsumerIntrospection { | ||
|
||
/** | ||
* @return {@code true} if a custom onError consumer implementation was supplied. Returns {@code false} if the | ||
* implementation is missing an error consumer and thus using a throwing default implementation. | ||
*/ | ||
@Experimental | ||
boolean hasCustomOnError(); | ||
|
||
} |
25 changes: 25 additions & 0 deletions
25
src/test/java/io/reactivex/internal/observers/CallbackCompletableObserverTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package io.reactivex.internal.observers; | ||
|
||
import io.reactivex.internal.functions.Functions; | ||
import org.junit.Test; | ||
|
||
import static org.junit.Assert.*; | ||
|
||
public final class CallbackCompletableObserverTest { | ||
|
||
@Test | ||
public void emptyActionShouldReportNoCustomOnError() { | ||
CallbackCompletableObserver o = new CallbackCompletableObserver(Functions.EMPTY_ACTION); | ||
|
||
assertFalse(o.hasCustomOnError()); | ||
} | ||
|
||
@Test | ||
public void customOnErrorShouldReportCustomOnError() { | ||
CallbackCompletableObserver o = new CallbackCompletableObserver(Functions.<Throwable>emptyConsumer(), | ||
Functions.EMPTY_ACTION); | ||
|
||
assertTrue(o.hasCustomOnError()); | ||
} | ||
|
||
} |
26 changes: 26 additions & 0 deletions
26
src/test/java/io/reactivex/internal/observers/ConsumerSingleObserverTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package io.reactivex.internal.observers; | ||
|
||
import io.reactivex.internal.functions.Functions; | ||
import org.junit.Test; | ||
|
||
import static org.junit.Assert.*; | ||
|
||
public final class ConsumerSingleObserverTest { | ||
|
||
@Test | ||
public void onErrorMissingShouldReportNoCustomOnError() { | ||
ConsumerSingleObserver<Integer> o = new ConsumerSingleObserver<Integer>(Functions.<Integer>emptyConsumer(), | ||
Functions.ON_ERROR_MISSING); | ||
|
||
assertFalse(o.hasCustomOnError()); | ||
} | ||
|
||
@Test | ||
public void customOnErrorShouldReportCustomOnError() { | ||
ConsumerSingleObserver<Integer> o = new ConsumerSingleObserver<Integer>(Functions.<Integer>emptyConsumer(), | ||
Functions.<Throwable>emptyConsumer()); | ||
|
||
assertTrue(o.hasCustomOnError()); | ||
} | ||
|
||
} |
15 changes: 15 additions & 0 deletions
15
src/test/java/io/reactivex/internal/observers/EmptyCompletableObserverTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package io.reactivex.internal.observers; | ||
|
||
import org.junit.Test; | ||
|
||
import static org.junit.Assert.assertFalse; | ||
|
||
public final class EmptyCompletableObserverTest { | ||
|
||
@Test | ||
public void defaultShouldReportNoCustomOnError() { | ||
EmptyCompletableObserver o = new EmptyCompletableObserver(); | ||
|
||
assertFalse(o.hasCustomOnError()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters