Skip to content

Commit aafceb3

Browse files
committed
Merge branch '2.7.x'
Closes spring-projectsgh-32285
2 parents 205378e + f17df7b commit aafceb3

File tree

10 files changed

+182
-53
lines changed

10 files changed

+182
-53
lines changed

spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/management/ThreadDumpEndpointTests.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2019 the original author or authors.
2+
* Copyright 2012-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.
@@ -105,7 +105,11 @@ void dumpThreadsAsText() throws InterruptedException {
105105
.contains(String.format("\t- waiting to lock <%s> (a java.lang.Object) owned by \"%s\" t@%d",
106106
hexIdentityHashCode(contendedMonitor), Thread.currentThread().getName(),
107107
Thread.currentThread().getId()))
108-
.contains(String.format("\t- waiting on <%s> (a java.lang.Object)", hexIdentityHashCode(monitor)))
108+
.satisfiesAnyOf(
109+
(dump) -> dump.contains(String.format("\t- waiting on <%s> (a java.lang.Object)",
110+
hexIdentityHashCode(monitor))),
111+
(dump) -> dump.contains(String.format("\t- parking to wait for <%s> (a java.lang.Object)",
112+
hexIdentityHashCode(monitor))))
109113
.containsPattern(
110114
String.format("Locked ownable synchronizers:%n\t- Locked <[0-9a-z]+> \\(a %s\\$NonfairSync\\)",
111115
ReentrantReadWriteLock.class.getName().replace(".", "\\.")));

spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/reactive/ReactiveWebServerFactoryCustomizerTests.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ void testCustomizeServerPort() {
5959
@Test
6060
void testCustomizeServerAddress() {
6161
ConfigurableReactiveWebServerFactory factory = mock(ConfigurableReactiveWebServerFactory.class);
62-
InetAddress address = mock(InetAddress.class);
62+
InetAddress address = InetAddress.getLoopbackAddress();
6363
this.properties.setAddress(address);
6464
this.customizer.customize(factory);
6565
then(factory).should().setAddress(address);

spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/build.gradle

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,3 +127,7 @@ task zip(type: Zip) {
127127
artifacts {
128128
"documentation" zip
129129
}
130+
131+
toolchain {
132+
maximumCompatibleJavaVersion = JavaLanguageVersion.of(18)
133+
}

spring-boot-project/spring-boot/src/test/java/org/springframework/boot/context/properties/bind/ArrayBinderTests.java

Lines changed: 32 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,9 @@
2121
import java.util.Set;
2222

2323
import org.junit.jupiter.api.Test;
24-
import org.mockito.Answers;
2524
import org.mockito.InOrder;
25+
import org.mockito.invocation.InvocationOnMock;
26+
import org.mockito.stubbing.Answer;
2627

2728
import org.springframework.boot.context.properties.source.ConfigurationProperty;
2829
import org.springframework.boot.context.properties.source.ConfigurationPropertyName;
@@ -35,6 +36,7 @@
3536
import static org.mockito.ArgumentMatchers.any;
3637
import static org.mockito.ArgumentMatchers.eq;
3738
import static org.mockito.ArgumentMatchers.isA;
39+
import static org.mockito.BDDMockito.given;
3840
import static org.mockito.Mockito.inOrder;
3941
import static org.mockito.Mockito.mock;
4042

@@ -68,7 +70,7 @@ void bindToArrayShouldReturnArray() {
6870
@Test
6971
void bindToCollectionShouldTriggerOnSuccess() {
7072
this.sources.add(new MockConfigurationPropertySource("foo[0]", "1", "line1"));
71-
BindHandler handler = mock(BindHandler.class, Answers.CALLS_REAL_METHODS);
73+
BindHandler handler = mockBindHandler();
7274
this.binder.bind("foo", INTEGER_LIST, handler);
7375
InOrder inOrder = inOrder(handler);
7476
inOrder.verify(handler).onSuccess(eq(ConfigurationPropertyName.of("foo[0]")), eq(Bindable.of(Integer.class)),
@@ -198,7 +200,7 @@ void bindToArrayWhenNoValueShouldReturnUnbound() {
198200
@Test
199201
void bindToArrayShouldTriggerOnSuccess() {
200202
this.sources.add(new MockConfigurationPropertySource("foo[0]", "1", "line1"));
201-
BindHandler handler = mock(BindHandler.class, Answers.CALLS_REAL_METHODS);
203+
BindHandler handler = mockBindHandler();
202204
Bindable<Integer[]> target = INTEGER_ARRAY;
203205
this.binder.bind("foo", target, handler);
204206
InOrder inOrder = inOrder(handler);
@@ -285,4 +287,31 @@ void bindToArrayWhenStringShouldUsePropertyEditor() {
285287
IllegalStateException.class);
286288
}
287289

290+
private BindHandler mockBindHandler() {
291+
BindHandler handler = mock(BindHandler.class);
292+
given(handler.onStart(any(), any(), any())).willAnswer(InvocationArgument.index(1));
293+
given(handler.onCreate(any(), any(), any(), any())).willAnswer(InvocationArgument.index(3));
294+
given(handler.onSuccess(any(), any(), any(), any())).willAnswer(InvocationArgument.index(3));
295+
return handler;
296+
}
297+
298+
private static final class InvocationArgument<T> implements Answer<T> {
299+
300+
private final int index;
301+
302+
private InvocationArgument(int index) {
303+
this.index = index;
304+
}
305+
306+
@Override
307+
public T answer(InvocationOnMock invocation) throws Throwable {
308+
return invocation.getArgument(this.index);
309+
}
310+
311+
private static <T> InvocationArgument<T> index(int index) {
312+
return new InvocationArgument<>(index);
313+
}
314+
315+
}
316+
288317
}

spring-boot-project/spring-boot/src/test/java/org/springframework/boot/context/properties/bind/BinderTests.java

Lines changed: 34 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,9 @@
2626

2727
import jakarta.validation.Validation;
2828
import org.junit.jupiter.api.Test;
29-
import org.mockito.Answers;
3029
import org.mockito.InOrder;
30+
import org.mockito.invocation.InvocationOnMock;
31+
import org.mockito.stubbing.Answer;
3132

3233
import org.springframework.boot.context.properties.bind.Bindable.BindRestriction;
3334
import org.springframework.boot.context.properties.bind.validation.ValidationBindHandler;
@@ -53,6 +54,7 @@
5354
import static org.mockito.ArgumentMatchers.any;
5455
import static org.mockito.ArgumentMatchers.eq;
5556
import static org.mockito.ArgumentMatchers.isA;
57+
import static org.mockito.BDDMockito.given;
5658
import static org.mockito.Mockito.inOrder;
5759
import static org.mockito.Mockito.mock;
5860

@@ -173,7 +175,7 @@ void bindToValueWithCustomPropertyEditorShouldReturnConvertedValue() {
173175
@Test
174176
void bindToValueShouldTriggerOnSuccess() {
175177
this.sources.add(new MockConfigurationPropertySource("foo", "1", "line1"));
176-
BindHandler handler = mock(BindHandler.class, Answers.CALLS_REAL_METHODS);
178+
BindHandler handler = mockBindHandler();
177179
Bindable<Integer> target = Bindable.of(Integer.class);
178180
this.binder.bind("foo", target, handler);
179181
InOrder ordered = inOrder(handler);
@@ -182,7 +184,7 @@ void bindToValueShouldTriggerOnSuccess() {
182184

183185
@Test
184186
void bindOrCreateWhenNotBoundShouldTriggerOnCreate() {
185-
BindHandler handler = mock(BindHandler.class, Answers.CALLS_REAL_METHODS);
187+
BindHandler handler = mock(BindHandler.class);
186188
Bindable<JavaBean> target = Bindable.of(JavaBean.class);
187189
this.binder.bindOrCreate("foo", target, handler);
188190
InOrder ordered = inOrder(handler);
@@ -218,7 +220,7 @@ void bindToJavaBeanWhenHasPropertyWithSameNameShouldStillBind() {
218220
@Test
219221
void bindToJavaBeanShouldTriggerOnSuccess() {
220222
this.sources.add(new MockConfigurationPropertySource("foo.value", "bar", "line1"));
221-
BindHandler handler = mock(BindHandler.class, Answers.CALLS_REAL_METHODS);
223+
BindHandler handler = mockBindHandler();
222224
Bindable<JavaBean> target = Bindable.of(JavaBean.class);
223225
this.binder.bind("foo", target, handler);
224226
InOrder inOrder = inOrder(handler);
@@ -231,7 +233,7 @@ void bindToJavaBeanShouldTriggerOnSuccess() {
231233
@Test
232234
void bindWhenHasCustomDefaultHandlerShouldTriggerOnSuccess() {
233235
this.sources.add(new MockConfigurationPropertySource("foo.value", "bar", "line1"));
234-
BindHandler handler = mock(BindHandler.class, Answers.CALLS_REAL_METHODS);
236+
BindHandler handler = mockBindHandler();
235237
Binder binder = new Binder(this.sources, null, null, null, handler);
236238
Bindable<JavaBean> target = Bindable.of(JavaBean.class);
237239
binder.bind("foo", target);
@@ -358,6 +360,14 @@ private JavaBeanWithPublicConstructor bindToJavaBeanWithPublicConstructor(
358360
return this.binder.bindOrCreate("foo", bindable);
359361
}
360362

363+
private BindHandler mockBindHandler() {
364+
BindHandler handler = mock(BindHandler.class);
365+
given(handler.onStart(any(), any(), any())).willAnswer(InvocationArgument.index(1));
366+
given(handler.onCreate(any(), any(), any(), any())).willAnswer(InvocationArgument.index(3));
367+
given(handler.onSuccess(any(), any(), any(), any())).willAnswer(InvocationArgument.index(3));
368+
return handler;
369+
}
370+
361371
static class JavaBean {
362372

363373
private String value;
@@ -486,4 +496,23 @@ public void setAsText(String text) {
486496

487497
}
488498

499+
private static final class InvocationArgument<T> implements Answer<T> {
500+
501+
private final int index;
502+
503+
private InvocationArgument(int index) {
504+
this.index = index;
505+
}
506+
507+
@Override
508+
public T answer(InvocationOnMock invocation) throws Throwable {
509+
return invocation.getArgument(this.index);
510+
}
511+
512+
private static <T> InvocationArgument<T> index(int index) {
513+
return new InvocationArgument<>(index);
514+
}
515+
516+
}
517+
489518
}

spring-boot-project/spring-boot/src/test/java/org/springframework/boot/context/properties/bind/MapBinderTests.java

Lines changed: 32 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,10 @@
2727
import java.util.stream.Collectors;
2828

2929
import org.junit.jupiter.api.Test;
30-
import org.mockito.Answers;
3130
import org.mockito.ArgumentCaptor;
3231
import org.mockito.InOrder;
32+
import org.mockito.invocation.InvocationOnMock;
33+
import org.mockito.stubbing.Answer;
3334

3435
import org.springframework.boot.context.properties.bind.BinderTests.ExampleEnum;
3536
import org.springframework.boot.context.properties.bind.BinderTests.JavaBean;
@@ -50,6 +51,7 @@
5051
import static org.mockito.ArgumentMatchers.any;
5152
import static org.mockito.ArgumentMatchers.eq;
5253
import static org.mockito.ArgumentMatchers.isA;
54+
import static org.mockito.BDDMockito.given;
5355
import static org.mockito.Mockito.inOrder;
5456
import static org.mockito.Mockito.mock;
5557

@@ -329,7 +331,7 @@ void bindToMapWithNoPropertiesShouldReturnUnbound() {
329331
@Test
330332
void bindToMapShouldTriggerOnSuccess() {
331333
this.sources.add(new MockConfigurationPropertySource("foo.bar", "1", "line1"));
332-
BindHandler handler = mock(BindHandler.class, Answers.CALLS_REAL_METHODS);
334+
BindHandler handler = mockBindHandler();
333335
Bindable<Map<String, Integer>> target = STRING_INTEGER_MAP;
334336
this.binder.bind("foo", target, handler);
335337
InOrder ordered = inOrder(handler);
@@ -341,7 +343,7 @@ void bindToMapShouldTriggerOnSuccess() {
341343
@Test
342344
void bindToMapStringArrayShouldTriggerOnSuccess() {
343345
this.sources.add(new MockConfigurationPropertySource("foo.bar", "a,b,c", "line1"));
344-
BindHandler handler = mock(BindHandler.class, Answers.CALLS_REAL_METHODS);
346+
BindHandler handler = mockBindHandler();
345347
Bindable<Map<String, String[]>> target = STRING_ARRAY_MAP;
346348
this.binder.bind("foo", target, handler);
347349
InOrder ordered = inOrder(handler);
@@ -614,6 +616,14 @@ private <T> Bindable<List<T>> getListBindable(ResolvableType type) {
614616
return Bindable.of(ResolvableType.forClassWithGenerics(List.class, type));
615617
}
616618

619+
private BindHandler mockBindHandler() {
620+
BindHandler handler = mock(BindHandler.class);
621+
given(handler.onStart(any(), any(), any())).willAnswer(InvocationArgument.index(1));
622+
given(handler.onCreate(any(), any(), any(), any())).willAnswer(InvocationArgument.index(3));
623+
given(handler.onSuccess(any(), any(), any(), any())).willAnswer(InvocationArgument.index(3));
624+
return handler;
625+
}
626+
617627
static class Foo {
618628

619629
private String pattern;
@@ -734,4 +744,23 @@ void setAddresses(Map<String, ? extends List<? extends InetAddress>> addresses)
734744

735745
}
736746

747+
private static final class InvocationArgument<T> implements Answer<T> {
748+
749+
private final int index;
750+
751+
private InvocationArgument(int index) {
752+
this.index = index;
753+
}
754+
755+
@Override
756+
public T answer(InvocationOnMock invocation) throws Throwable {
757+
return invocation.getArgument(this.index);
758+
}
759+
760+
private static <T> InvocationArgument<T> index(int index) {
761+
return new InvocationArgument<>(index);
762+
}
763+
764+
}
765+
737766
}

spring-boot-project/spring-boot/src/test/java/org/springframework/boot/context/properties/source/AliasedConfigurationPropertySourceTests.java

Lines changed: 7 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,8 @@
1919
import java.util.Collections;
2020

2121
import org.junit.jupiter.api.Test;
22-
import org.mockito.Answers;
2322

2423
import static org.assertj.core.api.Assertions.assertThat;
25-
import static org.mockito.BDDMockito.given;
26-
import static org.mockito.Mockito.mock;
2724

2825
/**
2926
* Tests for {@link AliasedConfigurationPropertySource}.
@@ -57,8 +54,7 @@ void getConfigurationPropertyWhenNotAliasesShouldReturnValue() {
5754
@Test
5855
void containsDescendantOfWhenSourceReturnsUnknownShouldReturnUnknown() {
5956
ConfigurationPropertyName name = ConfigurationPropertyName.of("foo");
60-
ConfigurationPropertySource source = mock(ConfigurationPropertySource.class, Answers.CALLS_REAL_METHODS);
61-
given(source.containsDescendantOf(name)).willReturn(ConfigurationPropertyState.UNKNOWN);
57+
ConfigurationPropertySource source = new KnownAncestorsConfigurationPropertySource().unknown(name);
6258
ConfigurationPropertySource aliased = source
6359
.withAliases(new ConfigurationPropertyNameAliases("foo.bar", "foo.bar1"));
6460
assertThat(aliased.containsDescendantOf(name)).isEqualTo(ConfigurationPropertyState.UNKNOWN);
@@ -67,10 +63,8 @@ void containsDescendantOfWhenSourceReturnsUnknownShouldReturnUnknown() {
6763
@Test
6864
void containsDescendantOfWhenSourceReturnsPresentShouldReturnPresent() {
6965
ConfigurationPropertyName name = ConfigurationPropertyName.of("foo");
70-
ConfigurationPropertySource source = mock(ConfigurationPropertySource.class, Answers.CALLS_REAL_METHODS);
71-
given(source.containsDescendantOf(name)).willReturn(ConfigurationPropertyState.PRESENT);
72-
given(source.containsDescendantOf(ConfigurationPropertyName.of("bar")))
73-
.willReturn(ConfigurationPropertyState.UNKNOWN);
66+
ConfigurationPropertySource source = new KnownAncestorsConfigurationPropertySource().present(name)
67+
.unknown(ConfigurationPropertyName.of("bar"));
7468
ConfigurationPropertySource aliased = source
7569
.withAliases(new ConfigurationPropertyNameAliases("foo.bar", "foo.bar1"));
7670
assertThat(aliased.containsDescendantOf(name)).isEqualTo(ConfigurationPropertyState.PRESENT);
@@ -79,21 +73,17 @@ void containsDescendantOfWhenSourceReturnsPresentShouldReturnPresent() {
7973
@Test
8074
void containsDescendantOfWhenAllAreAbsentShouldReturnAbsent() {
8175
ConfigurationPropertyName name = ConfigurationPropertyName.of("foo");
82-
ConfigurationPropertySource source = mock(ConfigurationPropertySource.class, Answers.CALLS_REAL_METHODS);
83-
given(source.containsDescendantOf(name)).willReturn(ConfigurationPropertyState.ABSENT);
84-
given(source.containsDescendantOf(ConfigurationPropertyName.of("bar")))
85-
.willReturn(ConfigurationPropertyState.ABSENT);
76+
ConfigurationPropertySource source = new KnownAncestorsConfigurationPropertySource().absent(name)
77+
.absent(ConfigurationPropertyName.of("bar"));
8678
ConfigurationPropertySource aliased = source.withAliases(new ConfigurationPropertyNameAliases("foo", "bar"));
8779
assertThat(aliased.containsDescendantOf(name)).isEqualTo(ConfigurationPropertyState.ABSENT);
8880
}
8981

9082
@Test
9183
void containsDescendantOfWhenAnyIsPresentShouldReturnPresent() {
9284
ConfigurationPropertyName name = ConfigurationPropertyName.of("foo");
93-
ConfigurationPropertySource source = mock(ConfigurationPropertySource.class, Answers.CALLS_REAL_METHODS);
94-
given(source.containsDescendantOf(name)).willReturn(ConfigurationPropertyState.ABSENT);
95-
given(source.containsDescendantOf(ConfigurationPropertyName.of("bar")))
96-
.willReturn(ConfigurationPropertyState.PRESENT);
85+
ConfigurationPropertySource source = new KnownAncestorsConfigurationPropertySource().absent(name)
86+
.present(ConfigurationPropertyName.of("bar"));
9787
ConfigurationPropertySource aliased = source.withAliases(new ConfigurationPropertyNameAliases("foo", "bar"));
9888
assertThat(aliased.containsDescendantOf(name)).isEqualTo(ConfigurationPropertyState.PRESENT);
9989
}

spring-boot-project/spring-boot/src/test/java/org/springframework/boot/context/properties/source/FilteredConfigurationPropertiesSourceTests.java

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,9 @@
1919
import java.util.Objects;
2020

2121
import org.junit.jupiter.api.Test;
22-
import org.mockito.Answers;
2322

2423
import static org.assertj.core.api.Assertions.assertThat;
2524
import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException;
26-
import static org.mockito.BDDMockito.given;
27-
import static org.mockito.Mockito.mock;
2825

2926
/**
3027
* Test for {@link FilteredIterableConfigurationPropertiesSource}.
@@ -64,26 +61,23 @@ void getValueShouldFilterNames() {
6461
@Test
6562
void containsDescendantOfWhenSourceReturnsEmptyShouldReturnEmpty() {
6663
ConfigurationPropertyName name = ConfigurationPropertyName.of("foo");
67-
ConfigurationPropertySource source = mock(ConfigurationPropertySource.class, Answers.CALLS_REAL_METHODS);
68-
given(source.containsDescendantOf(name)).willReturn(ConfigurationPropertyState.UNKNOWN);
64+
ConfigurationPropertySource source = new KnownAncestorsConfigurationPropertySource().unknown(name);
6965
ConfigurationPropertySource filtered = source.filter((n) -> true);
7066
assertThat(filtered.containsDescendantOf(name)).isEqualTo(ConfigurationPropertyState.UNKNOWN);
7167
}
7268

7369
@Test
7470
void containsDescendantOfWhenSourceReturnsFalseShouldReturnFalse() {
7571
ConfigurationPropertyName name = ConfigurationPropertyName.of("foo");
76-
ConfigurationPropertySource source = mock(ConfigurationPropertySource.class, Answers.CALLS_REAL_METHODS);
77-
given(source.containsDescendantOf(name)).willReturn(ConfigurationPropertyState.ABSENT);
72+
ConfigurationPropertySource source = new KnownAncestorsConfigurationPropertySource().absent(name);
7873
ConfigurationPropertySource filtered = source.filter((n) -> true);
7974
assertThat(filtered.containsDescendantOf(name)).isEqualTo(ConfigurationPropertyState.ABSENT);
8075
}
8176

8277
@Test
8378
void containsDescendantOfWhenSourceReturnsTrueShouldReturnEmpty() {
8479
ConfigurationPropertyName name = ConfigurationPropertyName.of("foo");
85-
ConfigurationPropertySource source = mock(ConfigurationPropertySource.class, Answers.CALLS_REAL_METHODS);
86-
given(source.containsDescendantOf(name)).willReturn(ConfigurationPropertyState.PRESENT);
80+
ConfigurationPropertySource source = new KnownAncestorsConfigurationPropertySource().present(name);
8781
ConfigurationPropertySource filtered = source.filter((n) -> true);
8882
assertThat(filtered.containsDescendantOf(name)).isEqualTo(ConfigurationPropertyState.UNKNOWN);
8983
}

0 commit comments

Comments
 (0)