Skip to content

Commit dade909

Browse files
committed
+tck tests of TCK, for incoming nulls rule
1 parent 46cdc0a commit dade909

6 files changed

+116
-21
lines changed

tck/src/main/java/org/reactivestreams/tck/IdentityProcessorVerification.java

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -564,8 +564,16 @@ public void untested_spec213_failingOnSignalInvocation() throws Exception {
564564
}
565565

566566
@Override @Test
567-
public void required_spec213_mustThrowNullPointerExceptionWhenParametersAreNull() throws Throwable {
568-
subscriberVerification.required_spec213_mustThrowNullPointerExceptionWhenParametersAreNull();
567+
public void required_spec213_onSubscribe_mustThrowNullPointerExceptionWhenParametersAreNull() throws Throwable {
568+
subscriberVerification.required_spec213_onSubscribe_mustThrowNullPointerExceptionWhenParametersAreNull();
569+
}
570+
@Override @Test
571+
public void required_spec213_onNext_mustThrowNullPointerExceptionWhenParametersAreNull() throws Throwable {
572+
subscriberVerification.required_spec213_onNext_mustThrowNullPointerExceptionWhenParametersAreNull();
573+
}
574+
@Override @Test
575+
public void required_spec213_onError_mustThrowNullPointerExceptionWhenParametersAreNull() throws Throwable {
576+
subscriberVerification.required_spec213_onError_mustThrowNullPointerExceptionWhenParametersAreNull();
569577
}
570578

571579
@Override @Test

tck/src/main/java/org/reactivestreams/tck/SubscriberBlackboxVerification.java

Lines changed: 33 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,6 @@
1414
import org.testng.annotations.BeforeMethod;
1515
import org.testng.annotations.Test;
1616

17-
import java.lang.NullPointerException;
18-
import java.lang.Override;
19-
import java.lang.RuntimeException;
2017
import java.util.concurrent.ExecutorService;
2118
import java.util.concurrent.Executors;
2219

@@ -316,14 +313,10 @@ public void untested_spec213_blackbox_failingOnSignalInvocation() throws Excepti
316313

317314
// Verifies rule: https://github.com/reactive-streams/reactive-streams#2.13
318315
@Override @Test
319-
public void required_spec213_blackbox_mustThrowNullPointerExceptionWhenParametersAreNull() throws Throwable {
316+
public void required_spec213_blackbox_onSubscribe_mustThrowNullPointerExceptionWhenParametersAreNull() throws Throwable {
320317
blackboxSubscriberWithoutSetupTest(new BlackboxTestStageTestRun() {
321318
@Override
322319
public void run(BlackboxTestStage stage) throws Throwable {
323-
final Subscription subscription = new Subscription() {
324-
@Override public void request(final long elements) {}
325-
@Override public void cancel() {}
326-
};
327320

328321
{
329322
final Subscriber<T> sub = createSubscriber();
@@ -336,6 +329,22 @@ public void run(BlackboxTestStage stage) throws Throwable {
336329
assertTrue(gotNPE, "onSubscribe(null) did not throw NullPointerException");
337330
}
338331

332+
env.verifyNoAsyncErrors();
333+
}
334+
});
335+
}
336+
337+
// Verifies rule: https://github.com/reactive-streams/reactive-streams#2.13
338+
@Override @Test
339+
public void required_spec213_blackbox_onNext_mustThrowNullPointerExceptionWhenParametersAreNull() throws Throwable {
340+
blackboxSubscriberWithoutSetupTest(new BlackboxTestStageTestRun() {
341+
@Override
342+
public void run(BlackboxTestStage stage) throws Throwable {
343+
final Subscription subscription = new Subscription() {
344+
@Override public void request(final long elements) {}
345+
@Override public void cancel() {}
346+
};
347+
339348
{
340349
final Subscriber<T> sub = createSubscriber();
341350
boolean gotNPE = false;
@@ -348,6 +357,22 @@ public void run(BlackboxTestStage stage) throws Throwable {
348357
assertTrue(gotNPE, "onNext(null) did not throw NullPointerException");
349358
}
350359

360+
env.verifyNoAsyncErrors();
361+
}
362+
});
363+
}
364+
365+
// Verifies rule: https://github.com/reactive-streams/reactive-streams#2.13
366+
@Override @Test
367+
public void required_spec213_blackbox_onError_mustThrowNullPointerExceptionWhenParametersAreNull() throws Throwable {
368+
blackboxSubscriberWithoutSetupTest(new BlackboxTestStageTestRun() {
369+
@Override
370+
public void run(BlackboxTestStage stage) throws Throwable {
371+
final Subscription subscription = new Subscription() {
372+
@Override public void request(final long elements) {}
373+
@Override public void cancel() {}
374+
};
375+
351376
{
352377
final Subscriber<T> sub = createSubscriber();
353378
boolean gotNPE = false;

tck/src/main/java/org/reactivestreams/tck/SubscriberWhiteboxVerification.java

Lines changed: 34 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,9 @@
44
import org.reactivestreams.Subscriber;
55
import org.reactivestreams.Subscription;
66
import org.reactivestreams.tck.TestEnvironment.*;
7-
import org.reactivestreams.tck.support.Function;
87
import org.reactivestreams.tck.support.Optional;
9-
import org.reactivestreams.tck.support.TestException;
108
import org.reactivestreams.tck.support.SubscriberWhiteboxVerificationRules;
9+
import org.reactivestreams.tck.support.TestException;
1110
import org.testng.SkipException;
1211
import org.testng.annotations.AfterClass;
1312
import org.testng.annotations.BeforeClass;
@@ -17,7 +16,6 @@
1716
import java.util.concurrent.ExecutorService;
1817
import java.util.concurrent.Executors;
1918

20-
import static org.testng.Assert.assertEquals;
2119
import static org.testng.Assert.assertTrue;
2220

2321
/**
@@ -345,16 +343,11 @@ public void untested_spec213_failingOnSignalInvocation() throws Exception {
345343

346344
// Verifies rule: https://github.com/reactive-streams/reactive-streams#2.13
347345
@Override @Test
348-
public void required_spec213_mustThrowNullPointerExceptionWhenParametersAreNull() throws Throwable {
346+
public void required_spec213_onSubscribe_mustThrowNullPointerExceptionWhenParametersAreNull() throws Throwable {
349347
subscriberTest(new TestStageTestRun() {
350348
@Override
351349
public void run(WhiteboxTestStage stage) throws Throwable {
352350

353-
final Subscription subscription = new Subscription() {
354-
@Override public void request(final long elements) {}
355-
@Override public void cancel() {}
356-
};
357-
358351
{
359352
final Subscriber<T> sub = createSubscriber(stage.probe());
360353
boolean gotNPE = false;
@@ -366,6 +359,21 @@ public void run(WhiteboxTestStage stage) throws Throwable {
366359
assertTrue(gotNPE, "onSubscribe(null) did not throw NullPointerException");
367360
}
368361

362+
env.verifyNoAsyncErrors();
363+
}
364+
});
365+
}// Verifies rule: https://github.com/reactive-streams/reactive-streams#2.13
366+
@Override @Test
367+
public void required_spec213_onNext_mustThrowNullPointerExceptionWhenParametersAreNull() throws Throwable {
368+
subscriberTest(new TestStageTestRun() {
369+
@Override
370+
public void run(WhiteboxTestStage stage) throws Throwable {
371+
372+
final Subscription subscription = new Subscription() {
373+
@Override public void request(final long elements) {}
374+
@Override public void cancel() {}
375+
};
376+
369377
{
370378
final Subscriber<T> sub = createSubscriber(stage.probe());
371379
boolean gotNPE = false;
@@ -378,6 +386,23 @@ public void run(WhiteboxTestStage stage) throws Throwable {
378386
assertTrue(gotNPE, "onNext(null) did not throw NullPointerException");
379387
}
380388

389+
env.verifyNoAsyncErrors();
390+
}
391+
});
392+
}
393+
394+
// Verifies rule: https://github.com/reactive-streams/reactive-streams#2.13
395+
@Override @Test
396+
public void required_spec213_onError_mustThrowNullPointerExceptionWhenParametersAreNull() throws Throwable {
397+
subscriberTest(new TestStageTestRun() {
398+
@Override
399+
public void run(WhiteboxTestStage stage) throws Throwable {
400+
401+
final Subscription subscription = new Subscription() {
402+
@Override public void request(final long elements) {}
403+
@Override public void cancel() {}
404+
};
405+
381406
{
382407
final Subscriber<T> sub = createSubscriber(stage.probe());
383408
boolean gotNPE = false;

tck/src/main/java/org/reactivestreams/tck/support/SubscriberBlackboxVerificationRules.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,9 @@ public interface SubscriberBlackboxVerificationRules {
2020
void untested_spec211_blackbox_mustMakeSureThatAllCallsOnItsMethodsHappenBeforeTheProcessingOfTheRespectiveEvents() throws Exception;
2121
void untested_spec212_blackbox_mustNotCallOnSubscribeMoreThanOnceBasedOnObjectEquality() throws Throwable;
2222
void untested_spec213_blackbox_failingOnSignalInvocation() throws Exception;
23-
void required_spec213_blackbox_mustThrowNullPointerExceptionWhenParametersAreNull() throws Throwable;
23+
void required_spec213_blackbox_onSubscribe_mustThrowNullPointerExceptionWhenParametersAreNull() throws Throwable;
24+
void required_spec213_blackbox_onNext_mustThrowNullPointerExceptionWhenParametersAreNull() throws Throwable;
25+
void required_spec213_blackbox_onError_mustThrowNullPointerExceptionWhenParametersAreNull() throws Throwable;
2426
void untested_spec301_blackbox_mustNotBeCalledOutsideSubscriberContext() throws Exception;
2527
void required_spec308_blackbox_requestMustRegisterGivenNumberElementsToBeProduced() throws Throwable;
2628
void untested_spec310_blackbox_requestMaySynchronouslyCallOnNextOnSubscriber() throws Exception;

tck/src/main/java/org/reactivestreams/tck/support/SubscriberWhiteboxVerificationRules.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,9 @@ public interface SubscriberWhiteboxVerificationRules {
2222
void untested_spec211_mustMakeSureThatAllCallsOnItsMethodsHappenBeforeTheProcessingOfTheRespectiveEvents() throws Exception;
2323
void untested_spec212_mustNotCallOnSubscribeMoreThanOnceBasedOnObjectEquality_specViolation() throws Throwable;
2424
void untested_spec213_failingOnSignalInvocation() throws Exception;
25-
void required_spec213_mustThrowNullPointerExceptionWhenParametersAreNull() throws Throwable;
25+
void required_spec213_onSubscribe_mustThrowNullPointerExceptionWhenParametersAreNull() throws Throwable;
26+
void required_spec213_onNext_mustThrowNullPointerExceptionWhenParametersAreNull() throws Throwable;
27+
void required_spec213_onError_mustThrowNullPointerExceptionWhenParametersAreNull() throws Throwable;
2628
void untested_spec301_mustNotBeCalledOutsideSubscriberContext() throws Exception;
2729
void required_spec308_requestMustRegisterGivenNumberElementsToBeProduced() throws Throwable;
2830
void untested_spec310_requestMaySynchronouslyCallOnNextOnSubscriber() throws Exception;

tck/src/test/java/org/reactivestreams/tck/SubscriberBlackboxVerificationTest.java

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,39 @@ public void required_spec210_blackbox_mustBePreparedToReceiveAnOnErrorSignalWith
133133
}, "Test Exception: Boom!"); // checks that the expected exception was delivered to onError, we don't expect anyone to implement onError so weirdly
134134
}
135135

136+
@Test
137+
public void required_spec213_blackbox_mustThrowNullPointerExceptionWhenParametersAreNull_mustFailOnIgnoredNull_onSubscribe() throws Throwable {
138+
requireTestFailure(new ThrowingRunnable() {
139+
@Override public void run() throws Throwable {
140+
141+
customSubscriberVerification(new NoopSubscriber())
142+
.required_spec213_blackbox_onSubscribe_mustThrowNullPointerExceptionWhenParametersAreNull();
143+
}
144+
}, "onSubscribe(null) did not throw NullPointerException");
145+
}
146+
147+
@Test
148+
public void required_spec213_blackbox_mustThrowNullPointerExceptionWhenParametersAreNull_mustFailOnIgnoredNull_onNext() throws Throwable {
149+
requireTestFailure(new ThrowingRunnable() {
150+
@Override public void run() throws Throwable {
151+
152+
customSubscriberVerification(new NoopSubscriber())
153+
.required_spec213_blackbox_onNext_mustThrowNullPointerExceptionWhenParametersAreNull();
154+
}
155+
}, "onNext(null) did not throw NullPointerException");
156+
}
157+
158+
@Test
159+
public void required_spec213_blackbox_mustThrowNullPointerExceptionWhenParametersAreNull_mustFailOnIgnoredNull_onError() throws Throwable {
160+
requireTestFailure(new ThrowingRunnable() {
161+
@Override public void run() throws Throwable {
162+
163+
customSubscriberVerification(new NoopSubscriber())
164+
.required_spec213_blackbox_onError_mustThrowNullPointerExceptionWhenParametersAreNull();
165+
}
166+
}, "onError(null) did not throw NullPointerException");
167+
}
168+
136169
// FAILING IMPLEMENTATIONS //
137170

138171
/**

0 commit comments

Comments
 (0)