MoneyMachine { public Coins acceptPayment(int priceCents, Coins payedCoins) { Coins coinsToReturn = tryPayment(priceCents, payedCoins); coinStash = coinStash.add(payedCoins).substract(coinsToReturn); return coinsToReturn; }  void empty(); void refill(Coins coins); Coins acceptPayment(int priceCents, Coins payedCoins); int sumTotalCents();  }
@Test public void givenEmptyStash_whenPayed2x1EUR_forPrice100_returns_1EUR() { Coins rest = machine.acceptPayment(100, new Coins(Coin.ONE_EURO, Coin.ONE_EURO)); assertEquals(new Coins(Coin.ONE_EURO), rest); }
@Test(expected = IllegalArgumentException.class) public void cannotReturnChange() { machine.acceptPayment(80, new Coins(Coin.ONE_EURO)); }