Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Link to FAQ on missing types in tests #4580

Merged
merged 1 commit into from
Oct 14, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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