Skip to content

Upgrade dependencies #1722

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

Merged
merged 2 commits into from
Aug 11, 2019
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
11 changes: 10 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,16 @@ Please see [CONTRIBUTING.md](https://github.com/cucumber/cucumber/blob/master/CO
* [Core] Use feature file language to parse numbers in the type registry
- Unless explicitly set using the `TypeRegistryConfigurer`
* [Core] Use Java Time API in Events ([#1620](https://github.com/cucumber/cucumber-jvm/pull/1620) Yatharth Zutshi)

* [Core] Upgrade `cucumber-expressions` to 8.0.0
- Simplify heuristics to distinguish between Cucumber Expressions and Regular Expressions ([#cucumber/515](https://github.com/cucumber/cucumber/issues/515), [#cucumber/581](https://github.com/cucumber/cucumber/pull/581), [#1581](https://github.com/cucumber/cucumber-jvm/issues/1581) M.P.Korstanje)
- Improve decimal number parsing ([#cucumber/600](https://github.com/cucumber/cucumber/issues/600), [#cucumber/605](https://github.com/cucumber/cucumber/pull/605), [#cucumber/669](https://github.com/cucumber/cucumber/issues/669), [#cucumber/672](https://github.com/cucumber/cucumber/pull/672), [#cucumber/675](https://github.com/cucumber/cucumber/pull/675), [#cucumber/677](https://github.com/cucumber/cucumber/pull/677) Aslak Hellesøy, Vincent Psarga, Luke Hill, M.P. Korstanje )
- Recognize look around as a non-capturing regex group ([#cucumber/481](https://github.com/cucumber/cucumber/issues/576), [#cucumber/593](https://github.com/cucumber/cucumber/pull/593) Luke Hill)
- Prefer type from method over type from ParameterType ([#cucumber/658](https://github.com/cucumber/cucumber/pull/658) [#cucumber/659](https://github.com/cucumber/cucumber/pull/659) M.P. Korstanje)
* [Core] Upgrade `datatable` to 2.0.0
- Empty cells are `null` values in `DataTable` ([1617](https://github.com/cucumber/cucumber-jvm/issues/1617) M.P. Korstanje)
- Improve handling of tables without header ([#cucumber/540](https://github.com/cucumber/cucumber/pull/540) M.P. Korstanje)
- Remove DataTableType convenience methods ([1643](https://github.com/cucumber/cucumber-jvm/issues/1643) M.P. Korstanje)

### Deprecated
* [Core] Deprecate `timeout` ([#1506](https://github.com/cucumber/cucumber-jvm/issues/1506), [#1694](https://github.com/cucumber/cucumber-jvm/issues/1694) M.P. Korstanje)
- Prefer using library based solutions
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package io.cucumber.core.stepexpression;


@FunctionalInterface
interface DocStringTransformer<T> {
T transform(String docString);
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,12 @@ private PickleTableConverter() {
}

static List<List<String>> toTable(PickleTable pickleTable) {
List<List<String>> table = new ArrayList<List<String>>();
List<List<String>> table = new ArrayList<>();
for (PickleRow pickleRow : pickleTable.getRows()) {
List<String> row = new ArrayList<String>();
List<String> row = new ArrayList<>();
for (PickleCell pickleCell : pickleRow.getCells()) {
row.add(pickleCell.getValue());
String value = pickleCell.getValue();
row.add(value.isEmpty() ? null : value);
}
table.add(row);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import java.util.List;

@FunctionalInterface
interface RawTableTransformer<T> {
T transform(List<List<String>> raw);
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,6 @@ public final class StepExpressionFactory {
private final io.cucumber.cucumberexpressions.ExpressionFactory expressionFactory;
private final DataTableTypeRegistryTableConverter tableConverter;

private static final DocStringTransformer<String> DOC_STRING_IDENTITY = new DocStringTransformer<String>() {
@Override
public String transform(String input) {
return input;
}
};

public StepExpressionFactory(TypeRegistry registry) {
this.expressionFactory = new io.cucumber.cucumberexpressions.ExpressionFactory(registry.parameterTypeRegistry());
this.tableConverter = new DataTableTypeRegistryTableConverter(registry.dataTableTypeRegistry());
Expand All @@ -32,13 +25,9 @@ public StepExpression createExpression(String expressionString) {
if (expressionString == null) throw new NullPointerException("expression can not be null");
Expression expression = expressionFactory.createExpression(expressionString);

RawTableTransformer<DataTable> toDataTable = new RawTableTransformer<DataTable>() {
@Override
public DataTable transform(List<List<String>> raw) {
return DataTable.create(raw, tableConverter);
}
};
return new StepExpression(expression, DOC_STRING_IDENTITY, toDataTable);
RawTableTransformer<DataTable> toDataTable = raw -> DataTable.create(raw, tableConverter);
DocStringTransformer<Object> toDocString = (String input) -> input;
return new StepExpression(expression, toDocString, toDataTable);
}

public StepExpression createExpression(String expressionString, Type tableOrDocStringType) {
Expand All @@ -64,26 +53,20 @@ public StepExpression createExpression(String expressionString, final TypeResolv
throw registerTypeInConfiguration(expressionString, e);
}

RawTableTransformer<?> tableTransform = new RawTableTransformer<Object>() {
@Override
public Object transform(List<List<String>> raw) {
DataTable dataTable = DataTable.create(raw, StepExpressionFactory.this.tableConverter);
Type targetType = tableOrDocStringType.resolve();
return dataTable.convert(Object.class.equals(targetType) ? DataTable.class : targetType, transpose);
}
RawTableTransformer<?> tableTransform = (List<List<String>> raw) -> {
DataTable dataTable = DataTable.create(raw, StepExpressionFactory.this.tableConverter);
Type targetType = tableOrDocStringType.resolve();
return dataTable.convert(Object.class.equals(targetType) ? DataTable.class : targetType, transpose);
};

DocStringTransformer<?> docStringTransform = new DocStringTransformer<Object>() {
@Override
public Object transform(String docString) {
Type targetType = tableOrDocStringType.resolve();
if (Object.class.equals(targetType)) {
return docString;
}

List<List<String>> raw = singletonList(singletonList(docString));
return DataTable.create(raw, StepExpressionFactory.this.tableConverter).convert(targetType, transpose);
DocStringTransformer<?> docStringTransform = (String docString) -> {
Type targetType = tableOrDocStringType.resolve();
if (Object.class.equals(targetType)) {
return docString;
}

List<List<String>> raw = singletonList(singletonList(docString));
return DataTable.create(raw, StepExpressionFactory.this.tableConverter).convert(targetType, transpose);
};
return new StepExpression(expression, docStringTransform, tableTransform);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import static org.hamcrest.core.Is.is;
import static org.hamcrest.core.IsEqual.equalTo;
import static org.junit.jupiter.api.Assertions.assertAll;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.mockito.Mockito.mock;

public class CoreStepDefinitionTest {
Expand All @@ -51,6 +52,16 @@ public void should_apply_identity_transform_to_data_table_when_target_type_is_ob
assertThat(arguments.get(0).getValue(), is(equalTo(DataTable.create(singletonList(singletonList("content"))))));
}

@Test
public void should_convert_empty_pickle_table_cells_to_null_values() {
StubStepDefinition stub = new StubStepDefinition("I have some step", Object.class);
CoreStepDefinition stepDefinition = new CoreStepDefinition(stub, typeRegistry);

PickleTable table = new PickleTable(singletonList(new PickleRow(singletonList(new PickleCell(null, "")))));
List<Argument> arguments = stepDefinition.matchedArguments(new PickleStep("I have some step", singletonList(table), emptyList()));
assertEquals(DataTable.create(singletonList(singletonList(null))), arguments.get(0).getValue());
}


public static class StepDefs {
public void listOfListOfDoubles(List<List<Double>> listOfListOfDoubles) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -185,23 +185,16 @@ public ItemQuantity transform(String s) throws Throwable {
public void throws_could_not_convert_exception_for_singleton_table_dimension_mismatch() {
PickleTable table = new PickleTable(
asList(
new PickleRow(asList(new PickleCell(mock(PickleLocation.class), "A"), new PickleCell(mock(PickleLocation.class), "B"))),
new PickleRow(asList(new PickleCell(mock(PickleLocation.class), "C"), new PickleCell(mock(PickleLocation.class), "D")))
new PickleRow(singletonList(new PickleCell(mock(PickleLocation.class), "A"))),
new PickleRow(singletonList(new PickleCell(mock(PickleLocation.class), "B"))),
new PickleRow(singletonList(new PickleCell(mock(PickleLocation.class), "C"))),
new PickleRow(singletonList(new PickleCell(mock(PickleLocation.class), "D")))
)
);

typeRegistry.defineDataTableType(new DataTableType(
ItemQuantity.class,
new TableCellTransformer<ItemQuantity>() {
@Override
public ItemQuantity transform(String s) {
return new ItemQuantity(s);
}
}

));
typeRegistry.defineDataTableType(new DataTableType(ItemQuantity.class, ItemQuantity::new ));

PickleStep step = new PickleStep("I have some cukes in my belly", singletonList((gherkin.pickles.Argument) table), asList(mock(PickleLocation.class)));
PickleStep step = new PickleStep("I have some cukes in my belly", singletonList(table), singletonList(mock(PickleLocation.class)));
StepDefinition stepDefinition = new StubStepDefinition("I have some cukes in my belly", ItemQuantity.class);
CoreStepDefinition coreStepDefinition = new CoreStepDefinition(stepDefinition, typeRegistry);
List<Argument> arguments = coreStepDefinition.matchedArguments(step);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,11 @@

import io.cucumber.datatable.DataTable;
import io.cucumber.datatable.DataTableType;
import io.cucumber.datatable.TableCellByTypeTransformer;
import io.cucumber.datatable.TableEntryByTypeTransformer;
import io.cucumber.datatable.TableEntryTransformer;
import io.cucumber.datatable.TableTransformer;
import io.cucumber.datatable.dependency.com.fasterxml.jackson.databind.ObjectMapper;
import org.junit.jupiter.api.Test;

import java.lang.reflect.Method;
Expand All @@ -16,15 +19,16 @@
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.core.Is.is;
import static org.hamcrest.core.IsEqual.equalTo;
import static org.hamcrest.core.IsNull.nullValue;

public class StepExpressionFactoryTest {

private static final TypeResolver UNKNOWN_TYPE = () -> Object.class;

static class Ingredient {
String name;
Integer amount;
String unit;
public String name;
public Integer amount;
public String unit;

Ingredient() {
}
Expand All @@ -37,27 +41,20 @@ static class Ingredient {

private TableEntryTransformer<Ingredient> listBeanMapper(final TypeRegistry registry) {
//Just pretend this is a bean mapper.
return new TableEntryTransformer<Ingredient>() {

@Override
public Ingredient transform(Map<String, String> tableRow) {
Ingredient bean = new Ingredient();
bean.amount = Integer.valueOf(tableRow.get("amount"));
bean.name = tableRow.get("name");
bean.unit = tableRow.get("unit");
return bean;
}
return tableRow -> {
Ingredient bean = new Ingredient();
bean.amount = Integer.valueOf(tableRow.get("amount"));
bean.name = tableRow.get("name");
bean.unit = tableRow.get("unit");
return bean;
};
}


private TableTransformer<Ingredient> beanMapper(final TypeRegistry registry) {
return new TableTransformer<Ingredient>() {
@Override
public Ingredient transform(DataTable table) throws Throwable {
Map<String, String> tableRow = table.transpose().asMaps().get(0);
return listBeanMapper(registry).transform(tableRow);
}
return table -> {
Map<String, String> tableRow = table.transpose().asMaps().get(0);
return listBeanMapper(registry).transform(tableRow);
};
}

Expand Down Expand Up @@ -96,7 +93,7 @@ public void table_expression_with_list_type_creates_list_of_ingredients_from_tab

List<Ingredient> ingredients = (List<Ingredient>) match.get(0).getValue();
Ingredient ingredient = ingredients.get(0);
assertThat(ingredient.name, is(equalTo("chocolate")));
assertThat(ingredient.amount, is(equalTo(2)));
}

@Test
Expand All @@ -107,13 +104,31 @@ public void unknown_target_type_does_no_transform_data_table() {
}

@Test
public void unknown_target_type_does_no_transform_doc_string() {
public void unknown_target_type_does_not_transform_doc_string() {
String docString = "A rather long and boring string of documentation";
StepExpression expression = new StepExpressionFactory(registry).createExpression("Given some stuff:", UNKNOWN_TYPE);
List<Argument> match = expression.match("Given some stuff:", docString);
assertThat(match.get(0).getValue(), is(equalTo(docString)));
}

@Test
public void empty_table_cells_are_presented_as_null_to_transformer() {
registry.setDefaultDataTableEntryTransformer(new TableEntryByTypeTransformer() {
@Override
public <T> T transform(Map<String, String> map, Class<T> aClass, TableCellByTypeTransformer tableCellByTypeTransformer) {
return new ObjectMapper().convertValue(map, aClass);
}
});

StepExpression expression = new StepExpressionFactory(registry).createExpression("Given some stuff:", getTypeFromStepDefinition());
List<List<String>> table = asList(asList("name", "amount", "unit"), asList("chocolate", null, "tbsp"));
List<Argument> match = expression.match("Given some stuff:", table);

List<Ingredient> ingredients = (List<Ingredient>) match.get(0).getValue();
Ingredient ingredient = ingredients.get(0);
assertThat(ingredient.name, is(equalTo("chocolate")));

}

private Type getTypeFromStepDefinition() {
for (Method method : this.getClass().getMethods()) {
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,57 +1,51 @@
package io.cucumber.core.stepexpression;

import io.cucumber.cucumberexpressions.Expression;
import io.cucumber.cucumberexpressions.ExpressionFactory;
import io.cucumber.cucumberexpressions.ParameterByTypeTransformer;
import io.cucumber.cucumberexpressions.ParameterType;
import io.cucumber.cucumberexpressions.Transformer;
import io.cucumber.datatable.DataTable;
import io.cucumber.datatable.DataTableType;
import io.cucumber.datatable.TableCellByTypeTransformer;
import io.cucumber.datatable.TableEntryByTypeTransformer;
import io.cucumber.datatable.TableTransformer;
import org.junit.jupiter.api.Test;

import java.lang.reflect.Type;
import java.util.Date;
import java.util.Map;
import java.util.regex.Pattern;

import static java.util.Locale.ENGLISH;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.core.Is.is;
import static org.hamcrest.core.IsEqual.equalTo;

public class TypeRegistryTest {

private final TypeRegistry registry = new TypeRegistry(ENGLISH);
private final ExpressionFactory expressionFactory = new ExpressionFactory(registry.parameterTypeRegistry());

@Test
public void should_define_parameter_type() {
ParameterType<Object> expected = new ParameterType<>(
"example",
".*",
Object.class,
new Transformer<Object>() {
@Override
public Object transform(String s) {
return null;
}
}
(String s) -> null
);
registry.defineParameterType(expected);
assertThat(registry.parameterTypeRegistry().lookupByTypeName("example"), is(equalTo(expected)));
Expression expresion = expressionFactory.createExpression("{example}");
assertThat(expresion.getRegexp().pattern(), is("^(.*)$"));
}

@Test
public void should_define_data_table_parameter_type() {
DataTableType expected = new DataTableType(Date.class, (DataTable dataTable) -> null);
registry.defineDataTableType(expected);
assertThat(registry.dataTableTypeRegistry().lookupTableTypeByType(Date.class), is(equalTo(expected)));
}

@Test
public void should_set_default_parameter_transformer() {
ParameterByTypeTransformer expected = (fromValue, toValueType) -> null;
registry.setDefaultParameterTransformer(expected);
assertThat(registry.parameterTypeRegistry().getDefaultParameterTransformer(), is(equalTo(expected)));
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public void adding(int arg1, int arg2) {
calc.push("+");
}

@Given("I press (.+)")
@Given("^I press (.+)$")
public void I_press(String what) {
calc.push(what);
}
Expand Down
Loading