Skip to content

Commit

Permalink
feat: 🚀 Support boolean parsing in Datatables
Browse files Browse the repository at this point in the history
  • Loading branch information
gaeljw committed Sep 14, 2022
1 parent 823c380 commit dca9bfa
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 0 deletions.
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"))));
}

}

0 comments on commit dca9bfa

Please sign in to comment.