diff --git a/spring-core-test/src/main/java/org/springframework/aot/test/generator/compile/CompileWithTargetClassAccess.java b/spring-core-test/src/main/java/org/springframework/aot/test/generator/compile/CompileWithTargetClassAccess.java index 471b3f805ae..d4141ae4feb 100644 --- a/spring-core-test/src/main/java/org/springframework/aot/test/generator/compile/CompileWithTargetClassAccess.java +++ b/spring-core-test/src/main/java/org/springframework/aot/test/generator/compile/CompileWithTargetClassAccess.java @@ -37,5 +37,4 @@ import org.junit.jupiter.api.extension.ExtendWith; @Documented @ExtendWith(CompileWithTargetClassAccessExtension.class) public @interface CompileWithTargetClassAccess { - } diff --git a/spring-core-test/src/main/java/org/springframework/aot/test/generator/compile/CompileWithTargetClassAccessClassLoader.java b/spring-core-test/src/main/java/org/springframework/aot/test/generator/compile/CompileWithTargetClassAccessClassLoader.java index 8114a6cdf10..141ba2f4e1d 100644 --- a/spring-core-test/src/main/java/org/springframework/aot/test/generator/compile/CompileWithTargetClassAccessClassLoader.java +++ b/spring-core-test/src/main/java/org/springframework/aot/test/generator/compile/CompileWithTargetClassAccessClassLoader.java @@ -63,6 +63,7 @@ final class CompileWithTargetClassAccessClassLoader extends ClassLoader { } + // Invoked reflectively by DynamicClassLoader.findDefineClassMethod(ClassLoader) Class defineClassWithTargetAccess(String name, byte[] b, int off, int len) { return super.defineClass(name, b, off, len); } diff --git a/spring-core-test/src/main/java/org/springframework/aot/test/generator/compile/CompileWithTargetClassAccessExtension.java b/spring-core-test/src/main/java/org/springframework/aot/test/generator/compile/CompileWithTargetClassAccessExtension.java index a221b60f8a4..c67e5816155 100644 --- a/spring-core-test/src/main/java/org/springframework/aot/test/generator/compile/CompileWithTargetClassAccessExtension.java +++ b/spring-core-test/src/main/java/org/springframework/aot/test/generator/compile/CompileWithTargetClassAccessExtension.java @@ -161,6 +161,7 @@ class CompileWithTargetClassAccessExtension implements InvocationInterceptor { } + @FunctionalInterface interface Action { static Action NONE = () -> { diff --git a/spring-core-test/src/main/java/org/springframework/aot/test/generator/compile/Compiled.java b/spring-core-test/src/main/java/org/springframework/aot/test/generator/compile/Compiled.java index 527867d6a0b..307b27d74d2 100644 --- a/spring-core-test/src/main/java/org/springframework/aot/test/generator/compile/Compiled.java +++ b/spring-core-test/src/main/java/org/springframework/aot/test/generator/compile/Compiled.java @@ -36,7 +36,6 @@ import org.springframework.util.Assert; */ public class Compiled { - private final ClassLoader classLoader; private final SourceFiles sourceFiles; @@ -47,8 +46,7 @@ public class Compiled { private List> compiledClasses; - Compiled(ClassLoader classLoader, SourceFiles sourceFiles, - ResourceFiles resourceFiles) { + Compiled(ClassLoader classLoader, SourceFiles sourceFiles, ResourceFiles resourceFiles) { this.classLoader = classLoader; this.sourceFiles = sourceFiles; this.resourceFiles = resourceFiles; diff --git a/spring-core-test/src/main/java/org/springframework/aot/test/generator/compile/DynamicClassFileObject.java b/spring-core-test/src/main/java/org/springframework/aot/test/generator/compile/DynamicClassFileObject.java index e1df45396a7..b7ceb6b41c7 100644 --- a/spring-core-test/src/main/java/org/springframework/aot/test/generator/compile/DynamicClassFileObject.java +++ b/spring-core-test/src/main/java/org/springframework/aot/test/generator/compile/DynamicClassFileObject.java @@ -35,8 +35,7 @@ class DynamicClassFileObject extends SimpleJavaFileObject { DynamicClassFileObject(String className) { - super(URI.create("class:///" + className.replace('.', '/') + ".class"), - Kind.CLASS); + super(URI.create("class:///" + className.replace('.', '/') + ".class"), Kind.CLASS); } diff --git a/spring-core-test/src/main/java/org/springframework/aot/test/generator/compile/DynamicClassLoader.java b/spring-core-test/src/main/java/org/springframework/aot/test/generator/compile/DynamicClassLoader.java index b1e2c4cd601..6d2301842cc 100644 --- a/spring-core-test/src/main/java/org/springframework/aot/test/generator/compile/DynamicClassLoader.java +++ b/spring-core-test/src/main/java/org/springframework/aot/test/generator/compile/DynamicClassLoader.java @@ -184,7 +184,6 @@ public class DynamicClassLoader extends ClassLoader { public InputStream getInputStream() throws IOException { return new ByteArrayInputStream( this.file.getContent().getBytes(StandardCharsets.UTF_8)); - } } diff --git a/spring-core-test/src/main/java/org/springframework/aot/test/generator/compile/TestCompiler.java b/spring-core-test/src/main/java/org/springframework/aot/test/generator/compile/TestCompiler.java index ea59603fa07..7924bde0d05 100644 --- a/spring-core-test/src/main/java/org/springframework/aot/test/generator/compile/TestCompiler.java +++ b/spring-core-test/src/main/java/org/springframework/aot/test/generator/compile/TestCompiler.java @@ -103,12 +103,11 @@ public final class TestCompiler { */ public TestCompiler withFiles(InMemoryGeneratedFiles generatedFiles) { List sourceFiles = new ArrayList<>(); - generatedFiles.getGeneratedFiles(Kind.SOURCE).forEach((path, - inputStreamSource) -> sourceFiles.add(SourceFile.of(inputStreamSource))); + generatedFiles.getGeneratedFiles(Kind.SOURCE).forEach( + (path, inputStreamSource) -> sourceFiles.add(SourceFile.of(inputStreamSource))); List resourceFiles = new ArrayList<>(); - generatedFiles.getGeneratedFiles(Kind.RESOURCE) - .forEach((path, inputStreamSource) -> resourceFiles - .add(ResourceFile.of(path, inputStreamSource))); + generatedFiles.getGeneratedFiles(Kind.RESOURCE).forEach( + (path, inputStreamSource) -> resourceFiles.add(ResourceFile.of(path, inputStreamSource))); return withSources(sourceFiles).withResources(resourceFiles); } @@ -256,7 +255,7 @@ public final class TestCompiler { } catch (IllegalAccessError ex) { throw new IllegalAccessError(ex.getMessage() + ". " + - "For non-public access ensure annotate your tests with @CompileWithTargetClassAccess"); + "For non-public access ensure you annotate your test class or test method with @CompileWithTargetClassAccess"); } finally { Thread.currentThread().setContextClassLoader(previousClassLoader); @@ -318,12 +317,12 @@ public final class TestCompiler { @Override public void report(Diagnostic diagnostic) { if (diagnostic.getKind() == Diagnostic.Kind.ERROR) { - this.message.append("\n"); + this.message.append('\n'); this.message.append(diagnostic.getMessage(Locale.getDefault())); - this.message.append(" "); + this.message.append(' '); this.message.append(diagnostic.getSource().getName()); - this.message.append(" "); - this.message.append(diagnostic.getLineNumber()).append(":") + this.message.append(' '); + this.message.append(diagnostic.getLineNumber()).append(':') .append(diagnostic.getColumnNumber()); } } diff --git a/spring-core-test/src/test/java/org/springframework/aot/test/generator/compile/TestCompilerTests.java b/spring-core-test/src/test/java/org/springframework/aot/test/generator/compile/TestCompilerTests.java index f808e8b4ee6..eb471210294 100644 --- a/spring-core-test/src/test/java/org/springframework/aot/test/generator/compile/TestCompilerTests.java +++ b/spring-core-test/src/test/java/org/springframework/aot/test/generator/compile/TestCompilerTests.java @@ -42,6 +42,8 @@ import static org.assertj.core.api.Assertions.assertThatExceptionOfType; /** * Tests for {@link TestCompiler}. + * + * @since 6.0 * @author Phillip Webb * @author Andy Wilkinson * @author Scott Frederick @@ -89,6 +91,7 @@ class TestCompilerTests { } """; + @Test @SuppressWarnings("unchecked") void compileWhenHasDifferentClassesWithSameClassNameCompilesBoth() {