Skip to content

Commit

Permalink
Suggestions
Browse files Browse the repository at this point in the history
  • Loading branch information
Stephan202 committed Apr 12, 2024
1 parent 0dfe086 commit 3742218
Show file tree
Hide file tree
Showing 3 changed files with 78 additions and 89 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1767,13 +1767,13 @@ StepVerifier.FirstStep<? extends T> after(Flux<T> flux) {
*/
static final class StepVerifierVerify {
@BeforeTemplate
void before(StepVerifier stepVerifier) {
stepVerifier.verifyThenAssertThat();
StepVerifier.Assertions before(StepVerifier stepVerifier) {
return stepVerifier.verifyThenAssertThat();
}

@AfterTemplate
void after(StepVerifier stepVerifier) {
stepVerifier.verify();
Duration after(StepVerifier stepVerifier) {
return stepVerifier.verify();
}
}

Expand All @@ -1783,13 +1783,13 @@ void after(StepVerifier stepVerifier) {
*/
static final class StepVerifierVerifyDuration {
@BeforeTemplate
void before(StepVerifier stepVerifier, Duration duration) {
stepVerifier.verifyThenAssertThat(duration);
StepVerifier.Assertions before(StepVerifier stepVerifier, Duration duration) {
return stepVerifier.verifyThenAssertThat(duration);
}

@AfterTemplate
void after(StepVerifier stepVerifier, Duration duration) {
stepVerifier.verify(duration);
Duration after(StepVerifier stepVerifier, Duration duration) {
return stepVerifier.verify(duration);
}
}

Expand Down Expand Up @@ -1906,25 +1906,15 @@ Duration before(StepVerifier.LastStep step, Predicate<Throwable> predicate) {
return step.expectErrorMatches(predicate).verify();
}

@AfterTemplate
Duration after(StepVerifier.LastStep step, Predicate<Throwable> predicate) {
return step.verifyErrorMatches(predicate);
}
}

/**
* Prefer {@link StepVerifier.LastStep#verifyErrorMatches(Predicate)} over more verbose
* alternatives.
*/
static final class StepVerifierLastStepVerifyErrorMatchesAssertions {
@BeforeTemplate
void before(StepVerifier.LastStep step, Predicate<Throwable> predicate) {
step.expectError().verifyThenAssertThat().hasOperatorErrorMatching(predicate);
@SuppressWarnings("StepVerifierVerify" /* This is a more specific template. */)
StepVerifier.Assertions before2(StepVerifier.LastStep step, Predicate<Throwable> predicate) {
return step.expectError().verifyThenAssertThat().hasOperatorErrorMatching(predicate);
}

@AfterTemplate
void after(StepVerifier.LastStep step, Predicate<Throwable> predicate) {
step.verifyErrorMatches(predicate);
Duration after(StepVerifier.LastStep step, Predicate<Throwable> predicate) {
return step.verifyErrorMatches(predicate);
}
}

Expand All @@ -1948,10 +1938,11 @@ Duration after(StepVerifier.LastStep step, Consumer<Throwable> consumer) {
* Prefer {@link StepVerifier.LastStep#verifyErrorSatisfies(Consumer)} with AssertJ over more
* contrived alternatives.
*/
static final class StepVerifierLastStepVerifyErrorSatisfiesAssertJ {
static final class StepVerifierLastStepVerifyErrorSatisfiesAssertJ<T extends Throwable> {
@BeforeTemplate
void before(StepVerifier.LastStep step, Class<? extends Throwable> clazz, String message) {
Refaster.anyOf(
@SuppressWarnings("StepVerifierVerify" /* This is a more specific template. */)
StepVerifier.Assertions before(StepVerifier.LastStep step, Class<T> clazz, String message) {
return Refaster.anyOf(
step.expectError()
.verifyThenAssertThat()
.hasOperatorErrorOfType(clazz)
Expand All @@ -1962,8 +1953,8 @@ void before(StepVerifier.LastStep step, Class<? extends Throwable> clazz, String

@AfterTemplate
@UseImportPolicy(STATIC_IMPORT_ALWAYS)
void after(StepVerifier.LastStep step, Class<? extends Throwable> clazz, String message) {
step.verifyErrorSatisfies(t -> assertThat(t).isInstanceOf(clazz).hasMessage(message));
Duration after(StepVerifier.LastStep step, Class<T> clazz, String message) {
return step.verifyErrorSatisfies(t -> assertThat(t).isInstanceOf(clazz).hasMessage(message));
}
}

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

void testStepVerifierVerify() {
Mono.empty().as(StepVerifier::create).expectError().verifyThenAssertThat();
Object testStepVerifierVerify() {
return Mono.empty().as(StepVerifier::create).expectError().verifyThenAssertThat();
}

void testStepVerifierVerifyDuration() {
Mono.empty().as(StepVerifier::create).expectError().verifyThenAssertThat(Duration.ZERO);
Object testStepVerifierVerifyDuration() {
return Mono.empty().as(StepVerifier::create).expectError().verifyThenAssertThat(Duration.ZERO);
}

StepVerifier testStepVerifierVerifyLater() {
Expand Down Expand Up @@ -644,42 +644,41 @@ ImmutableSet<Duration> testStepVerifierLastStepVerifyErrorClass() {
.verifyErrorSatisfies(t -> assertThat(t).isInstanceOf(AssertionError.class)));
}

Duration testStepVerifierLastStepVerifyErrorMatches() {
return Mono.empty()
.as(StepVerifier::create)
.expectErrorMatches(IllegalArgumentException.class::equals)
.verify();
}

void testStepVerifierLastStepVerifyErrorMatchesAssertions() {
Mono.empty()
.as(StepVerifier::create)
.expectError()
.verifyThenAssertThat()
.hasOperatorErrorMatching(IllegalArgumentException.class::equals);
ImmutableSet<?> testStepVerifierLastStepVerifyErrorMatches() {
return ImmutableSet.of(
Mono.empty()
.as(StepVerifier::create)
.expectErrorMatches(IllegalArgumentException.class::equals)
.verify(),
Mono.empty()
.as(StepVerifier::create)
.expectError()
.verifyThenAssertThat()
.hasOperatorErrorMatching(IllegalStateException.class::equals));
}

Duration testStepVerifierLastStepVerifyErrorSatisfies() {
return Mono.empty().as(StepVerifier::create).expectErrorSatisfies(t -> {}).verify();
}

void testStepVerifierLastStepVerifyErrorSatisfiesAssertJ() {
Mono.empty()
.as(StepVerifier::create)
.expectError()
.verifyThenAssertThat()
.hasOperatorErrorOfType(IllegalStateException.class)
.hasOperatorErrorWithMessage("foo");
Mono.empty()
.as(StepVerifier::create)
.expectError(IllegalStateException.class)
.verifyThenAssertThat()
.hasOperatorErrorWithMessage("bar");
Mono.empty()
.as(StepVerifier::create)
.expectErrorMessage("baz")
.verifyThenAssertThat()
.hasOperatorErrorOfType(IllegalStateException.class);
ImmutableSet<?> testStepVerifierLastStepVerifyErrorSatisfiesAssertJ() {
return ImmutableSet.of(
Mono.empty()
.as(StepVerifier::create)
.expectError()
.verifyThenAssertThat()
.hasOperatorErrorOfType(IllegalArgumentException.class)
.hasOperatorErrorWithMessage("foo"),
Mono.empty()
.as(StepVerifier::create)
.expectError(IllegalStateException.class)
.verifyThenAssertThat()
.hasOperatorErrorWithMessage("bar"),
Mono.empty()
.as(StepVerifier::create)
.expectErrorMessage("baz")
.verifyThenAssertThat()
.hasOperatorErrorOfType(AssertionError.class));
}

Duration testStepVerifierLastStepVerifyErrorMessage() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -581,12 +581,12 @@ StepVerifier.FirstStep<Integer> testStepVerifierFromFlux() {
return Flux.just(1).as(StepVerifier::create);
}

void testStepVerifierVerify() {
Mono.empty().as(StepVerifier::create).expectError().verify();
Object testStepVerifierVerify() {
return Mono.empty().as(StepVerifier::create).expectError().verify();
}

void testStepVerifierVerifyDuration() {
Mono.empty().as(StepVerifier::create).expectError().verify(Duration.ZERO);
Object testStepVerifierVerifyDuration() {
return Mono.empty().as(StepVerifier::create).expectError().verify(Duration.ZERO);
}

StepVerifier testStepVerifierVerifyLater() {
Expand Down Expand Up @@ -626,35 +626,34 @@ ImmutableSet<Duration> testStepVerifierLastStepVerifyErrorClass() {
Mono.empty().as(StepVerifier::create).verifyError(AssertionError.class));
}

Duration testStepVerifierLastStepVerifyErrorMatches() {
return Mono.empty()
.as(StepVerifier::create)
.verifyErrorMatches(IllegalArgumentException.class::equals);
}

void testStepVerifierLastStepVerifyErrorMatchesAssertions() {
Mono.empty()
.as(StepVerifier::create)
.verifyErrorMatches(IllegalArgumentException.class::equals);
ImmutableSet<?> testStepVerifierLastStepVerifyErrorMatches() {
return ImmutableSet.of(
Mono.empty()
.as(StepVerifier::create)
.verifyErrorMatches(IllegalArgumentException.class::equals),
Mono.empty()
.as(StepVerifier::create)
.verifyErrorMatches(IllegalStateException.class::equals));
}

Duration testStepVerifierLastStepVerifyErrorSatisfies() {
return Mono.empty().as(StepVerifier::create).verifyErrorSatisfies(t -> {});
}

void testStepVerifierLastStepVerifyErrorSatisfiesAssertJ() {
Mono.empty()
.as(StepVerifier::create)
.verifyErrorSatisfies(
t -> assertThat(t).isInstanceOf(IllegalStateException.class).hasMessage("foo"));
Mono.empty()
.as(StepVerifier::create)
.verifyErrorSatisfies(
t -> assertThat(t).isInstanceOf(IllegalStateException.class).hasMessage("bar"));
Mono.empty()
.as(StepVerifier::create)
.verifyErrorSatisfies(
t -> assertThat(t).isInstanceOf(IllegalStateException.class).hasMessage("baz"));
ImmutableSet<?> testStepVerifierLastStepVerifyErrorSatisfiesAssertJ() {
return ImmutableSet.of(
Mono.empty()
.as(StepVerifier::create)
.verifyErrorSatisfies(
t -> assertThat(t).isInstanceOf(IllegalArgumentException.class).hasMessage("foo")),
Mono.empty()
.as(StepVerifier::create)
.verifyErrorSatisfies(
t -> assertThat(t).isInstanceOf(IllegalStateException.class).hasMessage("bar")),
Mono.empty()
.as(StepVerifier::create)
.verifyErrorSatisfies(
t -> assertThat(t).isInstanceOf(AssertionError.class).hasMessage("baz")));
}

Duration testStepVerifierLastStepVerifyErrorMessage() {
Expand Down

0 comments on commit 3742218

Please sign in to comment.