From 46657035e394a2adfc925eed4d6219d01c43a59b Mon Sep 17 00:00:00 2001 From: Tim te Beek Date: Mon, 14 Oct 2024 13:51:58 +0200 Subject: [PATCH] Link to FAQ on missing types in tests --- .../java/org/openrewrite/java/Assertions.java | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/rewrite-java/src/main/java/org/openrewrite/java/Assertions.java b/rewrite-java/src/main/java/org/openrewrite/java/Assertions.java index a3996085614..19142844e33 100644 --- a/rewrite-java/src/main/java/org/openrewrite/java/Assertions.java +++ b/rewrite-java/src/main/java/org/openrewrite/java/Assertions.java @@ -28,7 +28,10 @@ import org.openrewrite.java.search.FindMissingTypes; import org.openrewrite.java.tree.J; import org.openrewrite.java.tree.JavaSourceFile; -import org.openrewrite.test.*; +import org.openrewrite.test.SourceSpec; +import org.openrewrite.test.SourceSpecs; +import org.openrewrite.test.TypeValidation; +import org.openrewrite.test.UncheckedConsumer; import java.nio.file.Path; import java.util.*; @@ -61,7 +64,7 @@ public static SourceFile validateTypes(SourceFile source, TypeValidation typeVal private static void assertValidTypes(TypeValidation typeValidation, J sf) { if (typeValidation.identifiers() || typeValidation.methodInvocations() || typeValidation.methodDeclarations() || typeValidation.classDeclarations() || - typeValidation.constructorInvocations()) { + typeValidation.constructorInvocations()) { List missingTypeResults = FindMissingTypes.findMissingTypes(sf); missingTypeResults = missingTypeResults.stream() .filter(missingType -> { @@ -83,8 +86,12 @@ private static void assertValidTypes(TypeValidation typeValidation, J sf) { }) .collect(Collectors.toList()); if (!missingTypeResults.isEmpty()) { - throw new IllegalStateException("LST contains missing or invalid type information\n" + missingTypeResults.stream().map(v -> v.getPath() + "\n" + v.getPrintedTree()) - .collect(Collectors.joining("\n\n"))); + String missingTypes = missingTypeResults.stream() + .map(v -> v.getPath() + "\n" + v.getPrintedTree()) + .collect(Collectors.joining("\n\n")); + throw new IllegalStateException( + "LST contains missing or invalid type information\n" + missingTypes + + "\nhttps://docs.openrewrite.org/reference/faq#im-seeing-lst-contains-missing-or-invalid-type-information-in-my-recipe-unit-tests-how-to-resolve"); } } }