diff --git a/src/main/java/org/openrewrite/javascript/Assertions.java b/src/main/java/org/openrewrite/javascript/Assertions.java index 3f5b419f..c601c824 100644 --- a/src/main/java/org/openrewrite/javascript/Assertions.java +++ b/src/main/java/org/openrewrite/javascript/Assertions.java @@ -25,7 +25,9 @@ import org.openrewrite.javascript.tree.JS; import org.openrewrite.test.SourceSpec; import org.openrewrite.test.SourceSpecs; +import org.opentest4j.AssertionFailedError; +import java.util.Optional; import java.util.function.Consumer; import static org.assertj.core.api.Assertions.assertThat; @@ -91,12 +93,14 @@ public Space visitSpace(Space space, Space.Location loc, Integer integer) { new JavaScriptVisitor() { @Override - public @Nullable J preVisit(J tree, Integer integer) { - if (tree instanceof J.Unknown) { - ((J.Unknown) tree).getSource().getMarkers().findFirst(ParseExceptionResult.class) - .ifPresent(result -> assertThat(result.getMessage()).isEqualTo("")); + public J visitUnknownSource(J.Unknown.Source source, Integer integer) { + Optional result = source.getMarkers().findFirst(ParseExceptionResult.class); + if (result.isPresent()) { + System.out.println(result.get().getMessage()); + throw new AssertionFailedError("Parsing error, J.Unknown detected"); + } else { + throw new UnsupportedOperationException("A J.Unknown should always have a parse exception result."); } - return super.preVisit(tree, integer); } }.visit(cu, 0); });