mirror of
https://github.com/jlengrand/error-prone-support.git
synced 2026-03-10 08:11:25 +00:00
Compare commits
3 Commits
v0.18.0
...
nkooij/web
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
8b0a287d6d | ||
|
|
8dd587850b | ||
|
|
21592cea95 |
@@ -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>
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user