Drop unnecessary AssertJ usage in StepVerifier expression (#103)

This commit is contained in:
David Mischke
2022-05-23 22:55:09 +02:00
committed by GitHub
parent aab308a190
commit 962d18dcb5
3 changed files with 26 additions and 5 deletions

View File

@@ -2,6 +2,7 @@ package tech.picnic.errorprone.refastertemplates;
import static com.google.common.collect.MoreCollectors.toOptional;
import static com.google.errorprone.refaster.ImportPolicy.STATIC_IMPORT_ALWAYS;
import static org.assertj.core.api.Assertions.assertThat;
import com.google.common.collect.MoreCollectors;
import com.google.errorprone.refaster.Refaster;
@@ -320,7 +321,9 @@ final class ReactorTemplates {
static final class StepVerifierLastStepVerifyErrorClass<T extends Throwable> {
@BeforeTemplate
Duration before(StepVerifier.LastStep step, Class<T> clazz) {
return step.expectError(clazz).verify();
return Refaster.anyOf(
step.expectError(clazz).verify(),
step.verifyErrorSatisfies(t -> assertThat(t).isInstanceOf(clazz)));
}
@AfterTemplate

View File

@@ -1,5 +1,7 @@
package tech.picnic.errorprone.bugpatterns;
import static org.assertj.core.api.Assertions.assertThat;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableSet;
import java.time.Duration;
@@ -11,6 +13,11 @@ import reactor.test.StepVerifier;
import reactor.test.publisher.PublisherProbe;
final class ReactorTemplatesTest implements RefasterTemplateTestCase {
@Override
public ImmutableSet<?> elidedTypesAndStaticImports() {
return ImmutableSet.of(assertThat(0));
}
ImmutableSet<Mono<Integer>> testMonoFromOptional() {
return ImmutableSet.of(
Mono.fromCallable(() -> Optional.of(1).orElse(null)),
@@ -99,8 +106,11 @@ final class ReactorTemplatesTest implements RefasterTemplateTestCase {
return StepVerifier.create(Mono.empty()).expectError().verify();
}
Duration testStepVerifierLastStepVerifyErrorClass() {
return StepVerifier.create(Mono.empty()).expectError(IllegalArgumentException.class).verify();
ImmutableSet<Duration> testStepVerifierLastStepVerifyErrorClass() {
return ImmutableSet.of(
StepVerifier.create(Mono.empty()).expectError(IllegalArgumentException.class).verify(),
StepVerifier.create(Mono.empty())
.verifyErrorSatisfies(t -> assertThat(t).isInstanceOf(IllegalStateException.class)));
}
Duration testStepVerifierLastStepVerifyErrorMatches() {

View File

@@ -1,6 +1,7 @@
package tech.picnic.errorprone.bugpatterns;
import static com.google.common.collect.MoreCollectors.toOptional;
import static org.assertj.core.api.Assertions.assertThat;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableSet;
@@ -13,6 +14,11 @@ import reactor.test.StepVerifier;
import reactor.test.publisher.PublisherProbe;
final class ReactorTemplatesTest implements RefasterTemplateTestCase {
@Override
public ImmutableSet<?> elidedTypesAndStaticImports() {
return ImmutableSet.of(assertThat(0));
}
ImmutableSet<Mono<Integer>> testMonoFromOptional() {
return ImmutableSet.of(
Mono.defer(() -> Mono.justOrEmpty(Optional.of(1))),
@@ -99,8 +105,10 @@ final class ReactorTemplatesTest implements RefasterTemplateTestCase {
return StepVerifier.create(Mono.empty()).verifyError();
}
Duration testStepVerifierLastStepVerifyErrorClass() {
return StepVerifier.create(Mono.empty()).verifyError(IllegalArgumentException.class);
ImmutableSet<Duration> testStepVerifierLastStepVerifyErrorClass() {
return ImmutableSet.of(
StepVerifier.create(Mono.empty()).verifyError(IllegalArgumentException.class),
StepVerifier.create(Mono.empty()).verifyError(IllegalStateException.class));
}
Duration testStepVerifierLastStepVerifyErrorMatches() {