From d03ab7953114b39f56ead049d1f66c4f93fa9d0d Mon Sep 17 00:00:00 2001 From: Sam Brannen Date: Mon, 11 Nov 2019 15:16:07 +0100 Subject: [PATCH] Polish contribution See gh-23970 --- .../web/reactive/resource/GzipSupport.java | 17 ++++++++++------- .../web/servlet/resource/GzipSupport.java | 17 ++++++++++------- 2 files changed, 20 insertions(+), 14 deletions(-) diff --git a/spring-webflux/src/test/java/org/springframework/web/reactive/resource/GzipSupport.java b/spring-webflux/src/test/java/org/springframework/web/reactive/resource/GzipSupport.java index 238c0a17e7..76af75c05b 100644 --- a/spring-webflux/src/test/java/org/springframework/web/reactive/resource/GzipSupport.java +++ b/spring-webflux/src/test/java/org/springframework/web/reactive/resource/GzipSupport.java @@ -31,7 +31,6 @@ import org.junit.jupiter.api.extension.ExtensionContext; import org.junit.jupiter.api.extension.ExtensionContext.Namespace; import org.junit.jupiter.api.extension.ExtensionContext.Store; import org.junit.jupiter.api.extension.ParameterContext; -import org.junit.jupiter.api.extension.ParameterResolutionException; import org.junit.jupiter.api.extension.ParameterResolver; import org.springframework.core.io.ClassPathResource; @@ -39,11 +38,17 @@ import org.springframework.core.io.FileSystemResource; import org.springframework.core.io.Resource; import org.springframework.util.FileCopyUtils; +/** + * @author Andy Wilkinson + * @since 5.2.2 + */ class GzipSupport implements AfterEachCallback, ParameterResolver { + private static final Namespace namespace = Namespace.create(GzipSupport.class); + @Override public void afterEach(ExtensionContext context) throws Exception { - GzippedFiles gzippedFiles = getStore(context).get(GzippedFiles.class, GzippedFiles.class); + GzippedFiles gzippedFiles = getStore(context).remove(GzippedFiles.class, GzippedFiles.class); if (gzippedFiles != null) { for (File gzippedFile: gzippedFiles.created) { gzippedFile.delete(); @@ -52,19 +57,17 @@ class GzipSupport implements AfterEachCallback, ParameterResolver { } @Override - public boolean supportsParameter(ParameterContext parameterContext, ExtensionContext extensionContext) - throws ParameterResolutionException { + public boolean supportsParameter(ParameterContext parameterContext, ExtensionContext extensionContext) { return parameterContext.getParameter().getType().equals(GzippedFiles.class); } @Override - public Object resolveParameter(ParameterContext parameterContext, ExtensionContext extensionContext) - throws ParameterResolutionException { + public Object resolveParameter(ParameterContext parameterContext, ExtensionContext extensionContext) { return getStore(extensionContext).getOrComputeIfAbsent(GzippedFiles.class); } private Store getStore(ExtensionContext extensionContext) { - return extensionContext.getStore(Namespace.create(getClass())); + return extensionContext.getStore(namespace); } static class GzippedFiles { diff --git a/spring-webmvc/src/test/java/org/springframework/web/servlet/resource/GzipSupport.java b/spring-webmvc/src/test/java/org/springframework/web/servlet/resource/GzipSupport.java index 598cd38cb4..8c1e7ea46c 100644 --- a/spring-webmvc/src/test/java/org/springframework/web/servlet/resource/GzipSupport.java +++ b/spring-webmvc/src/test/java/org/springframework/web/servlet/resource/GzipSupport.java @@ -31,7 +31,6 @@ import org.junit.jupiter.api.extension.ExtensionContext; import org.junit.jupiter.api.extension.ExtensionContext.Namespace; import org.junit.jupiter.api.extension.ExtensionContext.Store; import org.junit.jupiter.api.extension.ParameterContext; -import org.junit.jupiter.api.extension.ParameterResolutionException; import org.junit.jupiter.api.extension.ParameterResolver; import org.springframework.core.io.ClassPathResource; @@ -39,11 +38,17 @@ import org.springframework.core.io.FileSystemResource; import org.springframework.core.io.Resource; import org.springframework.util.FileCopyUtils; +/** + * @author Andy Wilkinson + * @since 5.2.2 + */ class GzipSupport implements AfterEachCallback, ParameterResolver { + private static final Namespace namespace = Namespace.create(GzipSupport.class); + @Override public void afterEach(ExtensionContext context) throws Exception { - GzippedFiles gzippedFiles = getStore(context).get(GzippedFiles.class, GzippedFiles.class); + GzippedFiles gzippedFiles = getStore(context).remove(GzippedFiles.class, GzippedFiles.class); if (gzippedFiles != null) { for (File gzippedFile: gzippedFiles.created) { gzippedFile.delete(); @@ -52,19 +57,17 @@ class GzipSupport implements AfterEachCallback, ParameterResolver { } @Override - public boolean supportsParameter(ParameterContext parameterContext, ExtensionContext extensionContext) - throws ParameterResolutionException { + public boolean supportsParameter(ParameterContext parameterContext, ExtensionContext extensionContext) { return parameterContext.getParameter().getType().equals(GzippedFiles.class); } @Override - public Object resolveParameter(ParameterContext parameterContext, ExtensionContext extensionContext) - throws ParameterResolutionException { + public Object resolveParameter(ParameterContext parameterContext, ExtensionContext extensionContext) { return getStore(extensionContext).getOrComputeIfAbsent(GzippedFiles.class); } private Store getStore(ExtensionContext extensionContext) { - return extensionContext.getStore(Namespace.create(getClass())); + return extensionContext.getStore(namespace); } static class GzippedFiles {