Skip to content

Commit 6d99770

Browse files
committed
Merge branch 'framework-6.2'
Closes gh-41177
2 parents 9016695 + fe4c34d commit 6d99770

File tree

10 files changed

+25
-102
lines changed

10 files changed

+25
-102
lines changed

gradle.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ junitJupiterVersion=5.10.2
1414
kotlinVersion=1.9.24
1515
mavenVersion=3.9.4
1616
nativeBuildToolsVersion=0.10.2
17-
springFrameworkVersion=6.1.10
17+
springFrameworkVersion=6.2.0-M4
1818
springFramework60xVersion=6.0.21
1919
tomcatVersion=10.1.25
2020
snakeYamlVersion=2.2

spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/scheduling/ScheduledTasksEndpoint.java

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2023 the original author or authors.
2+
* Copyright 2012-2024 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,7 +16,6 @@
1616

1717
package org.springframework.boot.actuate.scheduling;
1818

19-
import java.lang.reflect.Method;
2019
import java.time.Duration;
2120
import java.util.Collection;
2221
import java.util.Collections;
@@ -46,7 +45,6 @@
4645
import org.springframework.scheduling.config.TriggerTask;
4746
import org.springframework.scheduling.support.CronTrigger;
4847
import org.springframework.scheduling.support.PeriodicTrigger;
49-
import org.springframework.scheduling.support.ScheduledMethodRunnable;
5048

5149
/**
5250
* {@link Endpoint @Endpoint} to expose information about an application's scheduled
@@ -284,13 +282,7 @@ public static final class RunnableDescriptor {
284282
private final String target;
285283

286284
private RunnableDescriptor(Runnable runnable) {
287-
if (runnable instanceof ScheduledMethodRunnable scheduledMethodRunnable) {
288-
Method method = scheduledMethodRunnable.getMethod();
289-
this.target = method.getDeclaringClass().getName() + "." + method.getName();
290-
}
291-
else {
292-
this.target = runnable.getClass().getName();
293-
}
285+
this.target = runnable.toString();
294286
}
295287

296288
public String getTarget() {

spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/scheduling/ScheduledTasksEndpointTests.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ void cronTriggerIsReported() {
8080
assertThat(tasks.getCron()).hasSize(1);
8181
CronTaskDescriptor description = (CronTaskDescriptor) tasks.getCron().get(0);
8282
assertThat(description.getExpression()).isEqualTo("0 0 0/6 1/1 * ?");
83-
assertThat(description.getRunnable().getTarget()).isEqualTo(CronTriggerRunnable.class.getName());
83+
assertThat(description.getRunnable().getTarget()).contains(CronTriggerRunnable.class.getName());
8484
});
8585
}
8686

@@ -109,7 +109,7 @@ void fixedDelayTriggerIsReported() {
109109
FixedDelayTaskDescriptor description = (FixedDelayTaskDescriptor) tasks.getFixedDelay().get(0);
110110
assertThat(description.getInitialDelay()).isEqualTo(2000);
111111
assertThat(description.getInterval()).isEqualTo(1000);
112-
assertThat(description.getRunnable().getTarget()).isEqualTo(FixedDelayTriggerRunnable.class.getName());
112+
assertThat(description.getRunnable().getTarget()).contains(FixedDelayTriggerRunnable.class.getName());
113113
});
114114
}
115115

@@ -123,7 +123,7 @@ void noInitialDelayFixedDelayTriggerIsReported() {
123123
FixedDelayTaskDescriptor description = (FixedDelayTaskDescriptor) tasks.getFixedDelay().get(0);
124124
assertThat(description.getInitialDelay()).isEqualTo(0);
125125
assertThat(description.getInterval()).isEqualTo(1000);
126-
assertThat(description.getRunnable().getTarget()).isEqualTo(FixedDelayTriggerRunnable.class.getName());
126+
assertThat(description.getRunnable().getTarget()).contains(FixedDelayTriggerRunnable.class.getName());
127127
});
128128
}
129129

@@ -152,7 +152,7 @@ void fixedRateTriggerIsReported() {
152152
FixedRateTaskDescriptor description = (FixedRateTaskDescriptor) tasks.getFixedRate().get(0);
153153
assertThat(description.getInitialDelay()).isEqualTo(3000);
154154
assertThat(description.getInterval()).isEqualTo(2000);
155-
assertThat(description.getRunnable().getTarget()).isEqualTo(FixedRateTriggerRunnable.class.getName());
155+
assertThat(description.getRunnable().getTarget()).contains(FixedRateTriggerRunnable.class.getName());
156156
});
157157
}
158158

@@ -166,7 +166,7 @@ void noInitialDelayFixedRateTriggerIsReported() {
166166
FixedRateTaskDescriptor description = (FixedRateTaskDescriptor) tasks.getFixedRate().get(0);
167167
assertThat(description.getInitialDelay()).isEqualTo(0);
168168
assertThat(description.getInterval()).isEqualTo(2000);
169-
assertThat(description.getRunnable().getTarget()).isEqualTo(FixedRateTriggerRunnable.class.getName());
169+
assertThat(description.getRunnable().getTarget()).contains(FixedRateTriggerRunnable.class.getName());
170170
});
171171
}
172172

@@ -178,7 +178,7 @@ void taskWithCustomTriggerIsReported() {
178178
assertThat(tasks.getFixedRate()).isEmpty();
179179
assertThat(tasks.getCustom()).hasSize(1);
180180
CustomTriggerTaskDescriptor description = (CustomTriggerTaskDescriptor) tasks.getCustom().get(0);
181-
assertThat(description.getRunnable().getTarget()).isEqualTo(CustomTriggerRunnable.class.getName());
181+
assertThat(description.getRunnable().getTarget()).contains(CustomTriggerRunnable.class.getName());
182182
assertThat(description.getTrigger()).isEqualTo(CustomTriggerTask.trigger.toString());
183183
});
184184
}

spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/jdbc/DataSourceAutoConfiguration.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,7 @@ private boolean hasDataSourceUrlProperty(ConditionContext context) {
157157
return StringUtils.hasText(environment.getProperty(DATASOURCE_URL_PROPERTY));
158158
}
159159
catch (IllegalArgumentException ex) {
160+
// NOTE: This should be PlaceholderResolutionException
160161
// Ignore unresolvable placeholder errors
161162
}
162163
}

spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/http/HttpMessageConvertersTests.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2023 the original author or authors.
2+
* Copyright 2012-2024 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.
@@ -146,7 +146,7 @@ protected List<HttpMessageConverter<?>> postProcessPartConverters(
146146
}
147147
assertThat(converterClasses).containsExactly(ByteArrayHttpMessageConverter.class,
148148
StringHttpMessageConverter.class, ResourceHttpMessageConverter.class,
149-
MappingJackson2HttpMessageConverter.class);
149+
MappingJackson2HttpMessageConverter.class, MappingJackson2CborHttpMessageConverter.class);
150150
}
151151

152152
private List<HttpMessageConverter<?>> extractFormPartConverters(List<HttpMessageConverter<?>> converters) {

spring-boot-project/spring-boot-test/src/main/java/org/springframework/boot/test/mock/mockito/MockitoTestExecutionListener.java

Lines changed: 1 addition & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -16,27 +16,18 @@
1616

1717
package org.springframework.boot.test.mock.mockito;
1818

19-
import java.lang.annotation.Annotation;
2019
import java.lang.reflect.Field;
21-
import java.util.LinkedHashSet;
22-
import java.util.Set;
2320
import java.util.function.BiConsumer;
2421

25-
import org.mockito.Captor;
26-
import org.mockito.MockitoAnnotations;
27-
2822
import org.springframework.test.context.TestContext;
2923
import org.springframework.test.context.TestExecutionListener;
3024
import org.springframework.test.context.support.AbstractTestExecutionListener;
3125
import org.springframework.test.context.support.DependencyInjectionTestExecutionListener;
3226
import org.springframework.util.ReflectionUtils;
33-
import org.springframework.util.ReflectionUtils.FieldCallback;
3427

3528
/**
3629
* {@link TestExecutionListener} to enable {@link MockBean @MockBean} and
37-
* {@link SpyBean @SpyBean} support. Also triggers
38-
* {@link MockitoAnnotations#openMocks(Object)} when any Mockito annotations used,
39-
* primarily to allow {@link Captor @Captor} annotations.
30+
* {@link SpyBean @SpyBean} support.
4031
* <p>
4132
* To use the automatic reset support of {@code @MockBean} and {@code @SpyBean}, configure
4233
* {@link ResetMocksTestExecutionListener} as well.
@@ -49,59 +40,24 @@
4940
*/
5041
public class MockitoTestExecutionListener extends AbstractTestExecutionListener {
5142

52-
private static final String MOCKS_ATTRIBUTE_NAME = MockitoTestExecutionListener.class.getName() + ".mocks";
53-
5443
@Override
5544
public final int getOrder() {
5645
return 1950;
5746
}
5847

5948
@Override
6049
public void prepareTestInstance(TestContext testContext) throws Exception {
61-
closeMocks(testContext);
62-
initMocks(testContext);
6350
injectFields(testContext);
6451
}
6552

6653
@Override
6754
public void beforeTestMethod(TestContext testContext) throws Exception {
6855
if (Boolean.TRUE.equals(
6956
testContext.getAttribute(DependencyInjectionTestExecutionListener.REINJECT_DEPENDENCIES_ATTRIBUTE))) {
70-
closeMocks(testContext);
71-
initMocks(testContext);
7257
reinjectFields(testContext);
7358
}
7459
}
7560

76-
@Override
77-
public void afterTestMethod(TestContext testContext) throws Exception {
78-
closeMocks(testContext);
79-
}
80-
81-
@Override
82-
public void afterTestClass(TestContext testContext) throws Exception {
83-
closeMocks(testContext);
84-
}
85-
86-
private void initMocks(TestContext testContext) {
87-
if (hasMockitoAnnotations(testContext)) {
88-
testContext.setAttribute(MOCKS_ATTRIBUTE_NAME, MockitoAnnotations.openMocks(testContext.getTestInstance()));
89-
}
90-
}
91-
92-
private void closeMocks(TestContext testContext) throws Exception {
93-
Object mocks = testContext.getAttribute(MOCKS_ATTRIBUTE_NAME);
94-
if (mocks instanceof AutoCloseable closeable) {
95-
closeable.close();
96-
}
97-
}
98-
99-
private boolean hasMockitoAnnotations(TestContext testContext) {
100-
MockitoAnnotationCollection collector = new MockitoAnnotationCollection();
101-
ReflectionUtils.doWithFields(testContext.getTestClass(), collector);
102-
return collector.hasAnnotations();
103-
}
104-
10561
private void injectFields(TestContext testContext) {
10662
postProcessFields(testContext, (mockitoField, postProcessor) -> postProcessor.inject(mockitoField.field,
10763
mockitoField.target, mockitoField.definition));
@@ -130,28 +86,6 @@ private void postProcessFields(TestContext testContext, BiConsumer<MockitoField,
13086
}
13187
}
13288

133-
/**
134-
* {@link FieldCallback} to collect Mockito annotations.
135-
*/
136-
private static final class MockitoAnnotationCollection implements FieldCallback {
137-
138-
private final Set<Annotation> annotations = new LinkedHashSet<>();
139-
140-
@Override
141-
public void doWith(Field field) throws IllegalArgumentException {
142-
for (Annotation annotation : field.getDeclaredAnnotations()) {
143-
if (annotation.annotationType().getName().startsWith("org.mockito")) {
144-
this.annotations.add(annotation);
145-
}
146-
}
147-
}
148-
149-
boolean hasAnnotations() {
150-
return !this.annotations.isEmpty();
151-
}
152-
153-
}
154-
15589
private static final class MockitoField {
15690

15791
private final Field field;

spring-boot-project/spring-boot-test/src/test/java/org/springframework/boot/test/mock/mockito/MockitoTestExecutionListenerTests.java

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2023 the original author or authors.
2+
* Copyright 2012-2024 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.
@@ -53,14 +53,6 @@ class MockitoTestExecutionListenerTests {
5353
@Mock
5454
private MockitoPostProcessor postProcessor;
5555

56-
@Test
57-
void prepareTestInstanceShouldInitMockitoAnnotations() throws Exception {
58-
WithMockitoAnnotations instance = new WithMockitoAnnotations();
59-
this.listener.prepareTestInstance(mockTestContext(instance));
60-
assertThat(instance.mock).isNotNull();
61-
assertThat(instance.captor).isNotNull();
62-
}
63-
6456
@Test
6557
void prepareTestInstanceShouldInjectMockBean() throws Exception {
6658
given(this.applicationContext.getBean(MockitoPostProcessor.class)).willReturn(this.postProcessor);

spring-boot-project/spring-boot-test/src/test/java/org/springframework/boot/test/web/SpringBootTestRandomPortEnvironmentPostProcessorTests.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,10 @@
2727
import org.springframework.core.env.MutablePropertySources;
2828
import org.springframework.mock.env.MockEnvironment;
2929
import org.springframework.test.context.support.TestPropertySourceUtils;
30+
import org.springframework.util.PlaceholderResolutionException;
3031

3132
import static org.assertj.core.api.Assertions.assertThat;
32-
import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException;
33+
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
3334

3435
/**
3536
* Tests for {@link SpringBootTestRandomPortEnvironmentPostProcessor}.
@@ -169,7 +170,7 @@ void postProcessWhenManagementServerPortPlaceholderAbsentShouldFail() {
169170
addTestPropertySource("0", null);
170171
this.propertySources
171172
.addLast(new MapPropertySource("other", Collections.singletonMap("management.server.port", "${port}")));
172-
assertThatIllegalArgumentException()
173+
assertThatExceptionOfType(PlaceholderResolutionException.class)
173174
.isThrownBy(() -> this.postProcessor.postProcessEnvironment(this.environment, null))
174175
.withMessage("Could not resolve placeholder 'port' in value \"${port}\"");
175176
}
@@ -196,7 +197,7 @@ void postProcessWhenServerPortPlaceholderAbsentShouldFail() {
196197
source.put("server.port", "${port}");
197198
source.put("management.server.port", "9090");
198199
this.propertySources.addLast(new MapPropertySource("other", source));
199-
assertThatIllegalArgumentException()
200+
assertThatExceptionOfType(PlaceholderResolutionException.class)
200201
.isThrownBy(() -> this.postProcessor.postProcessEnvironment(this.environment, null))
201202
.withMessage("Could not resolve placeholder 'port' in value \"${port}\"");
202203
}

spring-boot-project/spring-boot/src/main/java/org/springframework/boot/context/config/ConfigDataEnvironmentContributorPlaceholdersResolver.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,8 @@ class ConfigDataEnvironmentContributorPlaceholdersResolver implements Placeholde
5656
this.failOnResolveFromInactiveContributor = failOnResolveFromInactiveContributor;
5757
this.conversionService = conversionService;
5858
this.helper = new PropertyPlaceholderHelper(SystemPropertyUtils.PLACEHOLDER_PREFIX,
59-
SystemPropertyUtils.PLACEHOLDER_SUFFIX, SystemPropertyUtils.VALUE_SEPARATOR, true);
59+
SystemPropertyUtils.PLACEHOLDER_SUFFIX, SystemPropertyUtils.VALUE_SEPARATOR,
60+
SystemPropertyUtils.ESCAPE_CHARACTER, true);
6061
}
6162

6263
@Override

spring-boot-project/spring-boot/src/main/java/org/springframework/boot/context/properties/bind/PropertySourcesPlaceholdersResolver.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2022 the original author or authors.
2+
* Copyright 2012-2024 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,10 @@ public PropertySourcesPlaceholdersResolver(Iterable<PropertySource<?>> sources)
4747

4848
public PropertySourcesPlaceholdersResolver(Iterable<PropertySource<?>> sources, PropertyPlaceholderHelper helper) {
4949
this.sources = sources;
50-
this.helper = (helper != null) ? helper : new PropertyPlaceholderHelper(SystemPropertyUtils.PLACEHOLDER_PREFIX,
51-
SystemPropertyUtils.PLACEHOLDER_SUFFIX, SystemPropertyUtils.VALUE_SEPARATOR, true);
50+
this.helper = (helper != null) ? helper
51+
: new PropertyPlaceholderHelper(SystemPropertyUtils.PLACEHOLDER_PREFIX,
52+
SystemPropertyUtils.PLACEHOLDER_SUFFIX, SystemPropertyUtils.VALUE_SEPARATOR,
53+
SystemPropertyUtils.ESCAPE_CHARACTER, true);
5254
}
5355

5456
@Override

0 commit comments

Comments
 (0)