CoffeeMachine { public Coffee brewCoffee(CoffeeSelection selection) throws CoffeeException { switch (selection) { case FILTER_COFFEE: return brewFilterCoffee(); case ESPRESSO: return brewEspresso(); default: throw new CoffeeException("CoffeeSelection ["+selection+"] not supported!"); } } CoffeeMachine(Map<CoffeeSelection, CoffeeBean> beans); Coffee brewCoffee(CoffeeSelection selection);  }
@Test public void testEspresso() throws CoffeeException { Map<CoffeeSelection, CoffeeBean> beans = new HashMap<CoffeeSelection, CoffeeBean>(); beans.put(CoffeeSelection.ESPRESSO, new CoffeeBean("My favorite espresso bean", 1000)); beans.put(CoffeeSelection.FILTER_COFFEE, new CoffeeBean("My favorite filter coffee bean", 1000)); CoffeeMachine machine = new CoffeeMachine(beans); Coffee espresso = machine.brewCoffee(CoffeeSelection.ESPRESSO); Assert.assertEquals(CoffeeSelection.ESPRESSO, espresso.getSelection()); Assert.assertEquals(28d, espresso.getQuantity(), 0.01); }