mirror of
https://github.com/jlengrand/error-prone-support.git
synced 2026-03-10 08:11:25 +00:00
Compare commits
6 Commits
rossendrij
...
nkooij/web
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
8b0a287d6d | ||
|
|
8dd587850b | ||
|
|
21592cea95 | ||
|
|
e1bdb098de | ||
|
|
0be162c837 | ||
|
|
edfb2a70e8 |
@@ -171,6 +171,11 @@
|
||||
<artifactId>spring-context</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework</groupId>
|
||||
<artifactId>spring-core</artifactId>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework</groupId>
|
||||
<artifactId>spring-test</artifactId>
|
||||
|
||||
@@ -39,6 +39,7 @@ import java.util.stream.Collector;
|
||||
import java.util.stream.Stream;
|
||||
import org.assertj.core.api.AbstractAssert;
|
||||
import org.assertj.core.api.AbstractBooleanAssert;
|
||||
import org.assertj.core.api.AbstractCollectionAssert;
|
||||
import org.assertj.core.api.AbstractComparableAssert;
|
||||
import org.assertj.core.api.AbstractDoubleAssert;
|
||||
import org.assertj.core.api.AbstractIntegerAssert;
|
||||
@@ -529,7 +530,7 @@ final class AssertJTemplates {
|
||||
|
||||
static final class AssertThatSetsAreEqual<S, T extends S> {
|
||||
@BeforeTemplate
|
||||
IterableAssert<S> before(Set<S> set1, Set<T> set2) {
|
||||
AbstractCollectionAssert<?, ?, S, ?> before(Set<S> set1, Set<T> set2) {
|
||||
return Refaster.anyOf(
|
||||
assertThat(set1).isEqualTo(set2),
|
||||
assertThat(set1).containsExactlyInAnyOrderElementsOf(set2));
|
||||
@@ -537,7 +538,7 @@ final class AssertJTemplates {
|
||||
|
||||
@AfterTemplate
|
||||
@UseImportPolicy(ImportPolicy.STATIC_IMPORT_ALWAYS)
|
||||
IterableAssert<S> after(Set<S> set1, Set<T> set2) {
|
||||
AbstractCollectionAssert<?, ?, S, ?> after(Set<S> set1, Set<T> set2) {
|
||||
return assertThat(set1).hasSameElementsAs(set2);
|
||||
}
|
||||
}
|
||||
@@ -548,13 +549,13 @@ final class AssertJTemplates {
|
||||
|
||||
static final class AssertThatMultisetsAreEqual<S, T extends S> {
|
||||
@BeforeTemplate
|
||||
IterableAssert<S> before(Multiset<S> multiset1, Multiset<T> multiset2) {
|
||||
AbstractCollectionAssert<?, ?, S, ?> before(Multiset<S> multiset1, Multiset<T> multiset2) {
|
||||
return assertThat(multiset1).isEqualTo(multiset2);
|
||||
}
|
||||
|
||||
@AfterTemplate
|
||||
@UseImportPolicy(ImportPolicy.STATIC_IMPORT_ALWAYS)
|
||||
IterableAssert<S> after(Multiset<S> multiset1, Multiset<T> multiset2) {
|
||||
AbstractCollectionAssert<?, ?, S, ?> after(Multiset<S> multiset1, Multiset<T> multiset2) {
|
||||
return assertThat(multiset1).containsExactlyInAnyOrderElementsOf(multiset2);
|
||||
}
|
||||
}
|
||||
@@ -934,7 +935,7 @@ final class AssertJTemplates {
|
||||
}
|
||||
|
||||
@BeforeTemplate
|
||||
IterableAssert<T> before2(
|
||||
AbstractCollectionAssert<?, ?, T, ?> before2(
|
||||
Stream<S> stream, Collector<S, ?, ? extends Multiset<T>> collector, Iterable<U> iterable) {
|
||||
return assertThat(stream.collect(collector)).containsExactlyInAnyOrderElementsOf(iterable);
|
||||
}
|
||||
@@ -955,7 +956,7 @@ final class AssertJTemplates {
|
||||
}
|
||||
|
||||
@BeforeTemplate
|
||||
IterableAssert<T> before2(
|
||||
AbstractCollectionAssert<?, ?, T, ?> before2(
|
||||
Stream<S> stream, Collector<S, ?, ? extends Multiset<T>> collector, U[] array) {
|
||||
return assertThat(stream.collect(collector)).containsExactlyInAnyOrder(array);
|
||||
}
|
||||
@@ -979,7 +980,7 @@ final class AssertJTemplates {
|
||||
|
||||
@BeforeTemplate
|
||||
@SuppressWarnings("AssertThatStreamContainsExactlyInAnyOrder" /* Varargs converted to array. */)
|
||||
IterableAssert<T> before2(
|
||||
AbstractCollectionAssert<?, ?, T, ?> before2(
|
||||
Stream<S> stream, Collector<S, ?, ? extends Multiset<T>> collector, @Repeated U elements) {
|
||||
return assertThat(stream.collect(collector))
|
||||
.containsExactlyInAnyOrder(Refaster.asVarargs(elements));
|
||||
|
||||
@@ -128,19 +128,6 @@ final class ImmutableListTemplates {
|
||||
}
|
||||
}
|
||||
|
||||
/** Don't call {@link ImmutableList#asList()}; it is a no-op. */
|
||||
static final class ImmutableListAsList<T> {
|
||||
@BeforeTemplate
|
||||
ImmutableList<T> before(ImmutableList<T> list) {
|
||||
return list.asList();
|
||||
}
|
||||
|
||||
@AfterTemplate
|
||||
ImmutableList<T> after(ImmutableList<T> list) {
|
||||
return list;
|
||||
}
|
||||
}
|
||||
|
||||
/** Prefer {@link ImmutableList#sortedCopyOf(Iterable)} over more contrived alternatives. */
|
||||
static final class ImmutableListSortedCopyOf<T extends Comparable<? super T>> {
|
||||
@BeforeTemplate
|
||||
|
||||
@@ -91,19 +91,6 @@ final class OptionalTemplates {
|
||||
}
|
||||
}
|
||||
|
||||
/** Prefer {@link Optional#stream()} over the Guava alternative. */
|
||||
static final class OptionalToStream<T> {
|
||||
@BeforeTemplate
|
||||
Stream<T> before(Optional<T> optional) {
|
||||
return Streams.stream(optional);
|
||||
}
|
||||
|
||||
@AfterTemplate
|
||||
Stream<T> after(Optional<T> optional) {
|
||||
return optional.stream();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Don't use the ternary operator to extract the first element of a possibly-empty {@link
|
||||
* Iterator} as an {@link Optional}.
|
||||
|
||||
@@ -1,12 +1,19 @@
|
||||
package tech.picnic.errorprone.refastertemplates;
|
||||
|
||||
import static java.util.function.Function.identity;
|
||||
import static org.springframework.web.reactive.function.BodyInserters.fromValue;
|
||||
|
||||
import com.google.errorprone.refaster.Refaster;
|
||||
import com.google.errorprone.refaster.annotation.AfterTemplate;
|
||||
import com.google.errorprone.refaster.annotation.BeforeTemplate;
|
||||
import java.util.Collection;
|
||||
import org.springframework.core.ParameterizedTypeReference;
|
||||
import org.springframework.test.web.reactive.server.WebTestClient;
|
||||
import org.springframework.web.reactive.function.client.WebClient;
|
||||
import org.springframework.web.reactive.function.client.WebClient.RequestBodySpec;
|
||||
import org.springframework.web.reactive.function.client.WebClient.RequestHeadersSpec;
|
||||
import reactor.core.publisher.Flux;
|
||||
import reactor.core.publisher.Mono;
|
||||
|
||||
/**
|
||||
* Refaster templates related to expressions dealing with {@link
|
||||
@@ -33,4 +40,54 @@ final class WebClientTemplates {
|
||||
return requestBodySpec.bodyValue(value);
|
||||
}
|
||||
}
|
||||
|
||||
static final class RetrieveArray<T> {
|
||||
@BeforeTemplate
|
||||
Flux<T> before(WebClient.ResponseSpec responseSpec) {
|
||||
return responseSpec.bodyToMono(Refaster.<T[]>clazz()).flux().flatMap(Flux::fromArray);
|
||||
}
|
||||
|
||||
@AfterTemplate
|
||||
Flux<T> after(WebClient.ResponseSpec responseSpec) {
|
||||
return responseSpec.bodyToFlux(Refaster.<T>clazz());
|
||||
}
|
||||
}
|
||||
|
||||
static final class RetrieveParameterizedTypeReference<T> {
|
||||
@BeforeTemplate
|
||||
Flux<T> before(
|
||||
WebClient.ResponseSpec responseSpec,
|
||||
ParameterizedTypeReference<? extends Collection<T>> clazz) {
|
||||
return responseSpec.bodyToMono(clazz).flux().flatMapIterable(identity());
|
||||
}
|
||||
|
||||
@AfterTemplate
|
||||
Flux<T> after(WebClient.ResponseSpec responseSpec) {
|
||||
return responseSpec.bodyToFlux(Refaster.<T>clazz());
|
||||
}
|
||||
}
|
||||
|
||||
static final class RetrieveSingle<T> {
|
||||
@BeforeTemplate
|
||||
Mono<T> before(Mono<T> mono, Class<T> clazz) {
|
||||
return mono.flux().single();
|
||||
}
|
||||
|
||||
@AfterTemplate
|
||||
Mono<T> after(Mono<T> mono, Class<T> clazz) {
|
||||
return mono.single();
|
||||
}
|
||||
}
|
||||
|
||||
static final class RetrieveSingleOrEmpty<T> {
|
||||
@BeforeTemplate
|
||||
Mono<T> before(Mono<T> mono, Class<T> clazz) {
|
||||
return mono.flux().singleOrEmpty();
|
||||
}
|
||||
|
||||
@AfterTemplate
|
||||
Mono<T> after(Mono<T> mono) {
|
||||
return mono;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -59,10 +59,6 @@ final class ImmutableListTemplatesTest implements RefasterTemplateTestCase {
|
||||
Stream.of(2).collect(collectingAndThen(toList(), ImmutableList::copyOf)));
|
||||
}
|
||||
|
||||
ImmutableList<Integer> testImmutableListAsList() {
|
||||
return ImmutableList.of(1, 2, 3).asList();
|
||||
}
|
||||
|
||||
ImmutableSet<ImmutableList<Integer>> testImmutableListSortedCopyOf() {
|
||||
return ImmutableSet.of(
|
||||
ImmutableList.sortedCopyOf(naturalOrder(), ImmutableSet.of(1)),
|
||||
|
||||
@@ -57,10 +57,6 @@ final class ImmutableListTemplatesTest implements RefasterTemplateTestCase {
|
||||
Stream.of(1).collect(toImmutableList()), Stream.of(2).collect(toImmutableList()));
|
||||
}
|
||||
|
||||
ImmutableList<Integer> testImmutableListAsList() {
|
||||
return ImmutableList.of(1, 2, 3);
|
||||
}
|
||||
|
||||
ImmutableSet<ImmutableList<Integer>> testImmutableListSortedCopyOf() {
|
||||
return ImmutableSet.of(
|
||||
ImmutableList.sortedCopyOf(ImmutableSet.of(1)),
|
||||
|
||||
@@ -34,10 +34,6 @@ final class OptionalTemplatesTest implements RefasterTemplateTestCase {
|
||||
return Optional::get;
|
||||
}
|
||||
|
||||
Stream<Object> testOptionalToStream() {
|
||||
return Stream.concat(Streams.stream(Optional.empty()), Streams.stream(Optional.of("foo")));
|
||||
}
|
||||
|
||||
ImmutableSet<Optional<String>> testOptionalFirstIteratorElement() {
|
||||
return ImmutableSet.of(
|
||||
ImmutableSet.of("foo").iterator().hasNext()
|
||||
|
||||
@@ -34,10 +34,6 @@ final class OptionalTemplatesTest implements RefasterTemplateTestCase {
|
||||
return Optional::orElseThrow;
|
||||
}
|
||||
|
||||
Stream<Object> testOptionalToStream() {
|
||||
return Stream.concat(Optional.empty().stream(), Optional.of("foo").stream());
|
||||
}
|
||||
|
||||
ImmutableSet<Optional<String>> testOptionalFirstIteratorElement() {
|
||||
return ImmutableSet.of(
|
||||
stream(ImmutableSet.of("foo").iterator()).findFirst(),
|
||||
|
||||
@@ -1,15 +1,25 @@
|
||||
package tech.picnic.errorprone.bugpatterns;
|
||||
|
||||
import static java.util.function.Function.identity;
|
||||
import static org.springframework.web.reactive.function.BodyInserters.fromValue;
|
||||
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
import org.springframework.core.ParameterizedTypeReference;
|
||||
import org.springframework.test.web.reactive.server.WebTestClient;
|
||||
import org.springframework.web.reactive.function.client.WebClient;
|
||||
import reactor.core.publisher.Flux;
|
||||
import reactor.core.publisher.Mono;
|
||||
|
||||
final class WebClientTemplatesTest implements RefasterTemplateTestCase {
|
||||
@Override
|
||||
public ImmutableSet<?> elidedTypesAndStaticImports() {
|
||||
return ImmutableSet.of(fromValue(""));
|
||||
return ImmutableSet.of(
|
||||
fromValue(""),
|
||||
identity(),
|
||||
Flux.class,
|
||||
ImmutableList.class,
|
||||
ParameterizedTypeReference.class);
|
||||
}
|
||||
|
||||
ImmutableSet<?> testBodyValue() {
|
||||
@@ -17,4 +27,30 @@ final class WebClientTemplatesTest implements RefasterTemplateTestCase {
|
||||
WebClient.create("foo").post().body(fromValue("bar")),
|
||||
WebTestClient.bindToServer().build().post().body(fromValue("bar")));
|
||||
}
|
||||
|
||||
public void testBodyToFluxValue() {
|
||||
WebClient.create("foo")
|
||||
.get()
|
||||
.retrieve()
|
||||
.bodyToMono(Integer[].class)
|
||||
.flux()
|
||||
.flatMap(Flux::fromArray);
|
||||
}
|
||||
|
||||
public void testOther() {
|
||||
WebClient.create("foo")
|
||||
.get()
|
||||
.retrieve()
|
||||
.bodyToMono(new ParameterizedTypeReference<ImmutableList<String>>() {})
|
||||
.flux()
|
||||
.flatMapIterable(identity());
|
||||
}
|
||||
|
||||
public void testCase3() {
|
||||
Mono.empty().flux().single();
|
||||
}
|
||||
|
||||
public void testCase4() {
|
||||
Mono.empty().flux().singleOrEmpty();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,15 +1,25 @@
|
||||
package tech.picnic.errorprone.bugpatterns;
|
||||
|
||||
import static java.util.function.Function.identity;
|
||||
import static org.springframework.web.reactive.function.BodyInserters.fromValue;
|
||||
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
import org.springframework.core.ParameterizedTypeReference;
|
||||
import org.springframework.test.web.reactive.server.WebTestClient;
|
||||
import org.springframework.web.reactive.function.client.WebClient;
|
||||
import reactor.core.publisher.Flux;
|
||||
import reactor.core.publisher.Mono;
|
||||
|
||||
final class WebClientTemplatesTest implements RefasterTemplateTestCase {
|
||||
@Override
|
||||
public ImmutableSet<?> elidedTypesAndStaticImports() {
|
||||
return ImmutableSet.of(fromValue(""));
|
||||
return ImmutableSet.of(
|
||||
fromValue(""),
|
||||
identity(),
|
||||
Flux.class,
|
||||
ImmutableList.class,
|
||||
ParameterizedTypeReference.class);
|
||||
}
|
||||
|
||||
ImmutableSet<?> testBodyValue() {
|
||||
@@ -17,4 +27,20 @@ final class WebClientTemplatesTest implements RefasterTemplateTestCase {
|
||||
WebClient.create("foo").post().bodyValue("bar"),
|
||||
WebTestClient.bindToServer().build().post().bodyValue("bar"));
|
||||
}
|
||||
|
||||
public void testBodyToFluxValue() {
|
||||
WebClient.create("foo").get().retrieve().bodyToFlux(Integer.class);
|
||||
}
|
||||
|
||||
public void testOther() {
|
||||
WebClient.create("foo").get().retrieve().bodyToFlux(String.class);
|
||||
}
|
||||
|
||||
public void testCase3() {
|
||||
Mono.empty().single();
|
||||
}
|
||||
|
||||
public void testCase4() {
|
||||
Mono.empty();
|
||||
}
|
||||
}
|
||||
|
||||
18
pom.xml
18
pom.xml
@@ -126,6 +126,7 @@
|
||||
one place. We use these to keep dependencies in sync. Version numbers
|
||||
that need to be referenced only once should *not* be listed here. -->
|
||||
<version.auto-service>1.0</version.auto-service>
|
||||
<version.auto-value>1.8.2</version.auto-value>
|
||||
<version.error-prone>${version.error-prone-orig}</version.error-prone>
|
||||
<version.error-prone-fork>v${version.error-prone-orig}-picnic-1</version.error-prone-fork>
|
||||
<version.error-prone-orig>2.9.0</version.error-prone-orig>
|
||||
@@ -203,10 +204,15 @@
|
||||
<artifactId>auto-service-annotations</artifactId>
|
||||
<version>${version.auto-service}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.google.auto.value</groupId>
|
||||
<artifactId>auto-value</artifactId>
|
||||
<version>${version.auto-value}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.google.auto.value</groupId>
|
||||
<artifactId>auto-value-annotations</artifactId>
|
||||
<version>1.8.2</version>
|
||||
<version>${version.auto-value}</version>
|
||||
</dependency>
|
||||
<!-- Specified as a workaround for
|
||||
https://github.com/mojohaus/versions-maven-plugin/issues/244. -->
|
||||
@@ -235,7 +241,7 @@
|
||||
<dependency>
|
||||
<groupId>com.google.guava</groupId>
|
||||
<artifactId>guava-bom</artifactId>
|
||||
<version>30.1.1-jre</version>
|
||||
<version>31.0-jre</version>
|
||||
<type>pom</type>
|
||||
<scope>import</scope>
|
||||
</dependency>
|
||||
@@ -324,7 +330,7 @@
|
||||
<dependency>
|
||||
<groupId>org.assertj</groupId>
|
||||
<artifactId>assertj-core</artifactId>
|
||||
<version>3.20.2</version>
|
||||
<version>3.21.0</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.checkerframework</groupId>
|
||||
@@ -339,7 +345,7 @@
|
||||
<dependency>
|
||||
<groupId>org.junit</groupId>
|
||||
<artifactId>junit-bom</artifactId>
|
||||
<version>5.8.0</version>
|
||||
<version>5.8.1</version>
|
||||
<type>pom</type>
|
||||
<scope>import</scope>
|
||||
</dependency>
|
||||
@@ -743,7 +749,7 @@
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-enforcer-plugin</artifactId>
|
||||
<version>3.0.0-M3</version>
|
||||
<version>3.0.0</version>
|
||||
<configuration>
|
||||
<fail>false</fail>
|
||||
<rules>
|
||||
@@ -780,7 +786,7 @@
|
||||
<dependency>
|
||||
<groupId>org.codehaus.mojo</groupId>
|
||||
<artifactId>extra-enforcer-rules</artifactId>
|
||||
<version>1.3</version>
|
||||
<version>1.4</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
<executions>
|
||||
|
||||
Reference in New Issue
Block a user