Refactor tests to use lambda expressions & method references
Closes gh-27386
This commit is contained in:
parent
51d263bd06
commit
23ab9ca8ca
|
|
@ -257,7 +257,7 @@ class MissingMergedAnnotationTests {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void synthesizeThrowsNoSuchElementException() {
|
void synthesizeThrowsNoSuchElementException() {
|
||||||
assertThatNoSuchElementException().isThrownBy(() -> this.missing.synthesize());
|
assertThatNoSuchElementException().isThrownBy(this.missing::synthesize);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|
|
||||||
|
|
@ -190,12 +190,7 @@ class GenericConversionServiceTests {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void convertSuperSourceType() {
|
void convertSuperSourceType() {
|
||||||
conversionService.addConverter(new Converter<CharSequence, Integer>() {
|
conversionService.addConverter(CharSequence.class, Integer.class, source -> Integer.valueOf(source.toString()));
|
||||||
@Override
|
|
||||||
public Integer convert(CharSequence source) {
|
|
||||||
return Integer.valueOf(source.toString());
|
|
||||||
}
|
|
||||||
});
|
|
||||||
Integer result = conversionService.convert("3", Integer.class);
|
Integer result = conversionService.convert("3", Integer.class);
|
||||||
assertThat((int) result).isEqualTo((int) Integer.valueOf(3));
|
assertThat((int) result).isEqualTo((int) Integer.valueOf(3));
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -26,7 +26,6 @@ import org.junit.jupiter.api.Test;
|
||||||
import org.springframework.core.convert.ConversionFailedException;
|
import org.springframework.core.convert.ConversionFailedException;
|
||||||
import org.springframework.core.convert.ConverterNotFoundException;
|
import org.springframework.core.convert.ConverterNotFoundException;
|
||||||
import org.springframework.core.convert.TypeDescriptor;
|
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.assertThat;
|
||||||
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
|
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
|
||||||
|
|
@ -134,12 +133,7 @@ class StreamConverterTests {
|
||||||
@SuppressWarnings("resource")
|
@SuppressWarnings("resource")
|
||||||
void convertFromArrayToStream() throws NoSuchFieldException {
|
void convertFromArrayToStream() throws NoSuchFieldException {
|
||||||
Integer[] stream = new Integer[] {1, 0, 1};
|
Integer[] stream = new Integer[] {1, 0, 1};
|
||||||
this.conversionService.addConverter(new Converter<Integer, Boolean>() {
|
this.conversionService.addConverter(Integer.class, Boolean.class, source -> source == 1);
|
||||||
@Override
|
|
||||||
public Boolean convert(Integer source) {
|
|
||||||
return source == 1;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
TypeDescriptor streamOfBoolean = new TypeDescriptor(Types.class.getField("streamOfBooleans"));
|
TypeDescriptor streamOfBoolean = new TypeDescriptor(Types.class.getField("streamOfBooleans"));
|
||||||
Object result = this.conversionService.convert(stream, streamOfBoolean);
|
Object result = this.conversionService.convert(stream, streamOfBoolean);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -47,8 +47,7 @@ class ProfilesTests {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void ofWhenEmptyThrowsException() {
|
void ofWhenEmptyThrowsException() {
|
||||||
assertThatIllegalArgumentException().isThrownBy(() ->
|
assertThatIllegalArgumentException().isThrownBy(Profiles::of)
|
||||||
Profiles.of())
|
|
||||||
.withMessageContaining("Must specify at least one profile");
|
.withMessageContaining("Must specify at least one profile");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -212,7 +212,7 @@ public class StandardEnvironmentTests {
|
||||||
void defaultProfileWithCircularPlaceholder() {
|
void defaultProfileWithCircularPlaceholder() {
|
||||||
try {
|
try {
|
||||||
System.setProperty(DEFAULT_PROFILES_PROPERTY_NAME, "${spring.profiles.default}");
|
System.setProperty(DEFAULT_PROFILES_PROPERTY_NAME, "${spring.profiles.default}");
|
||||||
assertThatIllegalArgumentException().isThrownBy(() -> environment.getDefaultProfiles());
|
assertThatIllegalArgumentException().isThrownBy(environment::getDefaultProfiles);
|
||||||
}
|
}
|
||||||
finally {
|
finally {
|
||||||
System.clearProperty(DEFAULT_PROFILES_PROPERTY_NAME);
|
System.clearProperty(DEFAULT_PROFILES_PROPERTY_NAME);
|
||||||
|
|
|
||||||
|
|
@ -80,7 +80,7 @@ class DataBufferUtilsTests extends AbstractDataBufferAllocatingTests {
|
||||||
super.bufferFactory = bufferFactory;
|
super.bufferFactory = bufferFactory;
|
||||||
|
|
||||||
Flux<DataBuffer> flux = DataBufferUtils.readInputStream(
|
Flux<DataBuffer> flux = DataBufferUtils.readInputStream(
|
||||||
() -> this.resource.getInputStream(), super.bufferFactory, 3);
|
this.resource::getInputStream, super.bufferFactory, 3);
|
||||||
|
|
||||||
verifyReadData(flux);
|
verifyReadData(flux);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -16,8 +16,6 @@
|
||||||
|
|
||||||
package org.springframework.core.task;
|
package org.springframework.core.task;
|
||||||
|
|
||||||
import java.util.concurrent.ThreadFactory;
|
|
||||||
|
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
import org.springframework.util.ConcurrencyThrottleSupport;
|
import org.springframework.util.ConcurrencyThrottleSupport;
|
||||||
|
|
@ -61,12 +59,7 @@ class SimpleAsyncTaskExecutorTests {
|
||||||
@Test
|
@Test
|
||||||
void threadFactoryOverridesDefaults() throws Exception {
|
void threadFactoryOverridesDefaults() throws Exception {
|
||||||
final Object monitor = new Object();
|
final Object monitor = new Object();
|
||||||
SimpleAsyncTaskExecutor executor = new SimpleAsyncTaskExecutor(new ThreadFactory() {
|
SimpleAsyncTaskExecutor executor = new SimpleAsyncTaskExecutor(runnable -> new Thread(runnable, "test"));
|
||||||
@Override
|
|
||||||
public Thread newThread(Runnable r) {
|
|
||||||
return new Thread(r, "test");
|
|
||||||
}
|
|
||||||
});
|
|
||||||
ThreadNameHarvester task = new ThreadNameHarvester(monitor);
|
ThreadNameHarvester task = new ThreadNameHarvester(monitor);
|
||||||
executeAndWait(executor, task, monitor);
|
executeAndWait(executor, task, monitor);
|
||||||
assertThat(task.getThreadName()).isEqualTo("test");
|
assertThat(task.getThreadName()).isEqualTo("test");
|
||||||
|
|
|
||||||
|
|
@ -332,8 +332,7 @@ class SettableListenableFutureTests {
|
||||||
void cancelStateThrowsExceptionWhenCallingGet() throws ExecutionException, InterruptedException {
|
void cancelStateThrowsExceptionWhenCallingGet() throws ExecutionException, InterruptedException {
|
||||||
settableListenableFuture.cancel(true);
|
settableListenableFuture.cancel(true);
|
||||||
|
|
||||||
assertThatExceptionOfType(CancellationException.class).isThrownBy(() ->
|
assertThatExceptionOfType(CancellationException.class).isThrownBy(settableListenableFuture::get);
|
||||||
settableListenableFuture.get());
|
|
||||||
|
|
||||||
assertThat(settableListenableFuture.isCancelled()).isTrue();
|
assertThat(settableListenableFuture.isCancelled()).isTrue();
|
||||||
assertThat(settableListenableFuture.isDone()).isTrue();
|
assertThat(settableListenableFuture.isDone()).isTrue();
|
||||||
|
|
|
||||||
|
|
@ -179,12 +179,9 @@ abstract class AbstractStaxXMLReaderTests {
|
||||||
ContentHandler contentHandler = mock(ContentHandler.class);
|
ContentHandler contentHandler = mock(ContentHandler.class);
|
||||||
willAnswer(new CopyCharsAnswer()).given(contentHandler).characters(any(char[].class), anyInt(), anyInt());
|
willAnswer(new CopyCharsAnswer()).given(contentHandler).characters(any(char[].class), anyInt(), anyInt());
|
||||||
willAnswer(new CopyCharsAnswer()).given(contentHandler).ignorableWhitespace(any(char[].class), anyInt(), anyInt());
|
willAnswer(new CopyCharsAnswer()).given(contentHandler).ignorableWhitespace(any(char[].class), anyInt(), anyInt());
|
||||||
willAnswer(new Answer<Object>() {
|
willAnswer(invocation -> {
|
||||||
@Override
|
invocation.getArguments()[3] = new AttributesImpl((Attributes) invocation.getArguments()[3]);
|
||||||
public Object answer(InvocationOnMock invocation) throws Throwable {
|
return null;
|
||||||
invocation.getArguments()[3] = new AttributesImpl((Attributes) invocation.getArguments()[3]);
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}).given(contentHandler).startElement(anyString(), anyString(), anyString(), any(Attributes.class));
|
}).given(contentHandler).startElement(anyString(), anyString(), anyString(), any(Attributes.class));
|
||||||
return contentHandler;
|
return contentHandler;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue