From f0f450a18dec7639ce8b967ed26c78cf777d4f7e Mon Sep 17 00:00:00 2001 From: Sam Brannen Date: Mon, 7 Jun 2021 13:24:46 +0200 Subject: [PATCH] Polishing --- .../factory/config/YamlProcessorTests.java | 1 + .../connection/CachingConnectionFactory.java | 1 + .../Jetty10WebSocketHandlerAdapter.java | 7 +++-- .../function/SseServerResponseTests.java | 8 +++--- .../PrincipalMethodArgumentResolverTests.java | 26 +++++++------------ .../resource/ResourceUrlProviderTests.java | 1 + 6 files changed, 19 insertions(+), 25 deletions(-) diff --git a/spring-beans/src/test/java/org/springframework/beans/factory/config/YamlProcessorTests.java b/spring-beans/src/test/java/org/springframework/beans/factory/config/YamlProcessorTests.java index 50c7f903a40..edb1f994f33 100644 --- a/spring-beans/src/test/java/org/springframework/beans/factory/config/YamlProcessorTests.java +++ b/spring-beans/src/test/java/org/springframework/beans/factory/config/YamlProcessorTests.java @@ -141,6 +141,7 @@ class YamlProcessorTests { } @Test + @SuppressWarnings("unchecked") void standardTypesSupportedByDefault() throws Exception { setYaml("value: !!set\n ? first\n ? second"); this.processor.process((properties, map) -> { diff --git a/spring-jms/src/main/java/org/springframework/jms/connection/CachingConnectionFactory.java b/spring-jms/src/main/java/org/springframework/jms/connection/CachingConnectionFactory.java index d0a19fa5cf6..d9b8027f1aa 100644 --- a/spring-jms/src/main/java/org/springframework/jms/connection/CachingConnectionFactory.java +++ b/spring-jms/src/main/java/org/springframework/jms/connection/CachingConnectionFactory.java @@ -423,6 +423,7 @@ public class CachingConnectionFactory extends SingleConnectionFactory { return new CachedMessageProducer(producer); } + @SuppressWarnings("resource") private MessageConsumer getCachedConsumer(Destination dest, @Nullable String selector, @Nullable Boolean noLocal, @Nullable String subscription, boolean durable) throws JMSException { diff --git a/spring-webflux/src/main/java/org/springframework/web/reactive/socket/adapter/Jetty10WebSocketHandlerAdapter.java b/spring-webflux/src/main/java/org/springframework/web/reactive/socket/adapter/Jetty10WebSocketHandlerAdapter.java index 02358a7bf9d..5b88fab7977 100644 --- a/spring-webflux/src/main/java/org/springframework/web/reactive/socket/adapter/Jetty10WebSocketHandlerAdapter.java +++ b/spring-webflux/src/main/java/org/springframework/web/reactive/socket/adapter/Jetty10WebSocketHandlerAdapter.java @@ -48,9 +48,6 @@ import org.springframework.web.reactive.socket.WebSocketSession; @WebSocket public class Jetty10WebSocketHandlerAdapter { - private static final ByteBuffer EMPTY_PAYLOAD = ByteBuffer.wrap(new byte[0]); - - private final WebSocketHandler delegateHandler; private final Function sessionFactory; @@ -97,7 +94,9 @@ public class Jetty10WebSocketHandlerAdapter { // TODO: onWebSocketFrame can't be declared without compiling against Jetty 10 // Jetty 10: org.eclipse.jetty.websocket.api.Frame // Jetty 9: org.eclipse.jetty.websocket.api.extensions.Frame - +// +// private static final ByteBuffer EMPTY_PAYLOAD = ByteBuffer.wrap(new byte[0]); +// // @OnWebSocketFrame // public void onWebSocketFrame(Frame frame) { // if (this.delegateSession != null) { diff --git a/spring-webmvc/src/test/java/org/springframework/web/servlet/function/SseServerResponseTests.java b/spring-webmvc/src/test/java/org/springframework/web/servlet/function/SseServerResponseTests.java index ca035489fb1..0b9aff9d27d 100644 --- a/spring-webmvc/src/test/java/org/springframework/web/servlet/function/SseServerResponseTests.java +++ b/spring-webmvc/src/test/java/org/springframework/web/servlet/function/SseServerResponseTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2020 the original author or authors. + * Copyright 2002-2021 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -90,8 +90,7 @@ class SseServerResponseTests { } @Test - public void builder() throws Exception { - String body = "foo bar"; + void builder() throws Exception { ServerResponse response = ServerResponse.sse(sse -> { try { sse.id("id") @@ -132,14 +131,15 @@ class SseServerResponseTests { this.age = age; } + @SuppressWarnings("unused") public String getName() { return this.name; } + @SuppressWarnings("unused") public int getAge() { return this.age; } } - } diff --git a/spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/method/annotation/PrincipalMethodArgumentResolverTests.java b/spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/method/annotation/PrincipalMethodArgumentResolverTests.java index 4fa489195c8..c32813c40cc 100644 --- a/spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/method/annotation/PrincipalMethodArgumentResolverTests.java +++ b/spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/method/annotation/PrincipalMethodArgumentResolverTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2020 the original author or authors. + * Copyright 2002-2021 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -30,7 +30,6 @@ import org.junit.jupiter.api.Test; import org.springframework.core.MethodParameter; import org.springframework.web.context.request.ServletWebRequest; -import org.springframework.web.method.support.ModelAndViewContainer; import org.springframework.web.testfixture.servlet.MockHttpServletRequest; import org.springframework.web.testfixture.servlet.MockHttpServletResponse; @@ -41,32 +40,25 @@ import static org.assertj.core.api.Assertions.assertThat; * * @author Rossen Stoyanchev */ -public class PrincipalMethodArgumentResolverTests { +class PrincipalMethodArgumentResolverTests { - private PrincipalMethodArgumentResolver resolver; + private PrincipalMethodArgumentResolver resolver = new PrincipalMethodArgumentResolver(); - private ModelAndViewContainer mavContainer; + private MockHttpServletRequest servletRequest = new MockHttpServletRequest("GET", ""); - private MockHttpServletRequest servletRequest; - - private ServletWebRequest webRequest; + private ServletWebRequest webRequest = new ServletWebRequest(servletRequest, new MockHttpServletResponse()); private Method method; @BeforeEach - public void setup() throws Exception { - resolver = new PrincipalMethodArgumentResolver(); - mavContainer = new ModelAndViewContainer(); - servletRequest = new MockHttpServletRequest("GET", ""); - webRequest = new ServletWebRequest(servletRequest, new MockHttpServletResponse()); - + void setup() throws Exception { method = getClass().getMethod("supportedParams", ServletRequest.class, Principal.class); } @Test - public void principal() throws Exception { + void principal() throws Exception { Principal principal = () -> "Foo"; servletRequest.setUserPrincipal(principal); @@ -78,7 +70,7 @@ public class PrincipalMethodArgumentResolverTests { } @Test - public void principalAsNull() throws Exception { + void principalAsNull() throws Exception { MethodParameter principalParameter = new MethodParameter(method, 1); assertThat(resolver.supportsParameter(principalParameter)).as("Principal not supported").isTrue(); @@ -87,7 +79,7 @@ public class PrincipalMethodArgumentResolverTests { } @Test // gh-25780 - public void annotatedPrincipal() throws Exception { + void annotatedPrincipal() throws Exception { Principal principal = () -> "Foo"; servletRequest.setUserPrincipal(principal); Method principalMethod = getClass().getMethod("supportedParamsWithAnnotatedPrincipal", Principal.class); diff --git a/spring-webmvc/src/test/java/org/springframework/web/servlet/resource/ResourceUrlProviderTests.java b/spring-webmvc/src/test/java/org/springframework/web/servlet/resource/ResourceUrlProviderTests.java index b3c719ad732..516edf06eb2 100644 --- a/spring-webmvc/src/test/java/org/springframework/web/servlet/resource/ResourceUrlProviderTests.java +++ b/spring-webmvc/src/test/java/org/springframework/web/servlet/resource/ResourceUrlProviderTests.java @@ -151,6 +151,7 @@ public class ResourceUrlProviderTests { } @Test + @SuppressWarnings("resource") void initializeOnCurrentContext() { AnnotationConfigWebApplicationContext parentContext = new AnnotationConfigWebApplicationContext(); parentContext.setServletContext(new MockServletContext());