-
Notifications
You must be signed in to change notification settings - Fork 19
/
Copy pathCoffeeMachine.java
44 lines (36 loc) · 1.24 KB
/
CoffeeMachine.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
package io.split.client.testing.cucumber;
import io.split.client.SplitClient;
import java.util.ArrayList;
import java.util.List;
import static java.util.Collections.emptyList;
import static java.util.Collections.unmodifiableList;
/**
* A simple coffee machine that displays available drinks. It can offer an experimental cappuccino
* drink that is toggled on/off with Split.
*/
public class CoffeeMachine {
private final SplitClient splitClient;
private final String splitKey;
private double level;
public CoffeeMachine(SplitClient splitClient, String splitKey) {
this.splitClient = splitClient;
this.splitKey = splitKey;
}
/**
* Indicate how full the machine is
*
* @param level a number between 0 and 1
*/
public void setLevel(double level) {
this.level = level;
}
public List<SKU> getAvailableDrinks() {
if(this.level == 0) return emptyList();
List<SKU> availableDrinks = new ArrayList<>();
availableDrinks.add(new SKU("filter coffee", 0.80));
if ("on".equals(this.splitClient.getTreatment(splitKey, "cappuccino"))) {
availableDrinks.add(new SKU("cappuccino", 1.10));
}
return unmodifiableList(availableDrinks);
}
}