From a04285145c127e06de982bbcbc5bc3b4712f85d8 Mon Sep 17 00:00:00 2001 From: Sam Snyder Date: Mon, 6 Nov 2023 22:18:37 -0800 Subject: [PATCH] Actionable error message when test attempts to access a non-existent data table. This is usually a minor mistake when the test author provides the type of the DataTable, when actually they need to provide the type of the row. --- .../src/main/java/org/openrewrite/test/RecipeSpec.java | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/rewrite-test/src/main/java/org/openrewrite/test/RecipeSpec.java b/rewrite-test/src/main/java/org/openrewrite/test/RecipeSpec.java index 90c43fbb0ea..24139d4579b 100644 --- a/rewrite-test/src/main/java/org/openrewrite/test/RecipeSpec.java +++ b/rewrite-test/src/main/java/org/openrewrite/test/RecipeSpec.java @@ -34,6 +34,7 @@ import java.nio.file.Path; import java.util.*; import java.util.function.Function; +import java.util.stream.Collectors; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.fail; @@ -209,7 +210,14 @@ public RecipeSpec dataTable(Class rowType, UncheckedConsumer> ext return; } } - fail("No data table found with row type " + rowType); + String message = "No data table found with row type: " + rowType; + Set> tables = run.getDataTables().keySet(); + if (!tables.isEmpty()) { + message += "\nFound data tables row type(s): " + tables.stream() + .map(it -> it.getType().getName().replace("$", ".")) + .collect(Collectors.joining(",")); + } + fail(message); }); }