Skip to content

Commit

Permalink
Merge pull request #494 from smallrye/testing-api-improvements
Browse files Browse the repository at this point in the history
Enhance testing utilities
  • Loading branch information
jponge authored Mar 10, 2021
2 parents 45eb8ee + 6f6725d commit 4b5f7e6
Show file tree
Hide file tree
Showing 59 changed files with 1,590 additions and 482 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@ public void testOnSubscribe() {
})
.subscribe().withSubscriber(AssertSubscriber.create(20));

subscriber.await()
subscriber.awaitCompletion()
.assertItems(0L, 1L, 2L, 3L, 4L);

}
Expand All @@ -270,7 +270,7 @@ public void testSelectWhere() {
})
.subscribe().withSubscriber(AssertSubscriber.create(20));

subscriber.await()
subscriber.awaitCompletion()
.assertItems(0L, 2L, 4L);

}
Expand All @@ -289,8 +289,7 @@ public void testScan() {
.select().first(10)
.subscribe().withSubscriber(AssertSubscriber.create(10));

subscriber.await()
.assertCompleted()
subscriber.awaitCompletion()
.assertItems(0, 1, 3, 6, 10, 15, 21, 28, 36, 45);

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ public void test() {
// end::code[]
AssertSubscriber<String> subscriber = AssertSubscriber.create(Long.MAX_VALUE);
multi.subscribe().withSubscriber(subscriber)
.await()
.assertCompleted();
.awaitCompletion();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public void test() {
// end::code[]
AssertSubscriber<String> subscriber = AssertSubscriber.create(Long.MAX_VALUE);
multi.subscribe().withSubscriber(subscriber)
.await()
.awaitCompletion()
.run(() -> assertThat(subscriber.getItems()).hasSize(1000));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,13 @@ public Uni<T> call(Function<Throwable, Uni<?>> action) {
//noinspection unchecked
return (Uni<T>) uni
.onItem().failWith(ignored -> failure)
.onFailure().apply(subFailure -> new CompositeException(failure, subFailure));
.onFailure().transform(subFailure -> {
if (subFailure != failure) {
return new CompositeException(failure, subFailure);
} else {
return subFailure;
}
});
});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,16 @@ public boolean isCancelled() {
public String toString() {
return "MultiOnCancellationSpy{} " + super.toString();
}

public void assertCancelled() {
if (!isCancelled()) {
throw new AssertionError("Expected downstream cancellation, but it did not happen");
}
}

public void assertNotCancelled() {
if (isCancelled()) {
throw new AssertionError("Did not expect to receive a downstream cancellation");
}
}
}
Loading

0 comments on commit 4b5f7e6

Please sign in to comment.