Skip to content

Commit

Permalink
Link to FAQ on missing types in tests (#4580)
Browse files Browse the repository at this point in the history
  • Loading branch information
timtebeek authored Oct 14, 2024
1 parent 243bd20 commit 5b0fa6d
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions rewrite-java/src/main/java/org/openrewrite/java/Assertions.java
Original file line number Diff line number Diff line change
Expand Up @@ -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.*;
Expand Down Expand Up @@ -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<FindMissingTypes.MissingTypeResult> missingTypeResults = FindMissingTypes.findMissingTypes(sf);
missingTypeResults = missingTypeResults.stream()
.filter(missingType -> {
Expand All @@ -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");
}
}
}
Expand Down

0 comments on commit 5b0fa6d

Please sign in to comment.