Skip to content

Commit a042851

Browse files
committed
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.
1 parent 4c654e4 commit a042851

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

rewrite-test/src/main/java/org/openrewrite/test/RecipeSpec.java

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
import java.nio.file.Path;
3535
import java.util.*;
3636
import java.util.function.Function;
37+
import java.util.stream.Collectors;
3738

3839
import static org.assertj.core.api.Assertions.assertThat;
3940
import static org.assertj.core.api.Assertions.fail;
@@ -209,7 +210,14 @@ public <E> RecipeSpec dataTable(Class<E> rowType, UncheckedConsumer<List<E>> ext
209210
return;
210211
}
211212
}
212-
fail("No data table found with row type " + rowType);
213+
String message = "No data table found with row type: " + rowType;
214+
Set<DataTable<?>> tables = run.getDataTables().keySet();
215+
if (!tables.isEmpty()) {
216+
message += "\nFound data tables row type(s): " + tables.stream()
217+
.map(it -> it.getType().getName().replace("$", "."))
218+
.collect(Collectors.joining(","));
219+
}
220+
fail(message);
213221
});
214222
}
215223

0 commit comments

Comments
 (0)