Using modern Java features

This commit is contained in:
Krzysztof Krason
2023-01-20 16:45:41 +01:00
committed by Josh Cummings
parent 7e01ebdd92
commit 9b603b99ab
72 changed files with 206 additions and 402 deletions

View File

@@ -382,7 +382,7 @@ public class RequestCacheConfigurerTests {
.anyRequest().authenticated()
)
.formLogin(Customizer.withDefaults())
.requestCache((cache) -> cache.disable());
.requestCache(RequestCacheConfigurer::disable);
// @formatter:on
return http.build();
}

View File

@@ -556,9 +556,7 @@ public class SessionManagementConfigurerTests {
.sessionManagement((sessionManagement) ->
sessionManagement
.requireExplicitAuthenticationStrategy(false)
.sessionFixation((sessionFixation) ->
sessionFixation.newSession()
)
.sessionFixation(SessionManagementConfigurer.SessionFixationConfigurer::newSession)
)
.httpBasic(withDefaults());
// @formatter:on

View File

@@ -868,8 +868,7 @@ public class OAuth2ResourceServerConfigurerTests {
context.registerBean("decoderTwo", JwtDecoder.class, () -> decoder);
this.spring.context(context).autowire();
OAuth2ResourceServerConfigurer.JwtConfigurer jwtConfigurer = new OAuth2ResourceServerConfigurer(context).jwt();
assertThatExceptionOfType(NoUniqueBeanDefinitionException.class)
.isThrownBy(() -> jwtConfigurer.getJwtDecoder());
assertThatExceptionOfType(NoUniqueBeanDefinitionException.class).isThrownBy(jwtConfigurer::getJwtDecoder);
}
@Test
@@ -1885,9 +1884,7 @@ public class OAuth2ResourceServerConfigurerTests {
.anyRequest().authenticated()
)
.oauth2Login(withDefaults())
.oauth2ResourceServer((oauth2) -> oauth2
.jwt()
);
.oauth2ResourceServer(OAuth2ResourceServerConfigurer::jwt);
return http.build();
// @formatter:on
}

View File

@@ -27,8 +27,7 @@ public class SyncExecutorSubscribableChannelPostProcessor implements BeanPostPro
@Override
public Object postProcessBeforeInitialization(Object bean, String beanName) throws BeansException {
if (bean instanceof ExecutorSubscribableChannel) {
ExecutorSubscribableChannel original = (ExecutorSubscribableChannel) bean;
if (bean instanceof ExecutorSubscribableChannel original) {
ExecutorSubscribableChannel channel = new ExecutorSubscribableChannel();
channel.setInterceptors(original.getInterceptors());
return channel;

View File

@@ -627,9 +627,8 @@ public class WebSocketMessageBrokerSecurityConfigurationTests {
public boolean doHandshake(ServerHttpRequest request, ServerHttpResponse response, WebSocketHandler wsHandler,
Map<String, Object> attributes) throws HandshakeFailureException {
this.attributes = attributes;
if (wsHandler instanceof SockJsWebSocketHandler) {
if (wsHandler instanceof SockJsWebSocketHandler sockJs) {
// work around SPR-12716
SockJsWebSocketHandler sockJs = (SockJsWebSocketHandler) wsHandler;
WebSocketServerSockJsSession session = (WebSocketServerSockJsSession) ReflectionTestUtils
.getField(sockJs, "sockJsSession");
this.attributes = session.getAttributes();

View File

@@ -58,8 +58,7 @@ public class XmlNode {
public Optional<XmlNode> parent() {
// @formatter:off
return Optional.ofNullable(this.node.getParentNode())
.map((parent) -> new XmlNode(parent));
return Optional.ofNullable(this.node.getParentNode()).map(XmlNode::new);
// @formatter:on
}
@@ -67,7 +66,7 @@ public class XmlNode {
// @formatter:off
return Optional.ofNullable(this.node.getAttributes())
.map((attrs) -> attrs.getNamedItem(name))
.map((attr) -> attr.getTextContent())
.map(Node::getTextContent)
.orElse(null);
// @formatter:on
}

View File

@@ -31,7 +31,7 @@ public class SpringTestContextExtension implements BeforeEachCallback, AfterEach
@Override
public void afterEach(ExtensionContext context) throws Exception {
TestSecurityContextHolder.clearContext();
getContexts(context.getRequiredTestInstance()).forEach((springTestContext) -> springTestContext.close());
getContexts(context.getRequiredTestInstance()).forEach(SpringTestContext::close);
}
@Override