Use modern language features in tests

This commit is contained in:
Sam Brannen
2022-02-03 14:50:10 +01:00
parent 82a2544918
commit f8a5a8d7be
91 changed files with 577 additions and 1059 deletions

View File

@@ -319,9 +319,9 @@ public class MappingJackson2MessageConverterTests {
}
public interface MyJacksonView1 {};
public interface MyJacksonView1 {}
public interface MyJacksonView2 {};
public interface MyJacksonView2 {}
public static class JacksonViewBean {

View File

@@ -29,7 +29,6 @@ import org.springframework.messaging.MessageChannel;
import org.springframework.messaging.MessageDeliveryException;
import org.springframework.messaging.MessageHandler;
import org.springframework.messaging.MessageHeaders;
import org.springframework.messaging.MessagingException;
import org.springframework.messaging.StubMessageChannel;
import org.springframework.messaging.SubscribableChannel;
import org.springframework.messaging.support.ExecutorSubscribableChannel;
@@ -112,12 +111,9 @@ public class GenericMessagingTemplateTests {
@Test
public void sendAndReceive() {
SubscribableChannel channel = new ExecutorSubscribableChannel(this.executor);
channel.subscribe(new MessageHandler() {
@Override
public void handleMessage(Message<?> message) throws MessagingException {
MessageChannel replyChannel = (MessageChannel) message.getHeaders().getReplyChannel();
replyChannel.send(new GenericMessage<>("response"));
}
channel.subscribe(message -> {
MessageChannel replyChannel = (MessageChannel) message.getHeaders().getReplyChannel();
replyChannel.send(new GenericMessage<>("response"));
});
String actual = this.template.convertSendAndReceive(channel, "request", String.class);
@@ -126,7 +122,7 @@ public class GenericMessagingTemplateTests {
@Test
public void sendAndReceiveTimeout() throws InterruptedException {
final AtomicReference<Throwable> failure = new AtomicReference<Throwable>();
final AtomicReference<Throwable> failure = new AtomicReference<>();
final CountDownLatch latch = new CountDownLatch(1);
this.template.setReceiveTimeout(1);
@@ -152,7 +148,7 @@ public class GenericMessagingTemplateTests {
@Test
public void sendAndReceiveVariableTimeout() throws InterruptedException {
final AtomicReference<Throwable> failure = new AtomicReference<Throwable>();
final AtomicReference<Throwable> failure = new AtomicReference<>();
final CountDownLatch latch = new CountDownLatch(1);
this.template.setSendTimeout(20_000);
@@ -182,7 +178,7 @@ public class GenericMessagingTemplateTests {
@Test
public void sendAndReceiveVariableTimeoutCustomHeaders() throws InterruptedException {
final AtomicReference<Throwable> failure = new AtomicReference<Throwable>();
final AtomicReference<Throwable> failure = new AtomicReference<>();
final CountDownLatch latch = new CountDownLatch(1);
this.template.setSendTimeout(20_000);

View File

@@ -151,7 +151,7 @@ public class MessageMappingMessageHandlerTests {
}
private Message<?> message(String destination, String... content) {
Flux<DataBuffer> payload = Flux.fromIterable(Arrays.asList(content)).map(parts -> toDataBuffer(parts));
Flux<DataBuffer> payload = Flux.fromIterable(Arrays.asList(content)).map(this::toDataBuffer);
MessageHeaderAccessor headers = new MessageHeaderAccessor();
headers.setLeaveMutable(true);
headers.setHeader(DestinationPatternsMessageCondition.LOOKUP_DESTINATION_HEADER,

View File

@@ -28,7 +28,6 @@ import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.support.StaticListableBeanFactory;
import org.springframework.core.MethodParameter;
import org.springframework.core.convert.converter.Converter;
import org.springframework.core.convert.support.GenericConversionService;
import org.springframework.messaging.Message;
import org.springframework.messaging.converter.ByteArrayMessageConverter;
@@ -59,12 +58,7 @@ public class DefaultMessageHandlerMethodFactoryTests {
public void customConversion() throws Exception {
DefaultMessageHandlerMethodFactory instance = createInstance();
GenericConversionService conversionService = new GenericConversionService();
conversionService.addConverter(SampleBean.class, String.class, new Converter<SampleBean, String>() {
@Override
public String convert(SampleBean source) {
return "foo bar";
}
});
conversionService.addConverter(SampleBean.class, String.class, source -> "foo bar");
instance.setConversionService(conversionService);
instance.afterPropertiesSet();

View File

@@ -131,8 +131,7 @@ public class SimpAttributesContextHolderTests {
@Test
public void currentAttributesNone() {
assertThatIllegalStateException().isThrownBy(() ->
SimpAttributesContextHolder.currentAttributes())
assertThatIllegalStateException().isThrownBy(SimpAttributesContextHolder::currentAttributes)
.withMessageStartingWith("No thread-bound SimpAttributes found");
}

View File

@@ -224,8 +224,8 @@ public class SubscriptionMethodReturnValueHandlerTests {
}
private interface MyJacksonView1 {};
private interface MyJacksonView2 {};
private interface MyJacksonView1 {}
private interface MyJacksonView2 {}
private static class JacksonViewBean {

View File

@@ -19,7 +19,6 @@ package org.springframework.messaging.simp.stomp;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.concurrent.Callable;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
@@ -286,12 +285,7 @@ class StompBrokerRelayMessageHandlerTests {
private static ListenableFutureTask<Void> getVoidFuture() {
ListenableFutureTask<Void> futureTask = new ListenableFutureTask<>(new Callable<Void>() {
@Override
public Void call() {
return null;
}
});
ListenableFutureTask<Void> futureTask = new ListenableFutureTask<>(() -> null);
futureTask.run();
return futureTask;
}