1 package org.apidesign.apifest08.test;
3 import java.util.Currency;
4 import junit.framework.TestCase;
5 import org.apidesign.apifest08.currency.Convertor;
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 createCZKtoUSD() {
35 return Convertor.getInstanceFor(Currency.getInstance("CZK"), Currency.getInstance("USD"));
38 /** Create convertor that understands two currencies, CZK and
39 * SKK. Make 100 SKK == 80 CZK.
41 * Creation of the convertor shall not require subclassing of any class
42 * or interface on the client side.
44 * @return prepared convertor ready for converting SKK to CZK and CZK to SKK
46 public static Convertor createSKKtoCZK() {
47 return Convertor.getInstanceFor(Currency.getInstance("SKK"), Currency.getInstance("CZK"));
50 /** Use the convertor from <code>createCZKtoUSD</code> method and do few conversions
53 public void testCurrencyCZKUSD() throws Exception {
54 Convertor c = createCZKtoUSD();
55 Currency usd = Currency.getInstance("USD");
56 Currency czk = Currency.getInstance("CZK");
57 // convert $5 to CZK using c:
58 // assertEquals("Result is 85 CZK");
59 assertEquals(85F, c.convert(5, usd));
62 // assertEquals("Result is 136 CZK");
63 assertEquals(136F, c.convert(8, usd));
65 // convert 1003CZK to USD
66 // assertEquals("Result is 59 USD");
67 assertEquals(59F, c.convert(1003, czk));
70 /** Use the convertor from <code>createSKKtoCZK</code> method and do few conversions
73 public void testCurrencySKKCZK() throws Exception {
74 Convertor c = createSKKtoCZK();
75 Currency skk = Currency.getInstance("SKK");
76 Currency czk = Currency.getInstance("CZK");
77 // convert 16CZK using c:
78 // assertEquals("Result is 20 SKK");
79 assertEquals(20F, c.convert(16, skk));
81 // convert 500SKK to CZK
82 // assertEquals("Result is 400 CZK");
83 assertEquals(400F, c.convert(500, czk));