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

[Core] Deprecate TypeRegistryConfigurer #1799

Merged
merged 4 commits into from
Oct 18, 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
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,12 @@

/**
* The type registry configurer allows to configure a new type registry and the locale.
* @deprecated Please use annotation based configuration.
* See <a href="https://github.com/cucumber/cucumber-jvm/blob/master/examples/java-calculator/src/test/java/io/cucumber/examples/java/ShoppingSteps.java">Annotation based example</a>
* See <a href="https://github.com/cucumber/cucumber-jvm/blob/master/examples/java8-calculator/src/test/java/io/cucumber/examples/java8/ShoppingSteps.java">Lambda based example</a>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ideally this should link to the documentation pages rather then github examples.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can't really change configuration page in the docs repo before v5 release. This could mislead users.

So I'll change this links to https://cucumber.io/docs/cucumber/configuration/ after v5 release.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We also don't have to introduce this in 5.0.0. I'd rather have the docs in order so there is a clear way out before we deprecate it.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So. I was planning to do this in in v5.x rather then v5.0 because it would make updating the documentation a bit easier but since we're working with release candidates now I think we can prepare the MR for v5.0 along with the release of v5.0.

*/
@API(status = API.Status.STABLE)
@Deprecated
rasklaad marked this conversation as resolved.
Show resolved Hide resolved
public interface TypeRegistryConfigurer {
/**
* @return The locale to use, or null when language from feature file should be used.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,45 @@
package io.cucumber.examples.java;

import io.cucumber.java.DataTableType;
import io.cucumber.java.DocStringType;
import io.cucumber.java.ParameterType;
import io.cucumber.java.en.Given;
import io.cucumber.java.en.Then;
import io.cucumber.java.en.When;

import java.math.BigDecimal;
import java.util.Currency;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.stream.Collectors;
import java.util.stream.Stream;

import static org.junit.jupiter.api.Assertions.assertEquals;

public class ShoppingSteps {
private RpnCalculator calc = new RpnCalculator();

private List<Grocery> shoppingList;
private List<Grocery> shopStock;
private int groceriesPrice;

@DataTableType
public Grocery defineGrocery(Map<String, String> entry) {
return new Grocery(entry.get("name"), ShoppingSteps.Price.fromString(entry.get("price")));
}

@ParameterType(name = "amount", value = "\\d+\\.\\d+\\s[a-zA-Z]+")
public Amount defineAmount(String value) {
String [] arr = value.split("\\s");
return new Amount(new BigDecimal(arr[0]), Currency.getInstance(arr[1]));
}

@DocStringType(contentType = "shopping_list")
public List<Grocery> defineShoppingList(String docstring) {
return Stream.of(docstring.split("\\s")).map(Grocery::new).collect(Collectors.toList());
}

@Given("the following groceries:")
public void the_following_groceries(List<Grocery> groceries) {
for (Grocery grocery : groceries) {
Expand All @@ -19,9 +48,9 @@ public void the_following_groceries(List<Grocery> groceries) {
}
}

@When("I pay {}")
public void i_pay(int amount) {
calc.push(amount);
@When("I pay {amount}")
public void i_pay(Amount amount) {
calc.push(amount.price);
calc.push("-");
}

Expand All @@ -30,10 +59,46 @@ public void my_change_should_be_(int change) {
assertEquals(-calc.value().intValue(), change);
}

@Given("the following shopping list:")
public void the_following_shopping_list(List<Grocery> list) {
shoppingList = list;
}

@Given("the shop has following groceries:")
public void the_shop_has_following_groceries(List<Grocery> shopStock) {
this.shopStock = shopStock;

}

@When("I count shopping price")
public void i_count_shopping_price() {
shoppingList.forEach(grocery -> {
for (Grocery shopGrocery: shopStock) {
if (grocery.equals(shopGrocery)) {
groceriesPrice += shopGrocery.price.value;
}
}
});
}

@Then("price would be {int}")
public void price_would_be(int totalPrice) {
assertEquals(groceriesPrice, totalPrice);
}

static class Grocery {
private String name;
private Price price;

public Grocery(String name, Price price) {
this.name = name;
this.price = price;
}

public Grocery(String name) {
this.name = name;
}

public void setPrice(Price price) {
this.price = price;
}
Expand All @@ -50,6 +115,14 @@ public String getName() {
return name;
}

@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
Grocery grocery = (Grocery) o;
return Objects.equals(name, grocery.name);
}

}

static final class Price {
Expand All @@ -64,4 +137,14 @@ static Price fromString(String value) {
}

}

static final class Amount {
private final BigDecimal price;
private final Currency currency;

public Amount(BigDecimal price, Currency currency) {
this.price = price;
this.currency = currency;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,21 @@ Feature: Shopping
| milk | 9 |
| bread | 7 |
| soap | 5 |
When I pay 25
Then my change should be 4
When I pay 25.0 USD
Then my change should be 4

Scenario: Count shopping list cost
Given the following shopping list:
"""shopping_list
milk
bread
coffee
"""
And the shop has following groceries:
| name | price |
| milk | 9 |
| bread | 7 |
| coffee| 2 |
| soap | 5 |
When I count shopping price
Then price would be 18
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import io.cucumber.java8.Scenario;

import java.util.List;
import java.util.Map;

import static org.junit.jupiter.api.Assertions.assertEquals;

Expand Down Expand Up @@ -45,6 +46,12 @@ public RpnCalculatorSteps() {
}
});

DataTableType((Map<String, String> row) -> new RpnCalculatorSteps.Entry(
Integer.valueOf(row.get("first")),
Integer.valueOf(row.get("second")),
row.get("operation")
));

}

static final class Entry {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,25 @@
package io.cucumber.examples.java8;

import static org.junit.jupiter.api.Assertions.assertEquals;

import io.cucumber.datatable.DataTable;
import io.cucumber.java8.En;

import java.math.BigDecimal;
import java.util.Arrays;
import java.util.Currency;
import java.util.List;

import static org.junit.jupiter.api.Assertions.assertEquals;
import java.util.Map;
import java.util.Objects;
import java.util.stream.Stream;

public class ShoppingSteps implements En {

private RpnCalculator calc = new RpnCalculator();

private List<Grocery> shoppingList;
private List<Grocery> shopStock;
private int groceriesPrice;

public ShoppingSteps() {

Given("the following groceries:", (DataTable dataTable) -> {
Expand All @@ -21,24 +30,71 @@ public ShoppingSteps() {
}
});

When("I pay {}", (Integer amount) -> {
calc.push(amount);
When("I pay {amount}", (Amount amount) -> {
calc.push(amount.price);
calc.push("-");
});

Then("my change should be {}", (Integer change) -> {
assertEquals(-calc.value().intValue(), change.intValue());
});

Given("the following shopping list:", (Grocery [] array) -> {
shoppingList = Arrays.asList(array);
});

Given("the shop has following groceries:", (DataTable dataTable) -> {
this.shopStock = dataTable.asList(Grocery.class);
});

When("I count shopping price", () -> shoppingList.forEach(grocery -> {
for (Grocery shopGrocery: shopStock) {
if (grocery.equals(shopGrocery)) {
groceriesPrice += shopGrocery.price.value;
}
}
}));

Then("price would be {int}", (Integer totalPrice) -> assertEquals(groceriesPrice, totalPrice));

DataTableType((Map<String, String> row) -> new ShoppingSteps.Grocery(
row.get("name"),
ShoppingSteps.Price.fromString(row.get("price"))
));

ParameterType("amount", "\\d+\\.\\d+\\s[a-zA-Z]+", (String value) -> {
String [] arr = value.split("\\s");
return new Amount(new BigDecimal(arr[0]), Currency.getInstance(arr[1]));
});

DocStringType("shopping_list", (String docstring) -> {
return Stream.of(docstring.split("\\s"))
.map(Grocery::new)
.toArray(Grocery[]::new);
});
}

static class Grocery {
private String name;
private Price price;

public Grocery(String name) {
this.name = name;
}

Grocery(String name, Price price) {
this.name = name;
this.price = price;
}

@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
Grocery grocery = (Grocery) o;
return Objects.equals(name, grocery.name);
}

}

static final class Price {
Expand All @@ -53,4 +109,14 @@ static Price fromString(String value) {
}

}

static final class Amount {
private final BigDecimal price;
private final Currency currency;

public Amount(BigDecimal price, Currency currency) {
this.price = price;
this.currency = currency;
}
}
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,21 @@ Feature: Shopping
| milk | 9 |
| bread | 7 |
| soap | 5 |
When I pay 25
Then my change should be 4
When I pay 25.0 USD
Then my change should be 4

Scenario: Count shopping list cost
Given the following shopping list:
"""shopping_list
milk
bread
coffee
"""
And the shop has following groceries:
| name | price |
| milk | 9 |
| bread | 7 |
| coffee| 2 |
| soap | 5 |
When I count shopping price
Then price would be 18