Use modern language features in tests

This commit is contained in:
Sam Brannen
2022-02-03 15:35:32 +01:00
parent 32cd73261a
commit b3f786728e
58 changed files with 117 additions and 151 deletions

View File

@@ -202,7 +202,7 @@ public class DefaultClientRequestBuilderTests {
public void bodyParameterizedTypeReference() {
String body = "foo";
Publisher<String> publisher = Mono.just(body);
ParameterizedTypeReference<String> typeReference = new ParameterizedTypeReference<String>() {};
ParameterizedTypeReference<String> typeReference = new ParameterizedTypeReference<>() {};
ClientRequest result = ClientRequest.create(POST, DEFAULT_URL).body(publisher, typeReference).build();
List<HttpMessageWriter<?>> messageWriters = new ArrayList<>();

View File

@@ -111,7 +111,7 @@ public class ClientResponseWrapperTests {
@Test
public void bodyToMonoParameterizedTypeReference() {
Mono<String> result = Mono.just("foo");
ParameterizedTypeReference<String> reference = new ParameterizedTypeReference<String>() {};
ParameterizedTypeReference<String> reference = new ParameterizedTypeReference<>() {};
given(mockResponse.bodyToMono(reference)).willReturn(result);
assertThat(wrapper.bodyToMono(reference)).isSameAs(result);
@@ -128,7 +128,7 @@ public class ClientResponseWrapperTests {
@Test
public void bodyToFluxParameterizedTypeReference() {
Flux<String> result = Flux.just("foo");
ParameterizedTypeReference<String> reference = new ParameterizedTypeReference<String>() {};
ParameterizedTypeReference<String> reference = new ParameterizedTypeReference<>() {};
given(mockResponse.bodyToFlux(reference)).willReturn(result);
assertThat(wrapper.bodyToFlux(reference)).isSameAs(result);
@@ -145,7 +145,7 @@ public class ClientResponseWrapperTests {
@Test
public void toEntityParameterizedTypeReference() {
Mono<ResponseEntity<String>> result = Mono.just(new ResponseEntity<>("foo", HttpStatus.OK));
ParameterizedTypeReference<String> reference = new ParameterizedTypeReference<String>() {};
ParameterizedTypeReference<String> reference = new ParameterizedTypeReference<>() {};
given(mockResponse.toEntity(reference)).willReturn(result);
assertThat(wrapper.toEntity(reference)).isSameAs(result);
@@ -162,7 +162,7 @@ public class ClientResponseWrapperTests {
@Test
public void toEntityListParameterizedTypeReference() {
Mono<ResponseEntity<List<String>>> result = Mono.just(new ResponseEntity<>(singletonList("foo"), HttpStatus.OK));
ParameterizedTypeReference<String> reference = new ParameterizedTypeReference<String>() {};
ParameterizedTypeReference<String> reference = new ParameterizedTypeReference<>() {};
given(mockResponse.toEntityList(reference)).willReturn(result);
assertThat(wrapper.toEntityList(reference)).isSameAs(result);

View File

@@ -71,7 +71,7 @@ public class DefaultEntityResponseBuilderTests {
@Test
public void fromPublisher() {
Flux<String> body = Flux.just("foo", "bar");
ParameterizedTypeReference<String> typeReference = new ParameterizedTypeReference<String>() {};
ParameterizedTypeReference<String> typeReference = new ParameterizedTypeReference<>() {};
EntityResponse<Flux<String>> response = EntityResponse.fromPublisher(body, typeReference).build().block();
assertThat(response.entity()).isSameAs(body);
}
@@ -79,7 +79,7 @@ public class DefaultEntityResponseBuilderTests {
@Test
public void fromProducer() {
Single<String> body = Single.just("foo");
ParameterizedTypeReference<String> typeReference = new ParameterizedTypeReference<String>() {};
ParameterizedTypeReference<String> typeReference = new ParameterizedTypeReference<>() {};
EntityResponse<Single<String>> response = EntityResponse.fromProducer(body, typeReference).build().block();
assertThat(response.entity()).isSameAs(body);
}

View File

@@ -288,7 +288,7 @@ public class DefaultServerRequestTests {
.body(body);
DefaultServerRequest request = new DefaultServerRequest(MockServerWebExchange.from(mockRequest), messageReaders);
ParameterizedTypeReference<String> typeReference = new ParameterizedTypeReference<String>() {};
ParameterizedTypeReference<String> typeReference = new ParameterizedTypeReference<>() {};
Mono<String> resultMono = request.bodyToMono(typeReference);
assertThat(resultMono.block()).isEqualTo("foo");
}
@@ -346,7 +346,7 @@ public class DefaultServerRequestTests {
.body(body);
DefaultServerRequest request = new DefaultServerRequest(MockServerWebExchange.from(mockRequest), messageReaders);
ParameterizedTypeReference<String> typeReference = new ParameterizedTypeReference<String>() {};
ParameterizedTypeReference<String> typeReference = new ParameterizedTypeReference<>() {};
Flux<String> resultFlux = request.bodyToFlux(typeReference);
assertThat(resultFlux.collectList().block()).isEqualTo(Collections.singletonList("foo"));
}

View File

@@ -88,7 +88,7 @@ class DispatcherHandlerIntegrationTests extends AbstractHttpHandlerIntegrationTe
void flux(HttpServer httpServer) throws Exception {
startServer(httpServer);
ParameterizedTypeReference<List<Person>> reference = new ParameterizedTypeReference<List<Person>>() {};
ParameterizedTypeReference<List<Person>> reference = new ParameterizedTypeReference<>() {};
ResponseEntity<List<Person>> result =
this.restTemplate
.exchange("http://localhost:" + this.port + "/flux", HttpMethod.GET, null, reference);

View File

@@ -69,7 +69,7 @@ class PublisherHandlerFunctionIntegrationTests extends AbstractRouterFunctionInt
void flux(HttpServer httpServer) throws Exception {
startServer(httpServer);
ParameterizedTypeReference<List<Person>> reference = new ParameterizedTypeReference<List<Person>>() {};
ParameterizedTypeReference<List<Person>> reference = new ParameterizedTypeReference<>() {};
ResponseEntity<List<Person>> result =
restTemplate.exchange("http://localhost:" + super.port + "/flux", HttpMethod.GET, null, reference);

View File

@@ -159,7 +159,7 @@ public class ServerRequestWrapperTests {
@Test
public void bodyToMonoParameterizedTypeReference() {
Mono<String> result = Mono.just("foo");
ParameterizedTypeReference<String> reference = new ParameterizedTypeReference<String>() {};
ParameterizedTypeReference<String> reference = new ParameterizedTypeReference<>() {};
given(mockRequest.bodyToMono(reference)).willReturn(result);
assertThat(wrapper.bodyToMono(reference)).isSameAs(result);
@@ -176,7 +176,7 @@ public class ServerRequestWrapperTests {
@Test
public void bodyToFluxParameterizedTypeReference() {
Flux<String> result = Flux.just("foo");
ParameterizedTypeReference<String> reference = new ParameterizedTypeReference<String>() {};
ParameterizedTypeReference<String> reference = new ParameterizedTypeReference<>() {};
given(mockRequest.bodyToFlux(reference)).willReturn(result);
assertThat(wrapper.bodyToFlux(reference)).isSameAs(result);

View File

@@ -353,8 +353,7 @@ public class MessageReaderArgumentResolverTests {
if (this == o) {
return true;
}
if (o instanceof TestBean) {
TestBean other = (TestBean) o;
if (o instanceof TestBean other) {
return this.foo.equals(other.foo) && this.bar.equals(other.bar);
}
return false;

View File

@@ -71,7 +71,7 @@ import static org.springframework.http.MediaType.APPLICATION_XML;
public class RequestMappingMessageConversionIntegrationTests extends AbstractRequestMappingIntegrationTests {
private static final ParameterizedTypeReference<List<Person>> PERSON_LIST =
new ParameterizedTypeReference<List<Person>>() {};
new ParameterizedTypeReference<>() {};
private static final MediaType JSON = MediaType.APPLICATION_JSON;