1 package org.apidesign.apifest08.test;
3 import junit.framework.TestCase;
4 import org.apidesign.apifest08.currency.Convertor;
6 /** Finish the Convertor API, and then write bodies of methods inside
7 * of this class to match the given tasks. To fullfil your task, use the
8 * API define in the <code>org.apidesign.apifest08.currency</code> package.
9 * Do not you reflection, or other hacks as your code
10 * shall run without any runtime permissions.
12 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 new Convertor(17, 1);
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 new Convertor(100, 80);
50 /** Use the convertor from <code>createCZKtoUSD</code> method and do few conversions
53 public void testCurrencyCZKUSD() throws Exception {
54 Convertor c = createCZKtoUSD();
55 // convert $5 to CZK using c:
56 // assertEquals("Result is 85 CZK");
57 assertEquals(c.convert(5, Convertor.SECOND_TO_FIRST), (double) 85);
60 // assertEquals("Result is 136 CZK");
61 assertEquals(c.convert(8, Convertor.SECOND_TO_FIRST), (double) 136);
63 // convert 1003CZK to USD
64 // assertEquals("Result is 59 USD");
65 assertEquals(c.convert(1003, Convertor.FIRST_TO_SECOND), (double) 59);
68 /** Use the convertor from <code>createSKKtoCZK</code> method and do few conversions
71 public void testCurrencySKKCZK() throws Exception {
72 Convertor c = createSKKtoCZK();
73 // convert 16CZK using c:
74 // assertEquals("Result is 20 SKK");
75 assertEquals(c.convert(16, Convertor.SECOND_TO_FIRST), (double) 20);
77 // convert 500SKK to CZK
78 // assertEquals("Result is 400 CZK");
79 assertEquals(c.convert(500, Convertor.FIRST_TO_SECOND), (double) 400);