1 package org.apidesign.apifest08.test;
3 import junit.framework.TestCase;
4 import org.apidesign.apifest08.currency.Convertor;
5 import org.apidesign.apifest08.currency.CurrencyValue;
7 /** Finish the Convertor API, and then write bodies of methods inside
8 * of this class to match the given tasks. To fullfil your task, use the
9 * API define in the <code>org.apidesign.apifest08.currency</code> package.
10 * Do not you reflection, or other hacks as your code
11 * shall run without any runtime permissions.
13 public class Task1Test extends TestCase {
14 public Task1Test(String testName) {
19 protected void setUp() throws Exception {
23 protected void tearDown() throws Exception {
26 /** Create convertor that understands two currencies, CZK and
27 * USD. Make 1 USD == 17 CZK.
29 * Creation of the convertor shall not require subclassing of any class
30 * or interface on the client side.
32 * @return prepared convertor ready for converting USD to CZK and CZK to USD
34 public static Convertor<Integer, String> createCZKtoUSD() {
35 return Convertor.getConvertorIntegerString(
36 CurrencyValue.getCurrencyValue(1, "USD"),
37 CurrencyValue.getCurrencyValue(17, "CZK")
41 /** Create convertor that understands two currencies, CZK and
42 * SKK. Make 100 SKK == 80 CZK.
44 * Creation of the convertor shall not require subclassing of any class
45 * or interface on the client side.
47 * @return prepared convertor ready for converting SKK to CZK and CZK to SKK
49 public static Convertor<Integer, String> createSKKtoCZK() {
50 return Convertor.getConvertorIntegerString(
51 CurrencyValue.getCurrencyValue(100, "SKK"),
52 CurrencyValue.getCurrencyValue(80, "CZK")
56 /** Use the convertor from <code>createCZKtoUSD</code> method and do few conversions
59 public void testCurrencyCZKUSD() throws Exception {
60 Convertor<Integer, String> c = createCZKtoUSD();
62 CurrencyValue<Integer, String> result;
64 // convert $5 to CZK using c:
65 // assertEquals("Result is 85 CZK");
66 result = c.convert(CurrencyValue.getCurrencyValue(5, "USD"));
67 assertEquals(CurrencyValue.getCurrencyValue(85, "CZK"), result);
70 // assertEquals("Result is 136 CZK");
71 result = c.convert(CurrencyValue.getCurrencyValue(8, "USD"));
72 assertEquals(CurrencyValue.getCurrencyValue(136, "CZK"), result);
74 // convert 1003CZK to USD
75 // assertEquals("Result is 59 USD");
76 result = c.convert(CurrencyValue.getCurrencyValue(1003, "CZK"));
77 assertEquals(CurrencyValue.getCurrencyValue(59, "USD"), result);
80 /** Use the convertor from <code>createSKKtoCZK</code> method and do few conversions
83 public void testCurrencySKKCZK() throws Exception {
84 Convertor<Integer, String> c = createSKKtoCZK();
86 CurrencyValue<Integer, String> result;
88 // convert 16CZK using c:
89 // assertEquals("Result is 20 SKK");
90 result = c.convert(CurrencyValue.getCurrencyValue(16, "CZK"));
91 assertEquals(CurrencyValue.getCurrencyValue(20, "SKK"), result);
93 // convert 500SKK to CZK
94 // assertEquals("Result is 400 CZK");
95 result = c.convert(CurrencyValue.getCurrencyValue(500, "SKK"));
96 assertEquals(CurrencyValue.getCurrencyValue(400, "CZK"), result);