Chapter 14

Change

Change is worth embracing (especially if you have a book out with “embrace change” in the title). Here, however, we are thinking about a much simpler form of change—we have two francs and we want a dollar. That sounds like a test case already:

public void testReduceMoneyDifferentCurrency() {
   Bank bank= new Bank();
   bank.addRate("CHF", "USD", 2);
   Money result= bank.reduce(Money.franc(2), "USD");
   assertEquals(Money.dollar(1), result);
}

When I convert francs to dollars, I divide by two. (We’re still studiously ignoring all of those nasty numerical problems.) ...

Get Test Driven Development: By Example now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.