diff --git a/spring-core/src/test/java/org/springframework/core/annotation/MissingMergedAnnotationTests.java b/spring-core/src/test/java/org/springframework/core/annotation/MissingMergedAnnotationTests.java index 383536912f3..244b75dbfcf 100644 --- a/spring-core/src/test/java/org/springframework/core/annotation/MissingMergedAnnotationTests.java +++ b/spring-core/src/test/java/org/springframework/core/annotation/MissingMergedAnnotationTests.java @@ -257,7 +257,7 @@ class MissingMergedAnnotationTests { @Test void synthesizeThrowsNoSuchElementException() { - assertThatNoSuchElementException().isThrownBy(() -> this.missing.synthesize()); + assertThatNoSuchElementException().isThrownBy(this.missing::synthesize); } @Test diff --git a/spring-core/src/test/java/org/springframework/core/convert/support/GenericConversionServiceTests.java b/spring-core/src/test/java/org/springframework/core/convert/support/GenericConversionServiceTests.java index 01c40274fd7..c1fc1117d7f 100644 --- a/spring-core/src/test/java/org/springframework/core/convert/support/GenericConversionServiceTests.java +++ b/spring-core/src/test/java/org/springframework/core/convert/support/GenericConversionServiceTests.java @@ -190,12 +190,7 @@ class GenericConversionServiceTests { @Test void convertSuperSourceType() { - conversionService.addConverter(new Converter() { - @Override - public Integer convert(CharSequence source) { - return Integer.valueOf(source.toString()); - } - }); + conversionService.addConverter(CharSequence.class, Integer.class, source -> Integer.valueOf(source.toString())); Integer result = conversionService.convert("3", Integer.class); assertThat((int) result).isEqualTo((int) Integer.valueOf(3)); } diff --git a/spring-core/src/test/java/org/springframework/core/convert/support/StreamConverterTests.java b/spring-core/src/test/java/org/springframework/core/convert/support/StreamConverterTests.java index 42f4041ca9a..a7bee74e5a2 100644 --- a/spring-core/src/test/java/org/springframework/core/convert/support/StreamConverterTests.java +++ b/spring-core/src/test/java/org/springframework/core/convert/support/StreamConverterTests.java @@ -26,7 +26,6 @@ import org.junit.jupiter.api.Test; import org.springframework.core.convert.ConversionFailedException; import org.springframework.core.convert.ConverterNotFoundException; import org.springframework.core.convert.TypeDescriptor; -import org.springframework.core.convert.converter.Converter; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThatExceptionOfType; @@ -134,12 +133,7 @@ class StreamConverterTests { @SuppressWarnings("resource") void convertFromArrayToStream() throws NoSuchFieldException { Integer[] stream = new Integer[] {1, 0, 1}; - this.conversionService.addConverter(new Converter() { - @Override - public Boolean convert(Integer source) { - return source == 1; - } - }); + this.conversionService.addConverter(Integer.class, Boolean.class, source -> source == 1); TypeDescriptor streamOfBoolean = new TypeDescriptor(Types.class.getField("streamOfBooleans")); Object result = this.conversionService.convert(stream, streamOfBoolean); diff --git a/spring-core/src/test/java/org/springframework/core/env/ProfilesTests.java b/spring-core/src/test/java/org/springframework/core/env/ProfilesTests.java index 3e399697992..dfffcf64c4f 100644 --- a/spring-core/src/test/java/org/springframework/core/env/ProfilesTests.java +++ b/spring-core/src/test/java/org/springframework/core/env/ProfilesTests.java @@ -47,8 +47,7 @@ class ProfilesTests { @Test void ofWhenEmptyThrowsException() { - assertThatIllegalArgumentException().isThrownBy(() -> - Profiles.of()) + assertThatIllegalArgumentException().isThrownBy(Profiles::of) .withMessageContaining("Must specify at least one profile"); } diff --git a/spring-core/src/test/java/org/springframework/core/env/StandardEnvironmentTests.java b/spring-core/src/test/java/org/springframework/core/env/StandardEnvironmentTests.java index acd6d84acab..745321416f4 100644 --- a/spring-core/src/test/java/org/springframework/core/env/StandardEnvironmentTests.java +++ b/spring-core/src/test/java/org/springframework/core/env/StandardEnvironmentTests.java @@ -212,7 +212,7 @@ public class StandardEnvironmentTests { void defaultProfileWithCircularPlaceholder() { try { System.setProperty(DEFAULT_PROFILES_PROPERTY_NAME, "${spring.profiles.default}"); - assertThatIllegalArgumentException().isThrownBy(() -> environment.getDefaultProfiles()); + assertThatIllegalArgumentException().isThrownBy(environment::getDefaultProfiles); } finally { System.clearProperty(DEFAULT_PROFILES_PROPERTY_NAME); diff --git a/spring-core/src/test/java/org/springframework/core/io/buffer/DataBufferUtilsTests.java b/spring-core/src/test/java/org/springframework/core/io/buffer/DataBufferUtilsTests.java index ba85a1575bc..1f9a22abd37 100644 --- a/spring-core/src/test/java/org/springframework/core/io/buffer/DataBufferUtilsTests.java +++ b/spring-core/src/test/java/org/springframework/core/io/buffer/DataBufferUtilsTests.java @@ -80,7 +80,7 @@ class DataBufferUtilsTests extends AbstractDataBufferAllocatingTests { super.bufferFactory = bufferFactory; Flux flux = DataBufferUtils.readInputStream( - () -> this.resource.getInputStream(), super.bufferFactory, 3); + this.resource::getInputStream, super.bufferFactory, 3); verifyReadData(flux); } diff --git a/spring-core/src/test/java/org/springframework/core/task/SimpleAsyncTaskExecutorTests.java b/spring-core/src/test/java/org/springframework/core/task/SimpleAsyncTaskExecutorTests.java index c78f9a95f56..3aea9fbadf7 100644 --- a/spring-core/src/test/java/org/springframework/core/task/SimpleAsyncTaskExecutorTests.java +++ b/spring-core/src/test/java/org/springframework/core/task/SimpleAsyncTaskExecutorTests.java @@ -16,8 +16,6 @@ package org.springframework.core.task; -import java.util.concurrent.ThreadFactory; - import org.junit.jupiter.api.Test; import org.springframework.util.ConcurrencyThrottleSupport; @@ -61,12 +59,7 @@ class SimpleAsyncTaskExecutorTests { @Test void threadFactoryOverridesDefaults() throws Exception { final Object monitor = new Object(); - SimpleAsyncTaskExecutor executor = new SimpleAsyncTaskExecutor(new ThreadFactory() { - @Override - public Thread newThread(Runnable r) { - return new Thread(r, "test"); - } - }); + SimpleAsyncTaskExecutor executor = new SimpleAsyncTaskExecutor(runnable -> new Thread(runnable, "test")); ThreadNameHarvester task = new ThreadNameHarvester(monitor); executeAndWait(executor, task, monitor); assertThat(task.getThreadName()).isEqualTo("test"); diff --git a/spring-core/src/test/java/org/springframework/util/concurrent/SettableListenableFutureTests.java b/spring-core/src/test/java/org/springframework/util/concurrent/SettableListenableFutureTests.java index a14ecf5f4e9..e5b837f61a7 100644 --- a/spring-core/src/test/java/org/springframework/util/concurrent/SettableListenableFutureTests.java +++ b/spring-core/src/test/java/org/springframework/util/concurrent/SettableListenableFutureTests.java @@ -332,8 +332,7 @@ class SettableListenableFutureTests { void cancelStateThrowsExceptionWhenCallingGet() throws ExecutionException, InterruptedException { settableListenableFuture.cancel(true); - assertThatExceptionOfType(CancellationException.class).isThrownBy(() -> - settableListenableFuture.get()); + assertThatExceptionOfType(CancellationException.class).isThrownBy(settableListenableFuture::get); assertThat(settableListenableFuture.isCancelled()).isTrue(); assertThat(settableListenableFuture.isDone()).isTrue(); diff --git a/spring-core/src/test/java/org/springframework/util/xml/AbstractStaxXMLReaderTests.java b/spring-core/src/test/java/org/springframework/util/xml/AbstractStaxXMLReaderTests.java index 317a88b9eb8..454b8629063 100644 --- a/spring-core/src/test/java/org/springframework/util/xml/AbstractStaxXMLReaderTests.java +++ b/spring-core/src/test/java/org/springframework/util/xml/AbstractStaxXMLReaderTests.java @@ -179,12 +179,9 @@ abstract class AbstractStaxXMLReaderTests { ContentHandler contentHandler = mock(ContentHandler.class); willAnswer(new CopyCharsAnswer()).given(contentHandler).characters(any(char[].class), anyInt(), anyInt()); willAnswer(new CopyCharsAnswer()).given(contentHandler).ignorableWhitespace(any(char[].class), anyInt(), anyInt()); - willAnswer(new Answer() { - @Override - public Object answer(InvocationOnMock invocation) throws Throwable { - invocation.getArguments()[3] = new AttributesImpl((Attributes) invocation.getArguments()[3]); - return null; - } + willAnswer(invocation -> { + invocation.getArguments()[3] = new AttributesImpl((Attributes) invocation.getArguments()[3]); + return null; }).given(contentHandler).startElement(anyString(), anyString(), anyString(), any(Attributes.class)); return contentHandler; }