Skip to content

Commit 5d508de

Browse files
committed
Merge branch '5.3.x'
2 parents ab88ff3 + d68bb4e commit 5d508de

File tree

9 files changed

+44
-93
lines changed

9 files changed

+44
-93
lines changed

spring-core/src/test/java/org/springframework/core/annotation/MissingMergedAnnotationTests.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2019 the original author or authors.
2+
* Copyright 2002-2021 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -257,7 +257,7 @@ void getDefaultValueReturnsEmpty() {
257257

258258
@Test
259259
void synthesizeThrowsNoSuchElementException() {
260-
assertThatNoSuchElementException().isThrownBy(() -> this.missing.synthesize());
260+
assertThatNoSuchElementException().isThrownBy(this.missing::synthesize);
261261
}
262262

263263
@Test

spring-core/src/test/java/org/springframework/core/convert/support/GenericConversionServiceTests.java

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2019 the original author or authors.
2+
* Copyright 2002-2021 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -190,12 +190,7 @@ void convertWrongTypeArgument() {
190190

191191
@Test
192192
void convertSuperSourceType() {
193-
conversionService.addConverter(new Converter<CharSequence, Integer>() {
194-
@Override
195-
public Integer convert(CharSequence source) {
196-
return Integer.valueOf(source.toString());
197-
}
198-
});
193+
conversionService.addConverter(CharSequence.class, Integer.class, source -> Integer.valueOf(source.toString()));
199194
Integer result = conversionService.convert("3", Integer.class);
200195
assertThat((int) result).isEqualTo((int) Integer.valueOf(3));
201196
}

spring-core/src/test/java/org/springframework/core/convert/support/StreamConverterTests.java

Lines changed: 24 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2019 the original author or authors.
2+
* Copyright 2002-2022 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -26,16 +26,18 @@
2626
import org.springframework.core.convert.ConversionFailedException;
2727
import org.springframework.core.convert.ConverterNotFoundException;
2828
import org.springframework.core.convert.TypeDescriptor;
29-
import org.springframework.core.convert.converter.Converter;
3029

3130
import static org.assertj.core.api.Assertions.assertThat;
3231
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
3332
import static org.assertj.core.api.Assertions.assertThatIllegalStateException;
33+
import static org.assertj.core.api.InstanceOfAssertFactories.list;
34+
import static org.assertj.core.api.InstanceOfAssertFactories.stream;
3435

3536
/**
3637
* Tests for {@link StreamConverter}.
3738
*
3839
* @author Stephane Nicoll
40+
* @author Sam Brannen
3941
* @since 4.2
4042
*/
4143
class StreamConverterTests {
@@ -57,74 +59,53 @@ void setup() {
5759
@Test
5860
void convertFromStreamToList() throws NoSuchFieldException {
5961
this.conversionService.addConverter(Number.class, String.class, new ObjectToStringConverter());
60-
Stream<Integer> stream = Arrays.asList(1, 2, 3).stream();
62+
Stream<Integer> stream = Stream.of(1, 2, 3);
6163
TypeDescriptor listOfStrings = new TypeDescriptor(Types.class.getField("listOfStrings"));
6264
Object result = this.conversionService.convert(stream, listOfStrings);
6365

64-
assertThat(result).as("Converted object must not be null").isNotNull();
65-
boolean condition = result instanceof List;
66-
assertThat(condition).as("Converted object must be a list").isTrue();
67-
@SuppressWarnings("unchecked")
68-
List<String> content = (List<String>) result;
69-
assertThat(content.get(0)).isEqualTo("1");
70-
assertThat(content.get(1)).isEqualTo("2");
71-
assertThat(content.get(2)).isEqualTo("3");
72-
assertThat(content.size()).as("Wrong number of elements").isEqualTo(3);
66+
assertThat(result).asInstanceOf(list(String.class)).containsExactly("1", "2", "3");
7367
}
7468

7569
@Test
7670
void convertFromStreamToArray() throws NoSuchFieldException {
7771
this.conversionService.addConverterFactory(new NumberToNumberConverterFactory());
78-
Stream<Integer> stream = Arrays.asList(1, 2, 3).stream();
72+
Stream<Integer> stream = Stream.of(1, 2, 3);
7973
TypeDescriptor arrayOfLongs = new TypeDescriptor(Types.class.getField("arrayOfLongs"));
8074
Object result = this.conversionService.convert(stream, arrayOfLongs);
8175

8276
assertThat(result).as("Converted object must not be null").isNotNull();
8377
assertThat(result.getClass().isArray()).as("Converted object must be an array").isTrue();
8478
Long[] content = (Long[]) result;
85-
assertThat(content[0]).isEqualTo(Long.valueOf(1L));
86-
assertThat(content[1]).isEqualTo(Long.valueOf(2L));
87-
assertThat(content[2]).isEqualTo(Long.valueOf(3L));
88-
assertThat(content.length).as("Wrong number of elements").isEqualTo(3);
79+
assertThat(content).containsExactly(1L, 2L, 3L);
8980
}
9081

9182
@Test
9283
void convertFromStreamToRawList() throws NoSuchFieldException {
93-
Stream<Integer> stream = Arrays.asList(1, 2, 3).stream();
84+
Stream<Integer> stream = Stream.of(1, 2, 3);
9485
TypeDescriptor listOfStrings = new TypeDescriptor(Types.class.getField("rawList"));
9586
Object result = this.conversionService.convert(stream, listOfStrings);
9687

97-
assertThat(result).as("Converted object must not be null").isNotNull();
98-
boolean condition = result instanceof List;
99-
assertThat(condition).as("Converted object must be a list").isTrue();
100-
@SuppressWarnings("unchecked")
101-
List<Object> content = (List<Object>) result;
102-
assertThat(content.get(0)).isEqualTo(1);
103-
assertThat(content.get(1)).isEqualTo(2);
104-
assertThat(content.get(2)).isEqualTo(3);
105-
assertThat(content.size()).as("Wrong number of elements").isEqualTo(3);
88+
assertThat(result).asInstanceOf(list(Object.class)).containsExactly(1, 2, 3);
10689
}
10790

10891
@Test
10992
void convertFromStreamToArrayNoConverter() throws NoSuchFieldException {
110-
Stream<Integer> stream = Arrays.asList(1, 2, 3).stream();
93+
Stream<Integer> stream = Stream.of(1, 2, 3);
11194
TypeDescriptor arrayOfLongs = new TypeDescriptor(Types.class.getField("arrayOfLongs"));
112-
assertThatExceptionOfType(ConversionFailedException.class).isThrownBy(() ->
113-
this.conversionService.convert(stream, arrayOfLongs))
95+
assertThatExceptionOfType(ConversionFailedException.class)
96+
.isThrownBy(() -> this.conversionService.convert(stream, arrayOfLongs))
11497
.withCauseInstanceOf(ConverterNotFoundException.class);
11598
}
11699

117100
@Test
118101
@SuppressWarnings("resource")
119102
void convertFromListToStream() throws NoSuchFieldException {
120103
this.conversionService.addConverterFactory(new StringToNumberConverterFactory());
121-
List<String> stream = Arrays.asList("1", "2", "3");
104+
List<String> list = Arrays.asList("1", "2", "3");
122105
TypeDescriptor streamOfInteger = new TypeDescriptor(Types.class.getField("streamOfIntegers"));
123-
Object result = this.conversionService.convert(stream, streamOfInteger);
106+
Object result = this.conversionService.convert(list, streamOfInteger);
124107

125-
assertThat(result).as("Converted object must not be null").isNotNull();
126-
boolean condition = result instanceof Stream;
127-
assertThat(condition).as("Converted object must be a stream").isTrue();
108+
assertThat(result).as("Converted object must be a stream").isInstanceOf(Stream.class);
128109
@SuppressWarnings("unchecked")
129110
Stream<Integer> content = (Stream<Integer>) result;
130111
assertThat(content.mapToInt(x -> x).sum()).isEqualTo(6);
@@ -133,39 +114,25 @@ void convertFromListToStream() throws NoSuchFieldException {
133114
@Test
134115
@SuppressWarnings("resource")
135116
void convertFromArrayToStream() throws NoSuchFieldException {
136-
Integer[] stream = new Integer[] {1, 0, 1};
137-
this.conversionService.addConverter(new Converter<Integer, Boolean>() {
138-
@Override
139-
public Boolean convert(Integer source) {
140-
return source == 1;
141-
}
142-
});
117+
Integer[] array = new Integer[] {1, 0, 1};
118+
this.conversionService.addConverter(Integer.class, Boolean.class, source -> source == 1);
143119
TypeDescriptor streamOfBoolean = new TypeDescriptor(Types.class.getField("streamOfBooleans"));
144-
Object result = this.conversionService.convert(stream, streamOfBoolean);
120+
Object result = this.conversionService.convert(array, streamOfBoolean);
145121

146-
assertThat(result).as("Converted object must not be null").isNotNull();
147-
boolean condition = result instanceof Stream;
148-
assertThat(condition).as("Converted object must be a stream").isTrue();
149-
@SuppressWarnings("unchecked")
150-
Stream<Boolean> content = (Stream<Boolean>) result;
151-
assertThat(content.filter(x -> x).count()).isEqualTo(2);
122+
assertThat(result).asInstanceOf(stream(Boolean.class)).filteredOn(x -> x).hasSize(2);
152123
}
153124

154125
@Test
155126
@SuppressWarnings("resource")
156127
void convertFromListToRawStream() throws NoSuchFieldException {
157-
List<String> stream = Arrays.asList("1", "2", "3");
128+
List<String> list = Arrays.asList("1", "2", "3");
158129
TypeDescriptor streamOfInteger = new TypeDescriptor(Types.class.getField("rawStream"));
159-
Object result = this.conversionService.convert(stream, streamOfInteger);
130+
Object result = this.conversionService.convert(list, streamOfInteger);
160131

161-
assertThat(result).as("Converted object must not be null").isNotNull();
162-
boolean condition = result instanceof Stream;
163-
assertThat(condition).as("Converted object must be a stream").isTrue();
132+
assertThat(result).as("Converted object must be a stream").isInstanceOf(Stream.class);
164133
@SuppressWarnings("unchecked")
165134
Stream<Object> content = (Stream<Object>) result;
166-
StringBuilder sb = new StringBuilder();
167-
content.forEach(sb::append);
168-
assertThat(sb.toString()).isEqualTo("123");
135+
assertThat(content).containsExactly("1", "2", "3");
169136
}
170137

171138
@Test

spring-core/src/test/java/org/springframework/core/env/ProfilesTests.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2020 the original author or authors.
2+
* Copyright 2002-2021 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -47,8 +47,8 @@ void ofWhenNullThrowsException() {
4747

4848
@Test
4949
void ofWhenEmptyThrowsException() {
50-
assertThatIllegalArgumentException().isThrownBy(() ->
51-
Profiles.of())
50+
assertThatIllegalArgumentException()
51+
.isThrownBy(Profiles::of)
5252
.withMessageContaining("Must specify at least one profile");
5353
}
5454

@@ -354,8 +354,8 @@ void equalsAndHashCodeAreNotBasedOnLogicalStructureOfNodesWithinExpressionTree()
354354

355355

356356
private static void assertMalformed(Supplier<Profiles> supplier) {
357-
assertThatIllegalArgumentException().isThrownBy(
358-
supplier::get)
357+
assertThatIllegalArgumentException()
358+
.isThrownBy(supplier::get)
359359
.withMessageContaining("Malformed");
360360
}
361361

spring-core/src/test/java/org/springframework/core/env/StandardEnvironmentTests.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,7 @@ void reservedDefaultProfile() {
209209
void defaultProfileWithCircularPlaceholder() {
210210
try {
211211
System.setProperty(DEFAULT_PROFILES_PROPERTY_NAME, "${spring.profiles.default}");
212-
assertThatIllegalArgumentException().isThrownBy(() -> environment.getDefaultProfiles());
212+
assertThatIllegalArgumentException().isThrownBy(environment::getDefaultProfiles);
213213
}
214214
finally {
215215
System.clearProperty(DEFAULT_PROFILES_PROPERTY_NAME);

spring-core/src/test/java/org/springframework/core/io/buffer/DataBufferUtilsTests.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2020 the original author or authors.
2+
* Copyright 2002-2021 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -80,7 +80,7 @@ void readInputStream(String displayName, DataBufferFactory bufferFactory) {
8080
super.bufferFactory = bufferFactory;
8181

8282
Flux<DataBuffer> flux = DataBufferUtils.readInputStream(
83-
() -> this.resource.getInputStream(), super.bufferFactory, 3);
83+
this.resource::getInputStream, super.bufferFactory, 3);
8484

8585
verifyReadData(flux);
8686
}

spring-core/src/test/java/org/springframework/core/task/SimpleAsyncTaskExecutorTests.java

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2019 the original author or authors.
2+
* Copyright 2002-2021 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -16,8 +16,6 @@
1616

1717
package org.springframework.core.task;
1818

19-
import java.util.concurrent.ThreadFactory;
20-
2119
import org.junit.jupiter.api.Test;
2220

2321
import org.springframework.util.ConcurrencyThrottleSupport;
@@ -61,12 +59,7 @@ void threadNameGetsSetCorrectly() throws Exception {
6159
@Test
6260
void threadFactoryOverridesDefaults() throws Exception {
6361
final Object monitor = new Object();
64-
SimpleAsyncTaskExecutor executor = new SimpleAsyncTaskExecutor(new ThreadFactory() {
65-
@Override
66-
public Thread newThread(Runnable r) {
67-
return new Thread(r, "test");
68-
}
69-
});
62+
SimpleAsyncTaskExecutor executor = new SimpleAsyncTaskExecutor(runnable -> new Thread(runnable, "test"));
7063
ThreadNameHarvester task = new ThreadNameHarvester(monitor);
7164
executeAndWait(executor, task, monitor);
7265
assertThat(task.getThreadName()).isEqualTo("test");

spring-core/src/test/java/org/springframework/util/concurrent/SettableListenableFutureTests.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2020 the original author or authors.
2+
* Copyright 2002-2021 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -332,8 +332,7 @@ void setExceptionPreventsCancel() {
332332
void cancelStateThrowsExceptionWhenCallingGet() throws ExecutionException, InterruptedException {
333333
settableListenableFuture.cancel(true);
334334

335-
assertThatExceptionOfType(CancellationException.class).isThrownBy(() ->
336-
settableListenableFuture.get());
335+
assertThatExceptionOfType(CancellationException.class).isThrownBy(settableListenableFuture::get);
337336

338337
assertThat(settableListenableFuture.isCancelled()).isTrue();
339338
assertThat(settableListenableFuture.isDone()).isTrue();

spring-core/src/test/java/org/springframework/util/xml/AbstractStaxXMLReaderTests.java

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2019 the original author or authors.
2+
* Copyright 2002-2021 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -183,12 +183,9 @@ protected final ContentHandler mockContentHandler() throws Exception {
183183
ContentHandler contentHandler = mock(ContentHandler.class);
184184
willAnswer(new CopyCharsAnswer()).given(contentHandler).characters(any(char[].class), anyInt(), anyInt());
185185
willAnswer(new CopyCharsAnswer()).given(contentHandler).ignorableWhitespace(any(char[].class), anyInt(), anyInt());
186-
willAnswer(new Answer<Object>() {
187-
@Override
188-
public Object answer(InvocationOnMock invocation) throws Throwable {
189-
invocation.getArguments()[3] = new AttributesImpl((Attributes) invocation.getArguments()[3]);
190-
return null;
191-
}
186+
willAnswer(invocation -> {
187+
invocation.getArguments()[3] = new AttributesImpl((Attributes) invocation.getArguments()[3]);
188+
return null;
192189
}).given(contentHandler).startElement(anyString(), anyString(), anyString(), any(Attributes.class));
193190
return contentHandler;
194191
}

0 commit comments

Comments
 (0)