1 package org.apidesign.apifest08.test;
3 import junit.framework.TestCase;
4 import org.apidesign.apifest08.currency.Convertor;
5 import org.apidesign.apifest08.currency.ConvertorFactory;
6 import org.apidesign.apifest08.currency.CurrencyType;
8 /** Finish the Convertor API, and then write bodies of methods inside
9 * of this class to match the given tasks. To fullfil your task, use the
10 * API define in the <code>org.apidesign.apifest08.currency</code> package.
11 * Do not you reflection, or other hacks as your code
12 * shall run without any runtime permissions.
14 public class Task1Test extends TestCase {
15 public Task1Test(String testName) {
20 /** Create convertor that understands two currencies, CZK and
21 * USD. Make 1 USD == 17 CZK.
23 * Creation of the convertor shall not require subclassing of any class
24 * or interface on the client side.
26 * @return prepared convertor ready for converting USD to CZK and CZK to USD
28 public static Convertor createCZKtoUSD() {
29 return ConvertorFactory.getConvertor(CurrencyType.CZK, CurrencyType.USD);
32 /** Create convertor that understands two currencies, CZK and
33 * SKK. Make 100 SKK == 80 CZK.
35 * Creation of the convertor shall not require subclassing of any class
36 * or interface on the client side.
38 * @return prepared convertor ready for converting SKK to CZK and CZK to SKK
40 public static Convertor createSKKtoCZK() {
41 return ConvertorFactory.getConvertor(CurrencyType.SKK, CurrencyType.CZK);
44 /** Use the convertor from <code>createCZKtoUSD</code> method and do few conversions
47 public void testCurrencyCZKUSD() throws Exception {
48 Convertor c = createCZKtoUSD();
50 // convert $5 to CZK using c:
51 // assertEquals("Result is 85 CZK");
52 assertEquals(85, c.convertTo(5));
55 // assertEquals("Result is 136 CZK");
56 assertEquals(136, c.convertTo(8));
58 // convert 1003CZK to USD
59 // assertEquals("Result is 59 USD");
60 assertEquals(59, c.convertFrom(1003));
63 /** Use the convertor from <code>createSKKtoCZK</code> method and do few conversions
66 public void testCurrencySKKCZK() throws Exception {
67 Convertor c = createSKKtoCZK();
68 // convert 16CZK using c:
69 // assertEquals("Result is 20 SKK");
70 assertEquals(20, c.convertFrom(16));
72 // convert 500SKK to CZK
73 // assertEquals("Result is 400 CZK");
74 assertEquals(400, c.convertTo(500));