Created
March 10, 2011 21:16
-
-
Save martinsson/864943 to your computer and use it in GitHub Desktop.
ocp minimaliste
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class BillFormatter { | |
public String format(int price, Currency currency) throws UnknownCurrencyException { | |
String formattedPrice = "Your total is : "; | |
if (currency == Currency.EUROS) { | |
formattedPrice += price + "€"; | |
} else if (currency == Currency.POUNDS) { | |
formattedPrice += "£" + price; | |
} else { | |
throw new UnknownCurrencyException(); | |
} | |
return formattedPrice; | |
} | |
} | |
===================== | |
public class BillFormatterTest { | |
@Test | |
public void handlesPounds() throws Exception { | |
BillFormatter billFormatter = new BillFormatter(); | |
String price = billFormatter.format(100, Currency.POUNDS); | |
assertThat(price, endsWith("£100")); | |
} | |
@Test | |
public void handlesEuros() throws Exception { | |
BillFormatter billFormatter = new BillFormatter(); | |
String price = billFormatter.format(23, Currency.EUROS); | |
assertThat(price, endsWith("23€")); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment