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

[Datatable] Support boolean parsing in Datatables #2614

Merged
merged 1 commit into from
Sep 15, 2022
Merged
Show file tree
Hide file tree
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
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

### Added
- [Datatable] Support parsing Booleans in Datatables ([#2614](https://github.com/cucumber/cucumber-jvm/pull/2614) G. Jourdan-Weil)

## [7.7.0] - 2022-09-08
### Added
- [JUnit Platform] Enable parallel execution of features ([#2604](https://github.com/cucumber/cucumber-jvm/pull/2604) Sambathkumar Sekar)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,10 @@ public DataTableTypeRegistry(Locale locale) {
TableCellTransformer<Double> doubleTableCellTransformer = applyIfPresent(numberParser::parseDouble);
defineDataTableType(new DataTableType(Double.class, doubleTableCellTransformer));
defineDataTableType(new DataTableType(double.class, doubleTableCellTransformer));

TableCellTransformer<Boolean> booleanTableCellTransformer = applyIfPresent(Boolean::parseBoolean);
defineDataTableType(new DataTableType(Boolean.class, booleanTableCellTransformer, true));
defineDataTableType(new DataTableType(boolean.class, booleanTableCellTransformer, true));
}

private static <R> TableCellTransformer<R> applyIfPresent(Function<String, R> f) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ class DataTableTypeRegistryTest {
private static final Type LIST_OF_LIST_OF_FLOAT = aListOf(aListOf(Float.class));
private static final Type LIST_OF_LIST_OF_DOUBLE = aListOf(aListOf(Double.class));
private static final Type LIST_OF_LIST_OF_STRING = aListOf(aListOf(String.class));
private static final Type LIST_OF_LIST_OF_BOOLEAN = aListOf(aListOf(Boolean.class));
private static final Type LIST_OF_LIST_OF_OBJECT = aListOf(aListOf(Object.class));

private static final TableCellByTypeTransformer PLACE_TABLE_CELL_TRANSFORMER = (value,
Expand Down Expand Up @@ -244,4 +245,28 @@ void object_transformer_is_replaceable() {
singletonList(singletonList("")),
dataTableType.transform(singletonList(singletonList("[blank]"))));
}

@Test
void parse_boolean() {
DataTableTypeRegistry registry = new DataTableTypeRegistry(Locale.ENGLISH);
DataTableType dataTableType = registry.lookupTableTypeByType(LIST_OF_LIST_OF_BOOLEAN);
assertEquals(
singletonList(singletonList(Boolean.TRUE)),
dataTableType.transform(singletonList(singletonList("true"))));
assertEquals(
singletonList(singletonList(Boolean.FALSE)),
dataTableType.transform(singletonList(singletonList("false"))));
}

@Test
void boolean_transformer_is_replaceable() {
DataTableTypeRegistry registry = new DataTableTypeRegistry(Locale.ENGLISH);
registry.defineDataTableType(
new DataTableType(Boolean.class, (String cell) -> "yes".equals(cell)));
DataTableType dataTableType = registry.lookupTableTypeByType(LIST_OF_LIST_OF_BOOLEAN);
assertEquals(
singletonList(singletonList(Boolean.TRUE)),
dataTableType.transform(singletonList(singletonList("yes"))));
}

}