Skip to content

Commit

Permalink
Extend StepVerifierStepIdentity Refaster rule (#541)
Browse files Browse the repository at this point in the history
By flagging expressions of the form `step.expectNextCount(0)`.
  • Loading branch information
mohamedsamehsalah authored Mar 27, 2023
1 parent 0b3be1b commit 57cd084
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1204,12 +1204,14 @@ StepVerifier.FirstStep<? extends T> after(Flux<T> flux) {
}
}

/** Don't unnecessarily call {@link StepVerifier.Step#expectNext(Object[])}. */
static final class StepVerifierStepExpectNextEmpty<T> {
/** Don't unnecessarily have {@link StepVerifier.Step} expect no elements. */
// XXX: Given an `IsEmpty` matcher that identifies a wide range of guaranteed-empty `Iterable`
// expressions, consider also simplifying `step.expectNextSequence(someEmptyIterable)`.
static final class StepVerifierStepIdentity<T> {
@BeforeTemplate
@SuppressWarnings("unchecked")
StepVerifier.Step<T> before(StepVerifier.Step<T> step) {
return step.expectNext();
return Refaster.anyOf(step.expectNext(), step.expectNextCount(0));
}

@AfterTemplate
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -389,8 +389,10 @@ StepVerifier.FirstStep<Integer> testStepVerifierFromFlux() {
return StepVerifier.create(Flux.just(1));
}

StepVerifier.Step<Integer> testStepVerifierStepExpectNextEmpty() {
return StepVerifier.create(Mono.just(0)).expectNext();
ImmutableSet<StepVerifier.Step<Integer>> testStepVerifierStepIdentity() {
return ImmutableSet.of(
StepVerifier.create(Mono.just(1)).expectNext(),
StepVerifier.create(Mono.just(2)).expectNextCount(0L));
}

ImmutableSet<StepVerifier.Step<String>> testStepVerifierStepExpectNext() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -377,8 +377,8 @@ StepVerifier.FirstStep<Integer> testStepVerifierFromFlux() {
return Flux.just(1).as(StepVerifier::create);
}

StepVerifier.Step<Integer> testStepVerifierStepExpectNextEmpty() {
return StepVerifier.create(Mono.just(0));
ImmutableSet<StepVerifier.Step<Integer>> testStepVerifierStepIdentity() {
return ImmutableSet.of(StepVerifier.create(Mono.just(1)), StepVerifier.create(Mono.just(2)));
}

ImmutableSet<StepVerifier.Step<String>> testStepVerifierStepExpectNext() {
Expand Down

0 comments on commit 57cd084

Please sign in to comment.