|
| 1 | +package io.split.client.testing.cucumber; |
| 2 | + |
| 3 | +import io.cucumber.java.Before; |
| 4 | +import io.cucumber.java.DataTableType; |
| 5 | +import io.cucumber.java.Scenario; |
| 6 | +import io.cucumber.java.en.Given; |
| 7 | +import io.cucumber.java.en.Then; |
| 8 | +import io.split.client.testing.SplitClientForTest; |
| 9 | + |
| 10 | +import java.util.List; |
| 11 | +import java.util.Map; |
| 12 | + |
| 13 | +import static java.util.Collections.emptyList; |
| 14 | +import static org.junit.Assert.assertEquals; |
| 15 | + |
| 16 | +public class StepDefinitions { |
| 17 | + private final SplitClientForTest splitClient = new SplitClientForTest(); |
| 18 | + private final CoffeeMachine coffeeMachine = new CoffeeMachine(splitClient, "arbitraryKey"); |
| 19 | + |
| 20 | + // Called by Cucumber to convert each row in the data table in the .feature file to a SKU object |
| 21 | + @DataTableType |
| 22 | + public SKU sku(Map<String, String> entry) { |
| 23 | + return new SKU( |
| 24 | + entry.get("name"), |
| 25 | + Double.parseDouble(entry.get("price")) |
| 26 | + ); |
| 27 | + } |
| 28 | + |
| 29 | + @Given("the machine is not empty") |
| 30 | + public void the_machine_is_not_empty() { |
| 31 | + coffeeMachine.setLevel(1.0); |
| 32 | + } |
| 33 | + |
| 34 | + @Given("the machine is empty") |
| 35 | + public void the_machine_is_empty() { |
| 36 | + coffeeMachine.setLevel(0); |
| 37 | + } |
| 38 | + |
| 39 | + @Then("the following drinks should be available:") |
| 40 | + public void the_following_drinks_should_be_available(List<SKU> expectedSKUs) { |
| 41 | + List<SKU> availableSKUs = coffeeMachine.getAvailableDrinks(); |
| 42 | + assertEquals(expectedSKUs, availableSKUs); |
| 43 | + } |
| 44 | + |
| 45 | + @Then("no drinks should be available") |
| 46 | + public void no_drinks_should_be_available() { |
| 47 | + List<SKU> availableSKUs = coffeeMachine.getAvailableDrinks(); |
| 48 | + assertEquals(emptyList(), availableSKUs); |
| 49 | + } |
| 50 | + |
| 51 | + @Before |
| 52 | + public void configureSplit(Scenario scenario) { |
| 53 | + CucumberSplit.configureSplit(splitClient, scenario); |
| 54 | + } |
| 55 | +} |
0 commit comments