Skip to content

Commit

Permalink
Actionable error message when test attempts to access a non-existent …
Browse files Browse the repository at this point in the history
…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.
  • Loading branch information
sambsnyd committed Nov 7, 2023
1 parent 4c654e4 commit a042851
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion rewrite-test/src/main/java/org/openrewrite/test/RecipeSpec.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -209,7 +210,14 @@ public <E> RecipeSpec dataTable(Class<E> rowType, UncheckedConsumer<List<E>> ext
return;
}
}
fail("No data table found with row type " + rowType);
String message = "No data table found with row type: " + rowType;
Set<DataTable<?>> 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);
});
}

Expand Down

0 comments on commit a042851

Please sign in to comment.