Use modern language features in tests
This commit is contained in:
@@ -89,8 +89,7 @@ abstract class AbstractHttpRequestFactoryTests extends AbstractMockWebServerTest
|
||||
final byte[] body = "Hello World".getBytes(StandardCharsets.UTF_8);
|
||||
request.getHeaders().setContentLength(body.length);
|
||||
|
||||
if (request instanceof StreamingHttpOutputMessage) {
|
||||
StreamingHttpOutputMessage streamingRequest = (StreamingHttpOutputMessage) request;
|
||||
if (request instanceof StreamingHttpOutputMessage streamingRequest) {
|
||||
streamingRequest.setBody(outputStream -> StreamUtils.copy(body, outputStream));
|
||||
}
|
||||
else {
|
||||
@@ -111,8 +110,7 @@ abstract class AbstractHttpRequestFactoryTests extends AbstractMockWebServerTest
|
||||
ClientHttpRequest request = factory.createRequest(new URI(baseUrl + "/echo"), HttpMethod.POST);
|
||||
|
||||
final byte[] body = "Hello World".getBytes(StandardCharsets.UTF_8);
|
||||
if (request instanceof StreamingHttpOutputMessage) {
|
||||
StreamingHttpOutputMessage streamingRequest = (StreamingHttpOutputMessage) request;
|
||||
if (request instanceof StreamingHttpOutputMessage streamingRequest) {
|
||||
streamingRequest.setBody(outputStream -> {
|
||||
StreamUtils.copy(body, outputStream);
|
||||
outputStream.flush();
|
||||
|
||||
@@ -289,8 +289,7 @@ public class Jaxb2XmlDecoderTests extends AbstractLeakCheckingTests {
|
||||
if (this == o) {
|
||||
return true;
|
||||
}
|
||||
if (o instanceof TypePojo) {
|
||||
TypePojo other = (TypePojo) o;
|
||||
if (o instanceof TypePojo other) {
|
||||
return this.foo.equals(other.foo) && this.bar.equals(other.bar);
|
||||
}
|
||||
return false;
|
||||
|
||||
@@ -207,7 +207,7 @@ public class GsonHttpMessageConverterTests {
|
||||
@Test
|
||||
@SuppressWarnings("unchecked")
|
||||
public void readAndWriteParameterizedType() throws Exception {
|
||||
ParameterizedTypeReference<List<MyBean>> beansList = new ParameterizedTypeReference<List<MyBean>>() {
|
||||
ParameterizedTypeReference<List<MyBean>> beansList = new ParameterizedTypeReference<>() {
|
||||
};
|
||||
|
||||
String body = "[{\"bytes\":[1,2],\"array\":[\"Foo\",\"Bar\"]," +
|
||||
@@ -234,8 +234,8 @@ public class GsonHttpMessageConverterTests {
|
||||
@Test
|
||||
@SuppressWarnings("unchecked")
|
||||
public void writeParameterizedBaseType() throws Exception {
|
||||
ParameterizedTypeReference<List<MyBean>> beansList = new ParameterizedTypeReference<List<MyBean>>() {};
|
||||
ParameterizedTypeReference<List<MyBase>> baseList = new ParameterizedTypeReference<List<MyBase>>() {};
|
||||
ParameterizedTypeReference<List<MyBean>> beansList = new ParameterizedTypeReference<>() {};
|
||||
ParameterizedTypeReference<List<MyBase>> baseList = new ParameterizedTypeReference<>() {};
|
||||
|
||||
String body = "[{\"bytes\":[1,2],\"array\":[\"Foo\",\"Bar\"]," +
|
||||
"\"number\":42,\"string\":\"Foo\",\"bool\":true,\"fraction\":42.0}]";
|
||||
|
||||
@@ -207,7 +207,7 @@ public class JsonbHttpMessageConverterTests {
|
||||
@Test
|
||||
@SuppressWarnings("unchecked")
|
||||
public void readAndWriteParameterizedType() throws Exception {
|
||||
ParameterizedTypeReference<List<MyBean>> beansList = new ParameterizedTypeReference<List<MyBean>>() {};
|
||||
ParameterizedTypeReference<List<MyBean>> beansList = new ParameterizedTypeReference<>() {};
|
||||
|
||||
String body = "[{\"bytes\":[1,2],\"array\":[\"Foo\",\"Bar\"]," +
|
||||
"\"number\":42,\"string\":\"Foo\",\"bool\":true,\"fraction\":42.0}]";
|
||||
@@ -233,8 +233,8 @@ public class JsonbHttpMessageConverterTests {
|
||||
@Test
|
||||
@SuppressWarnings("unchecked")
|
||||
public void writeParameterizedBaseType() throws Exception {
|
||||
ParameterizedTypeReference<List<MyBean>> beansList = new ParameterizedTypeReference<List<MyBean>>() {};
|
||||
ParameterizedTypeReference<List<MyBase>> baseList = new ParameterizedTypeReference<List<MyBase>>() {};
|
||||
ParameterizedTypeReference<List<MyBean>> beansList = new ParameterizedTypeReference<>() {};
|
||||
ParameterizedTypeReference<List<MyBase>> baseList = new ParameterizedTypeReference<>() {};
|
||||
|
||||
String body = "[{\"bytes\":[1,2],\"array\":[\"Foo\",\"Bar\"]," +
|
||||
"\"number\":42,\"string\":\"Foo\",\"bool\":true,\"fraction\":42.0}]";
|
||||
|
||||
@@ -281,7 +281,7 @@ public class MappingJackson2HttpMessageConverterTests {
|
||||
@Test
|
||||
@SuppressWarnings("unchecked")
|
||||
public void readAndWriteParameterizedType() throws Exception {
|
||||
ParameterizedTypeReference<List<MyBean>> beansList = new ParameterizedTypeReference<List<MyBean>>() {};
|
||||
ParameterizedTypeReference<List<MyBean>> beansList = new ParameterizedTypeReference<>() {};
|
||||
|
||||
String body = "[{" +
|
||||
"\"bytes\":\"AQI=\"," +
|
||||
@@ -312,8 +312,8 @@ public class MappingJackson2HttpMessageConverterTests {
|
||||
@Test
|
||||
@SuppressWarnings("unchecked")
|
||||
public void writeParameterizedBaseType() throws Exception {
|
||||
ParameterizedTypeReference<List<MyBean>> beansList = new ParameterizedTypeReference<List<MyBean>>() {};
|
||||
ParameterizedTypeReference<List<MyBase>> baseList = new ParameterizedTypeReference<List<MyBase>>() {};
|
||||
ParameterizedTypeReference<List<MyBean>> beansList = new ParameterizedTypeReference<>() {};
|
||||
ParameterizedTypeReference<List<MyBase>> baseList = new ParameterizedTypeReference<>() {};
|
||||
|
||||
String body = "[{" +
|
||||
"\"bytes\":\"AQI=\"," +
|
||||
@@ -468,7 +468,7 @@ public class MappingJackson2HttpMessageConverterTests {
|
||||
bar.setNumber(123);
|
||||
beans.add(bar);
|
||||
ParameterizedTypeReference<List<MyInterface>> typeReference =
|
||||
new ParameterizedTypeReference<List<MyInterface>>() {};
|
||||
new ParameterizedTypeReference<>() {};
|
||||
|
||||
this.converter.writeInternal(beans, typeReference.getType(), outputMessage);
|
||||
|
||||
|
||||
@@ -224,8 +224,7 @@ public class Jaxb2CollectionHttpMessageConverterTests {
|
||||
if (this == o) {
|
||||
return true;
|
||||
}
|
||||
if (o instanceof RootElement) {
|
||||
RootElement other = (RootElement) o;
|
||||
if (o instanceof RootElement other) {
|
||||
return this.type.equals(other.type);
|
||||
}
|
||||
return false;
|
||||
@@ -256,8 +255,7 @@ public class Jaxb2CollectionHttpMessageConverterTests {
|
||||
if (this == o) {
|
||||
return true;
|
||||
}
|
||||
if (o instanceof TestType) {
|
||||
TestType other = (TestType) o;
|
||||
if (o instanceof TestType other) {
|
||||
return this.s.equals(other.s);
|
||||
}
|
||||
return false;
|
||||
|
||||
@@ -140,7 +140,7 @@ public class ChannelSendOperatorTests {
|
||||
return Mono.never();
|
||||
});
|
||||
|
||||
BaseSubscriber<Void> subscriber = new BaseSubscriber<Void>() {};
|
||||
BaseSubscriber<Void> subscriber = new BaseSubscriber<>() {};
|
||||
operator.subscribe(subscriber);
|
||||
subscriber.cancel();
|
||||
|
||||
|
||||
@@ -153,7 +153,7 @@ class HttpMessageConverterExtractorTests {
|
||||
void generics() throws IOException {
|
||||
responseHeaders.setContentType(contentType);
|
||||
String expected = "Foo";
|
||||
ParameterizedTypeReference<List<String>> reference = new ParameterizedTypeReference<List<String>>() {};
|
||||
ParameterizedTypeReference<List<String>> reference = new ParameterizedTypeReference<>() {};
|
||||
Type type = reference.getType();
|
||||
|
||||
GenericHttpMessageConverter<String> converter = mock(GenericHttpMessageConverter.class);
|
||||
|
||||
@@ -115,8 +115,7 @@ class RestTemplateIntegrationTests extends AbstractMockWebServerTests {
|
||||
*/
|
||||
@RegisterExtension
|
||||
TestExecutionExceptionHandler serverErrorToAssertionErrorConverter = (context, throwable) -> {
|
||||
if (throwable instanceof HttpServerErrorException) {
|
||||
HttpServerErrorException ex = (HttpServerErrorException) throwable;
|
||||
if (throwable instanceof HttpServerErrorException ex) {
|
||||
String responseBody = ex.getResponseBodyAsString();
|
||||
String prefix = AssertionError.class.getName() + ": ";
|
||||
if (responseBody.startsWith(prefix)) {
|
||||
|
||||
@@ -646,7 +646,7 @@ class RestTemplateTests {
|
||||
void exchangeParameterizedType() throws Exception {
|
||||
GenericHttpMessageConverter converter = mock(GenericHttpMessageConverter.class);
|
||||
template.setMessageConverters(Collections.<HttpMessageConverter<?>>singletonList(converter));
|
||||
ParameterizedTypeReference<List<Integer>> intList = new ParameterizedTypeReference<List<Integer>>() {};
|
||||
ParameterizedTypeReference<List<Integer>> intList = new ParameterizedTypeReference<>() {};
|
||||
given(converter.canRead(intList.getType(), null, null)).willReturn(true);
|
||||
given(converter.getSupportedMediaTypes(any())).willReturn(Collections.singletonList(MediaType.TEXT_PLAIN));
|
||||
given(converter.canWrite(String.class, String.class, null)).willReturn(true);
|
||||
|
||||
Reference in New Issue
Block a user