Skip to content

Commit 287ca7a

Browse files
ktosobenjchristensen
authored andcommitted
+tck #29 null checks fixed - null from ABQueue#poll means "timeout"
1 parent d885731 commit 287ca7a

File tree

1 file changed

+12
-14
lines changed

1 file changed

+12
-14
lines changed

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

+12-14
Original file line numberDiff line numberDiff line change
@@ -493,10 +493,10 @@ public void assertUncompleted(String errorMsg) {
493493
env.flop(errorMsg);
494494
}
495495

496-
497496
public void expectCompletion(long timeoutMillis, String errorMsg) throws InterruptedException {
498497
if (!isCompleted()) {
499498
T val = abq.poll(timeoutMillis, TimeUnit.MILLISECONDS);
499+
500500
if (val == null) {
501501
env.flop(String.format("%s within %d ms", errorMsg, timeoutMillis));
502502
} else {
@@ -528,25 +528,25 @@ public void complete() {
528528
public T next(long timeoutMillis, String errorMsg) throws InterruptedException {
529529
Optional<T> value = abq.poll(timeoutMillis, TimeUnit.MILLISECONDS);
530530

531-
if (value.isEmpty()) {
532-
env.flop("Expected element but got end-of-stream");
533-
} else if (value.get() == null) {
531+
if (value == null) {
534532
env.flop(String.format("%s within %d ms", errorMsg, timeoutMillis));
535-
} else {
533+
} else if (value.isDefined()) {
536534
return value.get();
535+
} else {
536+
env.flop("Expected element but got end-of-stream");
537537
}
538538

539539
return null; // keep compiler happy
540540
}
541541

542542
public Optional<T> nextOrEndOfStream(long timeoutMillis, String errorMsg) throws InterruptedException {
543543
Optional<T> value = abq.poll(timeoutMillis, TimeUnit.MILLISECONDS);
544-
if (value.isDefined()) {
545-
return value;
546-
} else {
544+
545+
if (value == null) {
547546
env.flop(String.format("%s within %d ms", errorMsg, timeoutMillis));
548-
return null; // keep compiler happy
549547
}
548+
549+
return value;
550550
}
551551

552552
public List<T> nextN(int elements, long timeoutMillis, String errorMsg) throws InterruptedException {
@@ -564,13 +564,11 @@ public List<T> nextN(int elements, long timeoutMillis, String errorMsg) throws I
564564
public void expectCompletion(long timeoutMillis, String errorMsg) throws InterruptedException {
565565
Optional<T> value = abq.poll(timeoutMillis, TimeUnit.MILLISECONDS);
566566

567-
if (value.isEmpty()) {
568-
// ok
569-
} else if (value.get() == null) {
567+
if (value == null) {
570568
env.flop(String.format("%s within %d ms", errorMsg, timeoutMillis));
571-
} else {
569+
} else if (value.isDefined()) {
572570
env.flop("Expected end-of-stream but got " + value.get());
573-
}
571+
} // else, ok
574572
}
575573

576574
void expectNone(long withinMillis, String errorMsgPrefix) throws InterruptedException {

0 commit comments

Comments
 (0)