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";

0 commit comments

Comments
 (0)