CoffeeMachine implements ICoffeeMachine { public String process(IRequest request, double priceInEuros) { double drinkPrice = getDrinkPrice(request); final int sugarQuantity = request.getSugarQuantity(); return priceInEuros >= drinkPrice ? new StringBuilder("Drink maker makes 1 ") .append(request.getDrinkName().toLowerCase()) .append(" with ") .append(sugarQuantity > 0 ? sugarQuantity + " sugar and a stick" : "no sugar - and therefore no stick") .toString() : "Not enough money: " + Math.round((drinkPrice - priceInEuros) * 10)/10. + " euros still missing"; }  String process(IRequest request, double priceInEuros);  }
@Test public void tea_without_sugar() { ICoffeeMachine coffeeMachine = new CoffeeMachine(); IRequest request = DrinkFactory.getInstance().newTeaRequestBuilder().build(); String result = coffeeMachine.process(request, 0.4); assertEquals("Drink maker makes 1 tea with no sugar - and therefore no stick", result); }
@Test public void coffee_with_sugar_not_enough_money() { ICoffeeMachine coffeeMachine = new CoffeeMachine(); IRequest request = DrinkFactory.getInstance().newCoffeeRequestBuilder().withSugar(1).build(); String result = coffeeMachine.process(request, 0.4); assertEquals("Not enough money: 0.2 euros still missing", result); }