-
Notifications
You must be signed in to change notification settings - Fork 534
TCK: Fail early if registerOnSubscribe is not called #418
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
viktorklang
merged 1 commit into
reactive-streams:master
from
akarnokd:WhiteBoxOnSubscribeFix
Dec 5, 2017
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
185 changes: 185 additions & 0 deletions
185
tck/src/test/java/org/reactivestreams/tck/SubscriberNoRegisterOnSubscribeTest.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,185 @@ | ||
/************************************************************************ | ||
* Licensed under Public Domain (CC0) * | ||
* * | ||
* To the extent possible under law, the person who associated CC0 with * | ||
* this code has waived all copyright and related or neighboring * | ||
* rights to this code. * | ||
* * | ||
* You should have received a copy of the CC0 legalcode along with this * | ||
* work. If not, see <http://creativecommons.org/publicdomain/zero/1.0/>.* | ||
************************************************************************/ | ||
|
||
package org.reactivestreams.tck; | ||
|
||
import org.reactivestreams.*; | ||
import org.testng.annotations.Test; | ||
|
||
/** | ||
* This test verifies that the SubscriberWhiteboxVerification reports that | ||
* WhiteboxSubscriberProbe.registerOnSubscribe was not called during the setup | ||
* of each test. | ||
*/ | ||
@Test | ||
public class SubscriberNoRegisterOnSubscribeTest extends SubscriberWhiteboxVerification<Integer> { | ||
|
||
public SubscriberNoRegisterOnSubscribeTest() { | ||
super(new TestEnvironment()); | ||
} | ||
|
||
@Override | ||
public Subscriber<Integer> createSubscriber(final WhiteboxSubscriberProbe<Integer> probe) { | ||
return new Subscriber<Integer>() { | ||
@Override | ||
public void onSubscribe(final Subscription s) { | ||
// deliberately not calling probe.registerOnSubscribe() | ||
} | ||
|
||
@Override | ||
public void onNext(Integer integer) { | ||
probe.registerOnNext(integer); | ||
} | ||
|
||
@Override | ||
public void onError(Throwable t) { | ||
probe.registerOnError(t); | ||
} | ||
|
||
@Override | ||
public void onComplete() { | ||
probe.registerOnComplete(); | ||
} | ||
}; | ||
} | ||
|
||
@Override | ||
public Integer createElement(int element) { | ||
return element; | ||
} | ||
|
||
void assertMessage(AssertionError ex) { | ||
String message = ex.toString(); | ||
if (!message.contains(("did not `registerOnSubscribe` within"))) { | ||
throw ex; | ||
} | ||
} | ||
|
||
@Test | ||
@Override | ||
public void required_exerciseWhiteboxHappyPath() throws Throwable { | ||
try { | ||
super.required_exerciseWhiteboxHappyPath(); | ||
} catch (AssertionError ex) { | ||
assertMessage(ex); | ||
} | ||
} | ||
|
||
@Test | ||
@Override | ||
public void required_spec201_mustSignalDemandViaSubscriptionRequest() throws Throwable { | ||
try { | ||
super.required_spec201_mustSignalDemandViaSubscriptionRequest(); | ||
} catch (AssertionError ex) { | ||
assertMessage(ex); | ||
} | ||
} | ||
|
||
@Test | ||
@Override | ||
public void required_spec205_mustCallSubscriptionCancelIfItAlreadyHasAnSubscriptionAndReceivesAnotherOnSubscribeSignal() throws Throwable { | ||
try { | ||
super.required_spec205_mustCallSubscriptionCancelIfItAlreadyHasAnSubscriptionAndReceivesAnotherOnSubscribeSignal(); | ||
} catch (AssertionError ex) { | ||
assertMessage(ex); | ||
} | ||
} | ||
|
||
@Test | ||
@Override | ||
public void required_spec208_mustBePreparedToReceiveOnNextSignalsAfterHavingCalledSubscriptionCancel() throws Throwable { | ||
try { | ||
super.required_spec208_mustBePreparedToReceiveOnNextSignalsAfterHavingCalledSubscriptionCancel(); | ||
} catch (AssertionError ex) { | ||
assertMessage(ex); | ||
} | ||
} | ||
|
||
@Test | ||
@Override | ||
public void required_spec209_mustBePreparedToReceiveAnOnCompleteSignalWithoutPrecedingRequestCall() throws Throwable { | ||
try { | ||
super.required_spec209_mustBePreparedToReceiveAnOnCompleteSignalWithoutPrecedingRequestCall(); | ||
} catch (AssertionError ex) { | ||
assertMessage(ex); | ||
} | ||
} | ||
|
||
@Test | ||
@Override | ||
public void required_spec209_mustBePreparedToReceiveAnOnCompleteSignalWithPrecedingRequestCall() throws Throwable { | ||
try { | ||
super.required_spec209_mustBePreparedToReceiveAnOnCompleteSignalWithPrecedingRequestCall(); | ||
} catch (AssertionError ex) { | ||
assertMessage(ex); | ||
} | ||
} | ||
|
||
@Test | ||
@Override | ||
public void required_spec210_mustBePreparedToReceiveAnOnErrorSignalWithoutPrecedingRequestCall() throws Throwable { | ||
try { | ||
super.required_spec210_mustBePreparedToReceiveAnOnErrorSignalWithoutPrecedingRequestCall(); | ||
} catch (AssertionError ex) { | ||
assertMessage(ex); | ||
} | ||
} | ||
|
||
@Test | ||
@Override | ||
public void required_spec210_mustBePreparedToReceiveAnOnErrorSignalWithPrecedingRequestCall() throws Throwable { | ||
try { | ||
super.required_spec210_mustBePreparedToReceiveAnOnErrorSignalWithPrecedingRequestCall(); | ||
} catch (AssertionError ex) { | ||
assertMessage(ex); | ||
} | ||
} | ||
|
||
@Test | ||
@Override | ||
public void required_spec213_onError_mustThrowNullPointerExceptionWhenParametersAreNull() throws Throwable { | ||
try { | ||
super.required_spec213_onError_mustThrowNullPointerExceptionWhenParametersAreNull(); | ||
} catch (AssertionError ex) { | ||
assertMessage(ex); | ||
} | ||
} | ||
|
||
@Test | ||
@Override | ||
public void required_spec213_onNext_mustThrowNullPointerExceptionWhenParametersAreNull() throws Throwable { | ||
try { | ||
super.required_spec213_onNext_mustThrowNullPointerExceptionWhenParametersAreNull(); | ||
} catch (AssertionError ex) { | ||
assertMessage(ex); | ||
} | ||
} | ||
|
||
@Test | ||
@Override | ||
public void required_spec213_onSubscribe_mustThrowNullPointerExceptionWhenParametersAreNull() throws Throwable { | ||
try { | ||
super.required_spec213_onSubscribe_mustThrowNullPointerExceptionWhenParametersAreNull(); | ||
} catch (AssertionError ex) { | ||
assertMessage(ex); | ||
} | ||
} | ||
|
||
@Test | ||
@Override | ||
public void required_spec308_requestMustRegisterGivenNumberElementsToBeProduced() throws Throwable { | ||
try { | ||
super.required_spec308_requestMustRegisterGivenNumberElementsToBeProduced(); | ||
} catch (AssertionError ex) { | ||
assertMessage(ex); | ||
} | ||
} | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nicely done, @akarnokd! 👍