更新 私はブーリアンを追加し、それらも機能するようにしました。
Scenario: An international coffee shop must handle currencies
Given the price list for an international coffee shop
| product | currency | price | happy |
| coffee | EUR | 1 | true |
| donut | SEK | 18 | false |
When I buy "1" "coffee" and "1" "donut"
Then I should pay "1" EUR be "happy" and "18" SEK be "unhappy"
ステップ定義ファイル
public class datatable_steps {
private HashMap<String, Price> intPriceList = new HashMap<String, Price>();
private int sekSum;
private int euroSum;
@Given("^the price list for an international coffee shop$")
public void the_price_list_for_an_international_coffee_shop(List<Price> prices) {
int numPrices = prices.size();
System.out.println("numPrices = " + numPrices);
for(Price price : prices) {
String key = price.getProduct();
intPriceList.put(key, price);
}
}
@When("^I buy \"(\\d+)\" \"(.*)\" and \"(\\d+)\" \"(.*)\"$")
public void i_order_coffee_and_donut(int numberOfFirstItems, String firstItem,
int numberOfSecondItems, String secondItem) throws Throwable {
Price firstPrice = intPriceList.get(firstItem);
calculate(numberOfFirstItems, firstPrice);
Price secondPrice = intPriceList.get(secondItem);
calculate(numberOfSecondItems, secondPrice);
}
private void calculate(int numberOfItems, Price price) {
if (price.getCurrency().equals("SEK")) {
sekSum += numberOfItems * price.getPrice();
return;
}
if (price.getCurrency().equals("EUR")) {
euroSum += numberOfItems * price.getPrice();
return;
}
throw new IllegalArgumentException("The currency is unknown");
}
@Then("^I should pay \"(\\d+)\" EUR be \"(.*)\" and \"(\\d+)\" SEK be \"(.*)\"$")
public void should_I_pay_EUR_and_SEK(int expectedEuroSum, String eurHappy, int expectedSekSum, String sekHappy) throws Throwable {
boolean eurHappyBool = false;
boolean sekHappyBool = false;
Assert.assertEquals(expectedEuroSum, euroSum);
Assert.assertEquals(expectedSekSum,sekSum);
if (eurHappy.equalsIgnoreCase("happy")) {
eurHappyBool = true;
}
if (sekHappy.equalsIgnoreCase("happy")) {
sekHappyBool = true;
}
Assert.assertEquals(eurHappyBool, intPriceList.get("coffee").isHappy());
Assert.assertEquals(sekHappyBool, intPriceList.get("donut").isHappy());
}
}
クラスの価格は次のようになります。
package runsupport;
public class Price {
private String product;
private String currency;
private Integer price;
private boolean happy;
public Price(String product, Integer price, String currency){
this.product = product;
this.price = price;
this.currency = currency;
}
public String getProduct() {
return product;
}
public Integer getPrice() {
return price;
}
public String getCurrency() {
return currency;
}
public boolean isHappy() {
return happy;
}
}
isHappy()メソッドです。 ScenarioStuffのクラス定義は何ですか?あなたの機能はシナリオの輪郭のように見えますが、はどこにも表示されません。 [Doc String](https://cucumber.io/docs/reference#doc-strings)を使用することを意味しましたか?質問を明確にしてください。 –
MikeJRamsey56
isHappyは幸せのゲッターです(更新されたコードを参照)。フィーチャー・テーブルに名前が表示されます(「物を考える」を参照)。私は大文字のテキストではなくテーブルを渡すので、ここでdoc文字列が当てはまるとは思わない。 – mmalmeida
「Miguel」という文字列をList stuffListレシーバに渡しています。おそらくうまくいくわけではないでしょう。文字列を文字列として受け入れ、ステップボディに明示的にScenarioStuffを作成するのはなぜですか? –
MikeJRamsey56