Skip to content

Commit 847ff50

Browse files
committed
Merge pull request #40974 from asashour
* pr/40974: Polish "Use method references when possible in test code" Use method references when possible in test code Polish "Use method references when possible" Use method references when possible Closes gh-40974
2 parents ef99ce0 + bcbcafa commit 847ff50

File tree

42 files changed

+115
-93
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+115
-93
lines changed

buildSrc/src/main/java/org/springframework/boot/build/bom/UpgradePolicy.java

Lines changed: 3 additions & 3 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.
@@ -35,12 +35,12 @@ public enum UpgradePolicy implements BiPredicate<DependencyVersion, DependencyVe
3535
/**
3636
* Minor versions of the current major version.
3737
*/
38-
SAME_MAJOR_VERSION((candidate, current) -> candidate.isSameMajor(current)),
38+
SAME_MAJOR_VERSION(DependencyVersion::isSameMajor),
3939

4040
/**
4141
* Patch versions of the current minor version.
4242
*/
43-
SAME_MINOR_VERSION((candidate, current) -> candidate.isSameMinor(current));
43+
SAME_MINOR_VERSION(DependencyVersion::isSameMinor);
4444

4545
private final BiPredicate<DependencyVersion, DependencyVersion> delegate;
4646

spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/quartz/QuartzEndpoint.java

Lines changed: 4 additions & 3 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.
@@ -46,6 +46,7 @@
4646
import org.quartz.Trigger.TriggerState;
4747
import org.quartz.TriggerKey;
4848
import org.quartz.impl.matchers.GroupMatcher;
49+
import org.quartz.utils.Key;
4950

5051
import org.springframework.boot.actuate.endpoint.OperationResponseBody;
5152
import org.springframework.boot.actuate.endpoint.SanitizableData;
@@ -100,7 +101,7 @@ public QuartzGroupsDescriptor quartzJobGroups() throws SchedulerException {
100101
for (String groupName : this.scheduler.getJobGroupNames()) {
101102
List<String> jobs = this.scheduler.getJobKeys(GroupMatcher.jobGroupEquals(groupName))
102103
.stream()
103-
.map((key) -> key.getName())
104+
.map(Key::getName)
104105
.toList();
105106
result.put(groupName, Collections.singletonMap("jobs", jobs));
106107
}
@@ -121,7 +122,7 @@ public QuartzGroupsDescriptor quartzTriggerGroups() throws SchedulerException {
121122
groupDetails.put("triggers",
122123
this.scheduler.getTriggerKeys(GroupMatcher.triggerGroupEquals(groupName))
123124
.stream()
124-
.map((key) -> key.getName())
125+
.map(Key::getName)
125126
.toList());
126127
result.put(groupName, groupDetails);
127128
}

spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/flyway/FlywayAutoConfiguration.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -229,6 +229,8 @@ private void applyConnectionDetails(FlywayConnectionDetails connectionDetails, D
229229
* @param properties the properties
230230
*/
231231
private void configureProperties(FluentConfiguration configuration, FlywayProperties properties) {
232+
// NOTE: Using method references in the mapper methods can break
233+
// back-compatibilty (see gh-38164)
232234
PropertyMapper map = PropertyMapper.get().alwaysApplyingWhenNonNull();
233235
String[] locations = new LocationResolver(configuration.getDataSource())
234236
.resolveLocations(properties.getLocations())

spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/orm/jpa/HibernateProperties.java

Lines changed: 3 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.
@@ -148,9 +148,9 @@ public void setPhysicalStrategy(String physicalStrategy) {
148148

149149
private void applyNamingStrategies(Map<String, Object> properties) {
150150
applyNamingStrategy(properties, AvailableSettings.IMPLICIT_NAMING_STRATEGY, this.implicitStrategy,
151-
() -> SpringImplicitNamingStrategy.class.getName());
151+
SpringImplicitNamingStrategy.class::getName);
152152
applyNamingStrategy(properties, AvailableSettings.PHYSICAL_NAMING_STRATEGY, this.physicalStrategy,
153-
() -> CamelCaseToUnderscoresNamingStrategy.class.getName());
153+
CamelCaseToUnderscoresNamingStrategy.class::getName);
154154
}
155155

156156
private void applyNamingStrategy(Map<String, Object> properties, String key, Object strategy,

spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/graphql/security/GraphQlWebFluxSecurityAutoConfigurationTests.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2020-2023 the original author or authors.
2+
* Copyright 2020-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.
@@ -45,6 +45,7 @@
4545
import org.springframework.security.config.annotation.method.configuration.EnableReactiveMethodSecurity;
4646
import org.springframework.security.config.annotation.web.reactive.EnableWebFluxSecurity;
4747
import org.springframework.security.config.web.server.ServerHttpSecurity;
48+
import org.springframework.security.config.web.server.ServerHttpSecurity.CsrfSpec;
4849
import org.springframework.security.core.userdetails.MapReactiveUserDetailsService;
4950
import org.springframework.security.core.userdetails.User;
5051
import org.springframework.security.core.userdetails.UserDetails;
@@ -161,7 +162,7 @@ static class SecurityConfig {
161162

162163
@Bean
163164
SecurityWebFilterChain springWebFilterChain(ServerHttpSecurity http) {
164-
return http.csrf((spec) -> spec.disable())
165+
return http.csrf(CsrfSpec::disable)
165166
// Demonstrate that method security works
166167
// Best practice to use both for defense in depth
167168
.authorizeExchange((requests) -> requests.anyExchange().permitAll())

spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/graphql/security/GraphQlWebMvcSecurityAutoConfigurationTests.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
import org.springframework.security.config.annotation.method.configuration.EnableMethodSecurity;
4242
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
4343
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
44+
import org.springframework.security.config.annotation.web.configurers.CsrfConfigurer;
4445
import org.springframework.security.core.userdetails.User;
4546
import org.springframework.security.core.userdetails.UserDetails;
4647
import org.springframework.security.provisioning.InMemoryUserDetailsManager;
@@ -154,7 +155,7 @@ static class SecurityConfig {
154155

155156
@Bean
156157
DefaultSecurityFilterChain springWebFilterChain(HttpSecurity http) throws Exception {
157-
return http.csrf((c) -> c.disable())
158+
return http.csrf(CsrfConfigurer::disable)
158159
// Demonstrate that method security works
159160
// Best practice to use both for defense in depth
160161
.authorizeHttpRequests((requests) -> requests.anyRequest().permitAll())

spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/logging/ConditionEvaluationReportLoggingListenerTests.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.
@@ -58,7 +58,7 @@ void logsDebugOnContextRefresh(CapturedOutput output) {
5858
AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext();
5959
this.initializer.initialize(context);
6060
context.register(Config.class);
61-
withDebugLogging(() -> context.refresh());
61+
withDebugLogging(context::refresh);
6262
assertThat(output).contains("CONDITIONS EVALUATION REPORT");
6363
}
6464

spring-boot-project/spring-boot-devtools/src/main/java/org/springframework/boot/devtools/autoconfigure/RemoteDevtoolsSecurityConfiguration.java

Lines changed: 3 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.
@@ -23,6 +23,7 @@
2323
import org.springframework.context.annotation.Configuration;
2424
import org.springframework.core.annotation.Order;
2525
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
26+
import org.springframework.security.config.annotation.web.configurers.CsrfConfigurer;
2627
import org.springframework.security.web.SecurityFilterChain;
2728
import org.springframework.security.web.util.matcher.AntPathRequestMatcher;
2829

@@ -49,7 +50,7 @@ class RemoteDevtoolsSecurityConfiguration {
4950
SecurityFilterChain devtoolsSecurityFilterChain(HttpSecurity http) throws Exception {
5051
http.securityMatcher(new AntPathRequestMatcher(this.url));
5152
http.authorizeHttpRequests((requests) -> requests.anyRequest().anonymous());
52-
http.csrf((csrf) -> csrf.disable());
53+
http.csrf(CsrfConfigurer::disable);
5354
return http.build();
5455
}
5556

spring-boot-project/spring-boot-devtools/src/test/java/org/springframework/boot/devtools/filewatch/FileSystemWatcherTests.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -297,7 +297,7 @@ private void setupWatcher(long pollingInterval, long quietPeriod) {
297297
private void setupWatcher(long pollingInterval, long quietPeriod, SnapshotStateRepository snapshotStateRepository) {
298298
this.watcher = new FileSystemWatcher(false, Duration.ofMillis(pollingInterval), Duration.ofMillis(quietPeriod),
299299
snapshotStateRepository);
300-
this.watcher.addListener((changeSet) -> FileSystemWatcherTests.this.changes.add(changeSet));
300+
this.watcher.addListener(FileSystemWatcherTests.this.changes::add);
301301
}
302302

303303
private File startWithNewDirectory() {

spring-boot-project/spring-boot-docker-compose/src/test/java/org/springframework/boot/docker/compose/core/DefaultRunningServiceTests.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.
@@ -115,7 +115,7 @@ void toStringReturnsServiceName() {
115115
}
116116

117117
private DefaultRunningService createRunningService(boolean psResponseHasImage) {
118-
DockerHost host = DockerHost.get("192.168.1.1", () -> Collections.emptyList());
118+
DockerHost host = DockerHost.get("192.168.1.1", Collections::emptyList);
119119
String id = "123";
120120
String name = "my-service";
121121
String image = "redis";

spring-boot-project/spring-boot-docker-compose/src/test/java/org/springframework/boot/docker/compose/core/DockerHostTests.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.
@@ -52,7 +52,7 @@ class DockerHostTests {
5252

5353
private static final Function<String, String> NO_SYSTEM_ENV = (key) -> null;
5454

55-
private static final Supplier<List<DockerCliContextResponse>> NO_CONTEXT = () -> Collections.emptyList();
55+
private static final Supplier<List<DockerCliContextResponse>> NO_CONTEXT = Collections::emptyList;
5656

5757
@Test
5858
void getWhenHasHost() {

spring-boot-project/spring-boot-docker-compose/src/test/java/org/springframework/boot/docker/compose/lifecycle/TcpConnectServiceReadinessCheckTests.java

Lines changed: 3 additions & 3 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.
@@ -58,14 +58,14 @@ void setup() {
5858

5959
@Test
6060
void checkWhenServerWritesData() throws Exception {
61-
withServer((socket) -> socket.getOutputStream().write('!'), (port) -> check(port));
61+
withServer((socket) -> socket.getOutputStream().write('!'), this::check);
6262
}
6363

6464
@Test
6565
void checkWhenNoSocketOutput() throws Exception {
6666
// Simulate waiting for traffic from client to server. The sleep duration must
6767
// be longer than the read timeout of the ready check!
68-
withServer((socket) -> sleep(Duration.ofSeconds(10)), (port) -> check(port));
68+
withServer((socket) -> sleep(Duration.ofSeconds(10)), this::check);
6969
}
7070

7171
@Test

spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/data/sql/h2webconsole/springsecurity/DevProfileSecurityConfiguration.java

Lines changed: 5 additions & 3 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.
@@ -24,6 +24,8 @@
2424
import org.springframework.core.annotation.Order;
2525
import org.springframework.security.config.Customizer;
2626
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
27+
import org.springframework.security.config.annotation.web.configurers.CsrfConfigurer;
28+
import org.springframework.security.config.annotation.web.configurers.HeadersConfigurer.FrameOptionsConfig;
2729
import org.springframework.security.web.SecurityFilterChain;
2830

2931
@Profile("dev")
@@ -35,8 +37,8 @@ public class DevProfileSecurityConfiguration {
3537
SecurityFilterChain h2ConsoleSecurityFilterChain(HttpSecurity http) throws Exception {
3638
http.securityMatcher(PathRequest.toH2Console());
3739
http.authorizeHttpRequests(yourCustomAuthorization());
38-
http.csrf((csrf) -> csrf.disable());
39-
http.headers((headers) -> headers.frameOptions((frame) -> frame.sameOrigin()));
40+
http.csrf(CsrfConfigurer::disable);
41+
http.headers((headers) -> headers.frameOptions(FrameOptionsConfig::sameOrigin));
4042
return http.build();
4143
}
4244

spring-boot-project/spring-boot-test/src/test/java/org/springframework/boot/test/context/filter/ExcludeFilterApplicationContextInitializerTests.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.
@@ -40,7 +40,7 @@ class ExcludeFilterApplicationContextInitializerTests {
4040
void testConfigurationIsExcluded() {
4141
SpringApplication application = new SpringApplication(TestApplication.class);
4242
application.setWebApplicationType(WebApplicationType.NONE);
43-
AssertableApplicationContext applicationContext = AssertableApplicationContext.get(() -> application.run());
43+
AssertableApplicationContext applicationContext = AssertableApplicationContext.get(application::run);
4444
assertThat(applicationContext).hasSingleBean(TestApplication.class);
4545
assertThat(applicationContext).doesNotHaveBean(ExcludedTestConfiguration.class);
4646
}

spring-boot-project/spring-boot-testcontainers/src/test/java/org/springframework/boot/testcontainers/service/connection/ContainerConnectionDetailsFactoryTests.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ void getConnectionDetailsHasOrigin() {
111111
void getContainerWhenNotInitializedThrowsException() {
112112
TestContainerConnectionDetailsFactory factory = new TestContainerConnectionDetailsFactory();
113113
TestContainerConnectionDetails connectionDetails = getConnectionDetails(factory, this.source);
114-
assertThatIllegalStateException().isThrownBy(() -> connectionDetails.callGetContainer())
114+
assertThatIllegalStateException().isThrownBy(connectionDetails::callGetContainer)
115115
.withMessage("Container cannot be obtained before the connection details bean has been initialized");
116116
}
117117

spring-boot-project/spring-boot-tools/spring-boot-buildpack-platform/src/test/java/org/springframework/boot/buildpack/platform/docker/type/ImageReferenceTests.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -255,7 +255,7 @@ void randomWherePrefixIsNullThrowsException() {
255255
void inTaggedFormWhenHasDigestThrowsException() {
256256
ImageReference reference = ImageReference
257257
.of("ubuntu@sha256:6e9f67fa63b0323e9a1e587fd71c561ba48a034504fb804fd26fd8800039835d");
258-
assertThatIllegalStateException().isThrownBy(() -> reference.inTaggedForm())
258+
assertThatIllegalStateException().isThrownBy(reference::inTaggedForm)
259259
.withMessage(
260260
"Image reference 'docker.io/library/ubuntu@sha256:6e9f67fa63b0323e9a1e587fd71c561ba48a034504fb804fd26fd8800039835d' cannot contain a digest");
261261
}

spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/main/java/org/springframework/boot/gradle/dsl/SpringBootExtension.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ public void buildInfo(Action<BuildInfo> configurer) {
9393
tasks.named(JavaPlugin.CLASSES_TASK_NAME).configure((task) -> task.dependsOn(bootBuildInfo));
9494
bootBuildInfo.configure((buildInfo) -> buildInfo.getProperties()
9595
.getArtifact()
96-
.convention(this.project.provider(() -> determineArtifactBaseName())));
96+
.convention(this.project.provider(this::determineArtifactBaseName)));
9797
});
9898
if (configurer != null) {
9999
bootBuildInfo.configure(configurer);

spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/main/java/org/springframework/boot/gradle/plugin/SpringBootAotPlugin.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.
@@ -152,7 +152,7 @@ private void configureAotTask(Project project, SourceSet sourceSet, AbstractAot
152152
task.getClassesOutput()
153153
.set(project.getLayout().getBuildDirectory().dir("generated/" + sourceSet.getName() + "Classes"));
154154
task.getGroupId().set(project.provider(() -> String.valueOf(project.getGroup())));
155-
task.getArtifactId().set(project.provider(() -> project.getName()));
155+
task.getArtifactId().set(project.provider(project::getName));
156156
configureToolchainConvention(project, task);
157157
}
158158

spring-boot-project/spring-boot-tools/spring-boot-loader-classic/src/test/java/org/springframework/boot/loader/jar/JarFileTests.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.
@@ -719,7 +719,7 @@ void iteratorWhenClosedLater() throws IOException {
719719
Iterator<JarEntry> iterator = this.jarFile.iterator();
720720
iterator.next();
721721
this.jarFile.close();
722-
assertThatZipFileClosedIsThrownBy(() -> iterator.hasNext());
722+
assertThatZipFileClosedIsThrownBy(iterator::hasNext);
723723
}
724724

725725
@Test

spring-boot-project/spring-boot-tools/spring-boot-loader/src/test/java/org/springframework/boot/loader/jar/NestedJarFileTests.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,7 @@ void getCommentReturnsComment() throws IOException {
240240
void getCommentWhenClosedThrowsException() throws IOException {
241241
try (NestedJarFile jar = new NestedJarFile(this.file)) {
242242
jar.close();
243-
assertThatIllegalStateException().isThrownBy(() -> jar.getComment()).withMessage("Zip file closed");
243+
assertThatIllegalStateException().isThrownBy(jar::getComment).withMessage("Zip file closed");
244244
}
245245
}
246246

@@ -269,7 +269,7 @@ void sizeReturnsSize() throws IOException {
269269
void sizeWhenClosedThrowsException() throws Exception {
270270
try (NestedJarFile jar = new NestedJarFile(this.file)) {
271271
jar.close();
272-
assertThatIllegalStateException().isThrownBy(() -> jar.size()).withMessage("Zip file closed");
272+
assertThatIllegalStateException().isThrownBy(jar::size).withMessage("Zip file closed");
273273
}
274274
}
275275

spring-boot-project/spring-boot-tools/spring-boot-loader/src/test/java/org/springframework/boot/loader/net/protocol/jar/JarUrlConnectionTests.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.
@@ -242,7 +242,7 @@ void getPermissionReturnJarConnectionPermission() throws IOException {
242242
@Test
243243
void getInputStreamWhenNotNestedAndHasNoEntryThrowsException() throws Exception {
244244
JarUrlConnection connection = JarUrlConnection.open(JarUrl.create(this.file));
245-
assertThatIOException().isThrownBy(() -> connection.getInputStream()).withMessage("no entry name specified");
245+
assertThatIOException().isThrownBy(connection::getInputStream).withMessage("no entry name specified");
246246
}
247247

248248
@Test

spring-boot-project/spring-boot-tools/spring-boot-test-support/src/test/java/org/springframework/boot/testsupport/classpath/ModifiedClassPathExtensionForkParameterizedTests.java

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,14 @@ class ModifiedClassPathExtensionForkParameterizedTests {
3737
@ParameterizedTest
3838
@ValueSource(strings = { "one", "two", "three" })
3939
void testIsInvokedOnceForEachArgument(String argument) {
40-
switch (argument) {
41-
case "one" -> assertThat(arguments).isEmpty();
42-
case "two" -> assertThat(arguments).doesNotContain("two", "three");
43-
case "three" -> assertThat(arguments).doesNotContain("three");
40+
if (argument.equals("one")) {
41+
assertThat(arguments).isEmpty();
42+
}
43+
else if (argument.equals("two")) {
44+
assertThat(arguments).doesNotContain("two", "three");
45+
}
46+
else if (argument.equals("three")) {
47+
assertThat(arguments).doesNotContain("three");
4448
}
4549
arguments.add(argument);
4650
}

spring-boot-project/spring-boot/src/test/java/org/springframework/boot/context/properties/PropertySourcesDeducerTests.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.
@@ -79,7 +79,7 @@ void getPropertySourcesWhenUnavailableThrowsException() {
7979
Environment environment = mock(Environment.class);
8080
given(applicationContext.getEnvironment()).willReturn(environment);
8181
PropertySourcesDeducer deducer = new PropertySourcesDeducer(applicationContext);
82-
assertThatIllegalStateException().isThrownBy(() -> deducer.getPropertySources())
82+
assertThatIllegalStateException().isThrownBy(deducer::getPropertySources)
8383
.withMessage("Unable to obtain PropertySources from PropertySourcesPlaceholderConfigurer or Environment");
8484
}
8585

0 commit comments

Comments
 (0)