@Test void throws_duplicate_type_exception() { registry.defineDataTableType(new DataTableType( Place.class, (TableTransformer<Place>) table -> new Place(table.cell(0, 0)) )); DuplicateTypeException exception = assertThrows(DuplicateTypeException.class, () -> registry.defineDataTableType(new DataTableType( Place.class, (TableTransformer<Place>) table -> new Place(table.cell(0, 0)) ))); assertThat(exception.getMessage(), is("" + "There already is a data table type registered that can supply class io.cucumber.datatable.Place.\n" + "You are trying to register a TableTransformer for class io.cucumber.datatable.Place.\n" + "The existing data table type registered a TableTransformer for class io.cucumber.datatable.Place.\n" )); }
public void defineDataTableType(DataTableType dataTableType) { DataTableType existing = tableTypeByType.get(dataTableType.getTargetType()); if (existing != null && !existing.isReplaceable()) { throw new DuplicateTypeException(format("" + "There already is a data table type registered that can supply %s.\n" + "You are trying to register a %s for %s.\n" + "The existing data table type registered a %s for %s.\n", dataTableType.getElementType(), dataTableType.getTransformerType().getSimpleName(), dataTableType.getElementType(), existing.getTransformerType().getSimpleName(), existing.getElementType() )); } tableTypeByType.put(dataTableType.getTargetType(), dataTableType); }
DataTableTypeRegistry { public void defineDataTableType(DataTableType dataTableType) { DataTableType existing = tableTypeByType.get(dataTableType.getTargetType()); if (existing != null && !existing.isReplaceable()) { throw new DuplicateTypeException(format("" + "There already is a data table type registered that can supply %s.\n" + "You are trying to register a %s for %s.\n" + "The existing data table type registered a %s for %s.\n", dataTableType.getElementType(), dataTableType.getTransformerType().getSimpleName(), dataTableType.getElementType(), existing.getTransformerType().getSimpleName(), existing.getElementType() )); } tableTypeByType.put(dataTableType.getTargetType(), dataTableType); } }
DataTableTypeRegistry { public void defineDataTableType(DataTableType dataTableType) { DataTableType existing = tableTypeByType.get(dataTableType.getTargetType()); if (existing != null && !existing.isReplaceable()) { throw new DuplicateTypeException(format("" + "There already is a data table type registered that can supply %s.\n" + "You are trying to register a %s for %s.\n" + "The existing data table type registered a %s for %s.\n", dataTableType.getElementType(), dataTableType.getTransformerType().getSimpleName(), dataTableType.getElementType(), existing.getTransformerType().getSimpleName(), existing.getElementType() )); } tableTypeByType.put(dataTableType.getTargetType(), dataTableType); } DataTableTypeRegistry(Locale locale); }
DataTableTypeRegistry { public void defineDataTableType(DataTableType dataTableType) { DataTableType existing = tableTypeByType.get(dataTableType.getTargetType()); if (existing != null && !existing.isReplaceable()) { throw new DuplicateTypeException(format("" + "There already is a data table type registered that can supply %s.\n" + "You are trying to register a %s for %s.\n" + "The existing data table type registered a %s for %s.\n", dataTableType.getElementType(), dataTableType.getTransformerType().getSimpleName(), dataTableType.getElementType(), existing.getTransformerType().getSimpleName(), existing.getElementType() )); } tableTypeByType.put(dataTableType.getTargetType(), dataTableType); } DataTableTypeRegistry(Locale locale); void defineDataTableType(DataTableType dataTableType); void setDefaultDataTableEntryTransformer(TableEntryByTypeTransformer defaultDataTableEntryTransformer); void setDefaultDataTableCellTransformer(TableCellByTypeTransformer defaultDataTableCellTransformer); }
DataTableTypeRegistry { public void defineDataTableType(DataTableType dataTableType) { DataTableType existing = tableTypeByType.get(dataTableType.getTargetType()); if (existing != null && !existing.isReplaceable()) { throw new DuplicateTypeException(format("" + "There already is a data table type registered that can supply %s.\n" + "You are trying to register a %s for %s.\n" + "The existing data table type registered a %s for %s.\n", dataTableType.getElementType(), dataTableType.getTransformerType().getSimpleName(), dataTableType.getElementType(), existing.getTransformerType().getSimpleName(), existing.getElementType() )); } tableTypeByType.put(dataTableType.getTargetType(), dataTableType); } DataTableTypeRegistry(Locale locale); void defineDataTableType(DataTableType dataTableType); void setDefaultDataTableEntryTransformer(TableEntryByTypeTransformer defaultDataTableEntryTransformer); void setDefaultDataTableCellTransformer(TableCellByTypeTransformer defaultDataTableCellTransformer);  }