From e9997d4004fbf19382cfa9eabae790cf1e64dee8 Mon Sep 17 00:00:00 2001 From: Stephane Nicoll Date: Wed, 14 Sep 2022 14:35:17 +0200 Subject: [PATCH] Polish --- ...mpileWithTargetClassAccessClassLoader.java | 3 +++ .../generate/compile/DynamicClassLoader.java | 6 +++--- .../aot/test/generate/file/DynamicFile.java | 4 ++-- .../aot/test/generate/file/DynamicFiles.java | 3 +-- .../aot/test/generate/file/ResourceFile.java | 19 +++++++------------ .../aot/test/generate/file/ResourceFiles.java | 4 ++-- .../aot/test/generate/file/SourceFile.java | 8 +++----- .../aot/test/generate/file/SourceFiles.java | 2 +- .../aot/test/generate/file/package-info.java | 2 -- .../test/generate/compile/CompiledTests.java | 6 ++---- .../compile/DynamicJavaFileObjectTests.java | 2 +- .../generate/compile/TestCompilerTests.java | 2 +- .../generate/file/ResourceFilesTests.java | 2 +- .../test/generate/file/SourceFilesTests.java | 2 +- 14 files changed, 28 insertions(+), 37 deletions(-) diff --git a/spring-core-test/src/main/java/org/springframework/aot/test/generate/compile/CompileWithTargetClassAccessClassLoader.java b/spring-core-test/src/main/java/org/springframework/aot/test/generate/compile/CompileWithTargetClassAccessClassLoader.java index 01e2085b51e..c944995bb24 100644 --- a/spring-core-test/src/main/java/org/springframework/aot/test/generate/compile/CompileWithTargetClassAccessClassLoader.java +++ b/spring-core-test/src/main/java/org/springframework/aot/test/generate/compile/CompileWithTargetClassAccessClassLoader.java @@ -21,6 +21,8 @@ import java.io.InputStream; import java.net.URL; import java.util.Enumeration; +import org.springframework.lang.Nullable; + /** * {@link ClassLoader} implementation to support * {@link CompileWithTargetClassAccess @CompileWithTargetClassAccess}. @@ -74,6 +76,7 @@ final class CompileWithTargetClassAccessClassLoader extends ClassLoader { } @Override + @Nullable protected URL findResource(String name) { return this.testClassLoader.getResource(name); } diff --git a/spring-core-test/src/main/java/org/springframework/aot/test/generate/compile/DynamicClassLoader.java b/spring-core-test/src/main/java/org/springframework/aot/test/generate/compile/DynamicClassLoader.java index bec88b10d77..3154821cc5a 100644 --- a/spring-core-test/src/main/java/org/springframework/aot/test/generate/compile/DynamicClassLoader.java +++ b/spring-core-test/src/main/java/org/springframework/aot/test/generate/compile/DynamicClassLoader.java @@ -158,7 +158,7 @@ public class DynamicClassLoader extends ClassLoader { @Override - protected URLConnection openConnection(URL url) throws IOException { + protected URLConnection openConnection(URL url) { return new ResourceFileConnection(url, this.file); } @@ -177,11 +177,11 @@ public class DynamicClassLoader extends ClassLoader { @Override - public void connect() throws IOException { + public void connect() { } @Override - public InputStream getInputStream() throws IOException { + public InputStream getInputStream() { return new ByteArrayInputStream( this.file.getContent().getBytes(StandardCharsets.UTF_8)); } diff --git a/spring-core-test/src/main/java/org/springframework/aot/test/generate/file/DynamicFile.java b/spring-core-test/src/main/java/org/springframework/aot/test/generate/file/DynamicFile.java index 232eaf8f685..d770697961b 100644 --- a/spring-core-test/src/main/java/org/springframework/aot/test/generate/file/DynamicFile.java +++ b/spring-core-test/src/main/java/org/springframework/aot/test/generate/file/DynamicFile.java @@ -38,8 +38,8 @@ public abstract sealed class DynamicFile permits SourceFile, ResourceFile { protected DynamicFile(String path, String content) { - Assert.hasText(path, "Path must not be empty"); - Assert.hasText(content, "Content must not be empty"); + Assert.hasText(path, "'path' must not be empty"); + Assert.hasText(content, "'content' must not be empty"); this.path = path; this.content = content; } diff --git a/spring-core-test/src/main/java/org/springframework/aot/test/generate/file/DynamicFiles.java b/spring-core-test/src/main/java/org/springframework/aot/test/generate/file/DynamicFiles.java index c65ace25433..92cc7273115 100644 --- a/spring-core-test/src/main/java/org/springframework/aot/test/generate/file/DynamicFiles.java +++ b/spring-core-test/src/main/java/org/springframework/aot/test/generate/file/DynamicFiles.java @@ -38,8 +38,7 @@ import org.springframework.lang.Nullable; final class DynamicFiles implements Iterable { - private static final DynamicFiles NONE = new DynamicFiles<>( - Collections.emptyMap()); + private static final DynamicFiles NONE = new DynamicFiles<>(Collections.emptyMap()); private final Map files; diff --git a/spring-core-test/src/main/java/org/springframework/aot/test/generate/file/ResourceFile.java b/spring-core-test/src/main/java/org/springframework/aot/test/generate/file/ResourceFile.java index 67092d9dcab..9c8c21f986b 100644 --- a/spring-core-test/src/main/java/org/springframework/aot/test/generate/file/ResourceFile.java +++ b/spring-core-test/src/main/java/org/springframework/aot/test/generate/file/ResourceFile.java @@ -22,7 +22,6 @@ import java.nio.charset.StandardCharsets; import org.assertj.core.api.AssertProvider; import org.springframework.core.io.InputStreamSource; -import org.springframework.lang.Nullable; import org.springframework.util.FileCopyUtils; /** @@ -32,8 +31,7 @@ import org.springframework.util.FileCopyUtils; * @author Phillip Webb * @since 6.0 */ -public final class ResourceFile extends DynamicFile - implements AssertProvider { +public final class ResourceFile extends DynamicFile implements AssertProvider { private ResourceFile(String path, String content) { @@ -46,7 +44,7 @@ public final class ResourceFile extends DynamicFile * {@link CharSequence}. * @param path the relative path of the file or {@code null} to have the * path deduced - * @param charSequence a file containing the source contents + * @param charSequence a file containing the file contents * @return a {@link ResourceFile} instance */ public static ResourceFile of(String path, CharSequence charSequence) { @@ -56,13 +54,11 @@ public final class ResourceFile extends DynamicFile /** * Factory method to create a new {@link ResourceFile} from the given * {@link InputStreamSource}. - * @param path the relative path of the file or {@code null} to have the - * path deduced + * @param path the relative path of the file * @param inputStreamSource the source for the file - * @return a {@link SourceFile} instance + * @return a {@link ResourceFile} instance */ - public static ResourceFile of(@Nullable String path, - InputStreamSource inputStreamSource) { + public static ResourceFile of(String path, InputStreamSource inputStreamSource) { return of(path, appendable -> appendable.append(FileCopyUtils.copyToString( new InputStreamReader(inputStreamSource.getInputStream(), StandardCharsets.UTF_8)))); } @@ -70,10 +66,9 @@ public final class ResourceFile extends DynamicFile /** * Factory method to create a new {@link SourceFile} from the given * {@link WritableContent}. - * @param path the relative path of the file or {@code null} to have the - * path deduced + * @param path the relative path of the file * @param writableContent the content to write to the file - * @return a {@link SourceFile} instance + * @return a {@link ResourceFile} instance */ public static ResourceFile of(String path, WritableContent writableContent) { return new ResourceFile(path, toString(writableContent)); diff --git a/spring-core-test/src/main/java/org/springframework/aot/test/generate/file/ResourceFiles.java b/spring-core-test/src/main/java/org/springframework/aot/test/generate/file/ResourceFiles.java index 548a29efd9f..772524c62dd 100644 --- a/spring-core-test/src/main/java/org/springframework/aot/test/generate/file/ResourceFiles.java +++ b/spring-core-test/src/main/java/org/springframework/aot/test/generate/file/ResourceFiles.java @@ -111,7 +111,7 @@ public final class ResourceFiles implements Iterable { /** * Get the {@link ResourceFile} with the given - * {@code DynamicFile#getPath() path}. + * {@linkplain DynamicFile#getPath() path}. * @param path the path to find * @return a {@link ResourceFile} instance or {@code null} */ @@ -121,7 +121,7 @@ public final class ResourceFiles implements Iterable { } /** - * Return the single source file contained in the collection. + * Return the single {@link ResourceFile} contained in the collection. * @return the single file * @throws IllegalStateException if the collection doesn't contain exactly * one file diff --git a/spring-core-test/src/main/java/org/springframework/aot/test/generate/file/SourceFile.java b/spring-core-test/src/main/java/org/springframework/aot/test/generate/file/SourceFile.java index 8586c489fef..34f9c3f262d 100644 --- a/spring-core-test/src/main/java/org/springframework/aot/test/generate/file/SourceFile.java +++ b/spring-core-test/src/main/java/org/springframework/aot/test/generate/file/SourceFile.java @@ -35,9 +35,8 @@ import org.springframework.util.StringUtils; /** * {@link DynamicFile} that holds Java source code and provides - * {@link SourceFileAssert} support. Usually created from an AOT generated type, - * for example: - * + * {@link SourceFileAssert} support. Usually created from an AOT generated + * type, for example: *
  * SourceFile.of(generatedFile::writeTo)
  * 
@@ -45,8 +44,7 @@ import org.springframework.util.StringUtils; * @author Phillip Webb * @since 6.0 */ -public final class SourceFile extends DynamicFile - implements AssertProvider { +public final class SourceFile extends DynamicFile implements AssertProvider { private final String className; diff --git a/spring-core-test/src/main/java/org/springframework/aot/test/generate/file/SourceFiles.java b/spring-core-test/src/main/java/org/springframework/aot/test/generate/file/SourceFiles.java index 416c470520f..5aeb8ce0303 100644 --- a/spring-core-test/src/main/java/org/springframework/aot/test/generate/file/SourceFiles.java +++ b/spring-core-test/src/main/java/org/springframework/aot/test/generate/file/SourceFiles.java @@ -114,7 +114,7 @@ public final class SourceFiles implements Iterable { /** * Get the {@link SourceFile} with the given - * {@code DynamicFile#getPath() path}. + * {@linkplain DynamicFile#getPath() path}. * @param path the path to find * @return a {@link SourceFile} instance or {@code null} */ diff --git a/spring-core-test/src/main/java/org/springframework/aot/test/generate/file/package-info.java b/spring-core-test/src/main/java/org/springframework/aot/test/generate/file/package-info.java index 8559fb7d6c9..02e9edfe63a 100644 --- a/spring-core-test/src/main/java/org/springframework/aot/test/generate/file/package-info.java +++ b/spring-core-test/src/main/java/org/springframework/aot/test/generate/file/package-info.java @@ -1,7 +1,5 @@ /** * Support classes for running assertions on generated files. - * - * @author Stephane Nicoll */ @NonNullApi @NonNullFields diff --git a/spring-core-test/src/test/java/org/springframework/aot/test/generate/compile/CompiledTests.java b/spring-core-test/src/test/java/org/springframework/aot/test/generate/compile/CompiledTests.java index 183f270ae87..a5bb4a4571c 100644 --- a/spring-core-test/src/test/java/org/springframework/aot/test/generate/compile/CompiledTests.java +++ b/spring-core-test/src/test/java/org/springframework/aot/test/generate/compile/CompiledTests.java @@ -107,15 +107,13 @@ class CompiledTests { ResourceFile.of("META-INF/myfile1", "test1"), ResourceFile.of("META-INF/myfile2", "test2")); TestCompiler.forSystem().withResources(resourceFiles).compile( - compiled -> assertThatIllegalStateException().isThrownBy( - () -> compiled.getResourceFile())); + compiled -> assertThatIllegalStateException().isThrownBy(compiled::getResourceFile)); } @Test void getResourceFileWhenNoneThrowsException() { TestCompiler.forSystem().compile( - compiled -> assertThatIllegalStateException().isThrownBy( - () -> compiled.getResourceFile())); + compiled -> assertThatIllegalStateException().isThrownBy(compiled::getResourceFile)); } @Test diff --git a/spring-core-test/src/test/java/org/springframework/aot/test/generate/compile/DynamicJavaFileObjectTests.java b/spring-core-test/src/test/java/org/springframework/aot/test/generate/compile/DynamicJavaFileObjectTests.java index de5f6e2ddb5..b4f20fddde1 100644 --- a/spring-core-test/src/test/java/org/springframework/aot/test/generate/compile/DynamicJavaFileObjectTests.java +++ b/spring-core-test/src/test/java/org/springframework/aot/test/generate/compile/DynamicJavaFileObjectTests.java @@ -39,7 +39,7 @@ class DynamicJavaFileObjectTests { } @Test - void getCharContentReturnsContent() throws Exception { + void getCharContentReturnsContent() { DynamicJavaFileObject fileObject = new DynamicJavaFileObject(SourceFile.of(CONTENT)); assertThat(fileObject.getCharContent(true)).isEqualTo(CONTENT); } diff --git a/spring-core-test/src/test/java/org/springframework/aot/test/generate/compile/TestCompilerTests.java b/spring-core-test/src/test/java/org/springframework/aot/test/generate/compile/TestCompilerTests.java index c4217e27001..367b8666d7e 100644 --- a/spring-core-test/src/test/java/org/springframework/aot/test/generate/compile/TestCompilerTests.java +++ b/spring-core-test/src/test/java/org/springframework/aot/test/generate/compile/TestCompilerTests.java @@ -206,7 +206,7 @@ class TestCompilerTests { @Test @CompileWithTargetClassAccess - void compiledCodeCanAccessExistingPackagePrivateClassIfAnnotated() throws ClassNotFoundException, LinkageError { + void compiledCodeCanAccessExistingPackagePrivateClassIfAnnotated() throws LinkageError { SourceFiles sourceFiles = SourceFiles.of(SourceFile.of(""" package com.example; diff --git a/spring-core-test/src/test/java/org/springframework/aot/test/generate/file/ResourceFilesTests.java b/spring-core-test/src/test/java/org/springframework/aot/test/generate/file/ResourceFilesTests.java index 244a6358c95..724da255bc2 100644 --- a/spring-core-test/src/test/java/org/springframework/aot/test/generate/file/ResourceFilesTests.java +++ b/spring-core-test/src/test/java/org/springframework/aot/test/generate/file/ResourceFilesTests.java @@ -110,7 +110,7 @@ class ReResourceFilesTests { @Test void getSingleWhenHasMultipleFilesThrowsException() { ResourceFiles resourceFiles = ResourceFiles.of(RESOURCE_FILE_1, RESOURCE_FILE_2); - assertThatIllegalStateException().isThrownBy(() -> resourceFiles.getSingle()); + assertThatIllegalStateException().isThrownBy(resourceFiles::getSingle); } @Test diff --git a/spring-core-test/src/test/java/org/springframework/aot/test/generate/file/SourceFilesTests.java b/spring-core-test/src/test/java/org/springframework/aot/test/generate/file/SourceFilesTests.java index 994538a21e8..f83b79a3707 100644 --- a/spring-core-test/src/test/java/org/springframework/aot/test/generate/file/SourceFilesTests.java +++ b/spring-core-test/src/test/java/org/springframework/aot/test/generate/file/SourceFilesTests.java @@ -114,7 +114,7 @@ class SourceFilesTests { @Test void getSingleWhenHasMultipleFilesThrowsException() { SourceFiles sourceFiles = SourceFiles.of(SOURCE_FILE_1, SOURCE_FILE_2); - assertThatIllegalStateException().isThrownBy(() -> sourceFiles.getSingle()); + assertThatIllegalStateException().isThrownBy(sourceFiles::getSingle); } @Test