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

@@ -200,12 +200,9 @@ class JmsTemplateTests {
JmsTemplate template = createTemplate();
template.setConnectionFactory(this.connectionFactory);
template.execute(new SessionCallback<Void>() {
@Override
public Void doInJms(Session session) throws JMSException {
session.getTransacted();
return null;
}
template.execute((SessionCallback<Void>) session -> {
session.getTransacted();
return null;
});
verify(this.session).close();
@@ -220,19 +217,13 @@ class JmsTemplateTests {
TransactionSynchronizationManager.initSynchronization();
try {
template.execute(new SessionCallback<Void>() {
@Override
public Void doInJms(Session session) throws JMSException {
session.getTransacted();
return null;
}
template.execute((SessionCallback<Void>) session -> {
session.getTransacted();
return null;
});
template.execute(new SessionCallback<Void>() {
@Override
public Void doInJms(Session session) throws JMSException {
session.getTransacted();
return null;
}
template.execute((SessionCallback<Void>) session -> {
session.getTransacted();
return null;
});
assertThat(ConnectionFactoryUtils.getTransactionalSession(scf, null, false)).isSameAs(this.session);
@@ -374,29 +365,14 @@ class JmsTemplateTests {
}
if (useDefaultDestination) {
template.send(new MessageCreator() {
@Override
public Message createMessage(Session session) throws JMSException {
return session.createTextMessage("just testing");
}
});
template.send(session -> session.createTextMessage("just testing"));
}
else {
if (explicitDestination) {
template.send(this.queue, new MessageCreator() {
@Override
public Message createMessage(Session session) throws JMSException {
return session.createTextMessage("just testing");
}
});
template.send(this.queue, (MessageCreator) session -> session.createTextMessage("just testing"));
}
else {
template.send(destinationName, new MessageCreator() {
@Override
public Message createMessage(Session session) throws JMSException {
return session.createTextMessage("just testing");
}
});
template.send(destinationName, (MessageCreator) session -> session.createTextMessage("just testing"));
}
}

View File

@@ -31,7 +31,6 @@ import javax.jms.Session;
import org.junit.jupiter.api.Test;
import org.springframework.context.support.GenericApplicationContext;
import org.springframework.core.task.TaskExecutor;
import org.springframework.jms.StubQueue;
import org.springframework.lang.Nullable;
import org.springframework.util.ErrorHandler;
@@ -183,16 +182,13 @@ public class SimpleMessageListenerContainerTests {
this.container.setConnectionFactory(connectionFactory);
this.container.setDestinationName(DESTINATION_NAME);
this.container.setMessageListener(new SessionAwareMessageListener<Message>() {
@Override
public void onMessage(Message message, @Nullable Session sess) {
try {
// Check correct Session passed into SessionAwareMessageListener.
assertThat(session).isSameAs(sess);
}
catch (Throwable ex) {
failure.add("MessageListener execution failed: " + ex);
}
this.container.setMessageListener((SessionAwareMessageListener<Message>) (Message message, @Nullable Session sess) -> {
try {
// Check correct Session passed into SessionAwareMessageListener.
assertThat(session).isSameAs(sess);
}
catch (Throwable ex) {
failure.add("MessageListener execution failed: " + ex);
}
});
@@ -232,14 +228,11 @@ public class SimpleMessageListenerContainerTests {
this.container.setConnectionFactory(connectionFactory);
this.container.setDestinationName(DESTINATION_NAME);
this.container.setMessageListener(listener);
this.container.setTaskExecutor(new TaskExecutor() {
@Override
public void execute(Runnable task) {
listener.executorInvoked = true;
assertThat(listener.listenerInvoked).isFalse();
task.run();
assertThat(listener.listenerInvoked).isTrue();
}
this.container.setTaskExecutor(task -> {
listener.executorInvoked = true;
assertThat(listener.listenerInvoked).isFalse();
task.run();
assertThat(listener.listenerInvoked).isTrue();
});
this.container.afterPropertiesSet();
this.container.start();
@@ -279,11 +272,8 @@ public class SimpleMessageListenerContainerTests {
this.container.setConnectionFactory(connectionFactory);
this.container.setDestinationName(DESTINATION_NAME);
this.container.setMessageListener(new SessionAwareMessageListener<Message>() {
@Override
public void onMessage(Message message, @Nullable Session session) throws JMSException {
throw theException;
}
this.container.setMessageListener((SessionAwareMessageListener<Message>) (Message message, @Nullable Session session1) -> {
throw theException;
});
ExceptionListener exceptionListener = mock(ExceptionListener.class);
@@ -329,11 +319,8 @@ public class SimpleMessageListenerContainerTests {
this.container.setConnectionFactory(connectionFactory);
this.container.setDestinationName(DESTINATION_NAME);
this.container.setMessageListener(new SessionAwareMessageListener<Message>() {
@Override
public void onMessage(Message message, @Nullable Session session) throws JMSException {
throw theException;
}
this.container.setMessageListener((SessionAwareMessageListener<Message>) (Message message, @Nullable Session session1) -> {
throw theException;
});
ErrorHandler errorHandler = mock(ErrorHandler.class);
@@ -375,11 +362,8 @@ public class SimpleMessageListenerContainerTests {
this.container.setConnectionFactory(connectionFactory);
this.container.setDestinationName(DESTINATION_NAME);
this.container.setMessageListener(new MessageListener() {
@Override
public void onMessage(Message message) {
throw new UnsupportedOperationException();
}
this.container.setMessageListener((MessageListener) message -> {
throw new UnsupportedOperationException();
});
this.container.afterPropertiesSet();
this.container.start();
@@ -419,11 +403,8 @@ public class SimpleMessageListenerContainerTests {
this.container.setConnectionFactory(connectionFactory);
this.container.setDestinationName(DESTINATION_NAME);
this.container.setMessageListener(new MessageListener() {
@Override
public void onMessage(Message message) {
throw new UnsupportedOperationException();
}
this.container.setMessageListener((MessageListener) message -> {
throw new UnsupportedOperationException();
});
this.container.afterPropertiesSet();
this.container.start();

View File

@@ -432,8 +432,8 @@ public class MessagingMessageListenerAdapterTests {
}
}
interface Summary {};
interface Full extends Summary {};
interface Summary {}
interface Full extends Summary {}
@SuppressWarnings("unused")
private static class SampleResponse {

View File

@@ -30,8 +30,6 @@ import javax.jms.Session;
import javax.jms.TextMessage;
import org.junit.jupiter.api.Test;
import org.mockito.invocation.InvocationOnMock;
import org.mockito.stubbing.Answer;
import org.springframework.jms.support.converter.MessageConversionException;
import org.springframework.jms.support.converter.SimpleMessageConverter;
@@ -77,12 +75,7 @@ public class SimpleMessageConverterTests {
given(session.createBytesMessage()).willReturn(message);
given(message.getBodyLength()).willReturn((long) content.length);
given(message.readBytes(any(byte[].class))).willAnswer(new Answer<Integer>() {
@Override
public Integer answer(InvocationOnMock invocation) throws Throwable {
return byteArrayInputStream.read((byte[]) invocation.getArguments()[0]);
}
});
given(message.readBytes(any(byte[].class))).willAnswer(invocation -> byteArrayInputStream.read((byte[]) invocation.getArguments()[0]));
SimpleMessageConverter converter = new SimpleMessageConverter();
Message msg = converter.toMessage(content, session);

View File

@@ -300,9 +300,9 @@ class MappingJackson2MessageConverterTests {
}
private interface Summary {};
private interface Summary {}
private interface Full extends Summary {};
private interface Full extends Summary {}
@SuppressWarnings("unused")