task2/solution03/test/org/apidesign/apifest08/test/Task1Test.java
author Jaroslav Tulach <jaroslav.tulach@apidesign.org>
Wed, 01 Oct 2008 10:43:05 +0200
changeset 29 f6073056b9fe
parent 6 task1/solution03/test/org/apidesign/apifest08/test/Task1Test.java@97662396c0fd
permissions -rw-r--r--
Getting ready for task2: copying all solutions to new locations
japod@6
     1
package org.apidesign.apifest08.test;
japod@6
     2
japod@6
     3
import junit.framework.TestCase;
japod@6
     4
import org.apidesign.apifest08.currency.Convertor;
japod@6
     5
japod@6
     6
/** Finish the Convertor API, and then write bodies of methods inside
japod@6
     7
 * of this class to match the given tasks. To fullfil your task, use the
japod@6
     8
 * API define in the <code>org.apidesign.apifest08.currency</code> package.
japod@6
     9
 * Do not you reflection, or other hacks as your code
japod@6
    10
 * shall run without any runtime permissions.
japod@6
    11
 */
japod@6
    12
public class Task1Test extends TestCase {
japod@6
    13
japod@6
    14
    public Task1Test(String testName) {
japod@6
    15
        super(testName);
japod@6
    16
    }
japod@6
    17
japod@6
    18
    @Override
japod@6
    19
    protected void setUp() throws Exception {
japod@6
    20
    }
japod@6
    21
japod@6
    22
    @Override
japod@6
    23
    protected void tearDown() throws Exception {
japod@6
    24
    }
japod@6
    25
japod@6
    26
    /** Create convertor that understands two currencies, CZK and
japod@6
    27
     *  USD. Make 1 USD == 17 CZK.
japod@6
    28
     *
japod@6
    29
     * Creation of the convertor shall not require subclassing of any class
japod@6
    30
     * or interface on the client side.
japod@6
    31
     *
japod@6
    32
     * @return prepared convertor ready for converting USD to CZK and CZK to USD
japod@6
    33
     */
japod@6
    34
    public static Convertor createCZKtoUSD() {
japod@6
    35
        return new Convertor(17, 1);
japod@6
    36
    }
japod@6
    37
japod@6
    38
    /** Create convertor that understands two currencies, CZK and
japod@6
    39
     *  SKK. Make 100 SKK == 80 CZK.
japod@6
    40
     *
japod@6
    41
     * Creation of the convertor shall not require subclassing of any class
japod@6
    42
     * or interface on the client side.
japod@6
    43
     * 
japod@6
    44
     * @return prepared convertor ready for converting SKK to CZK and CZK to SKK
japod@6
    45
     */
japod@6
    46
    public static Convertor createSKKtoCZK() {
japod@6
    47
        return new Convertor(100, 80);
japod@6
    48
    }
japod@6
    49
japod@6
    50
    /** Use the convertor from <code>createCZKtoUSD</code> method and do few conversions
japod@6
    51
     * with it.
japod@6
    52
     */
japod@6
    53
    public void testCurrencyCZKUSD() throws Exception {
japod@6
    54
        Convertor c = createCZKtoUSD();
japod@6
    55
        // convert $5 to CZK using c:
japod@6
    56
        // assertEquals("Result is 85 CZK");
japod@6
    57
        assertEquals(c.convert(5, Convertor.SECOND_TO_FIRST), (double) 85);
japod@6
    58
japod@6
    59
        // convert $8 to CZK
japod@6
    60
        // assertEquals("Result is 136 CZK");
japod@6
    61
        assertEquals(c.convert(8, Convertor.SECOND_TO_FIRST), (double) 136);
japod@6
    62
japod@6
    63
        // convert 1003CZK to USD
japod@6
    64
        // assertEquals("Result is 59 USD");
japod@6
    65
        assertEquals(c.convert(1003, Convertor.FIRST_TO_SECOND), (double) 59);
japod@6
    66
    }
japod@6
    67
japod@6
    68
    /** Use the convertor from <code>createSKKtoCZK</code> method and do few conversions
japod@6
    69
     * with it.
japod@6
    70
     */
japod@6
    71
    public void testCurrencySKKCZK() throws Exception {
japod@6
    72
        Convertor c = createSKKtoCZK();
japod@6
    73
        // convert 16CZK using c:
japod@6
    74
        // assertEquals("Result is 20 SKK");
japod@6
    75
        assertEquals(c.convert(16, Convertor.SECOND_TO_FIRST), (double) 20);
japod@6
    76
japod@6
    77
        // convert 500SKK to CZK
japod@6
    78
        // assertEquals("Result is 400 CZK");
japod@6
    79
        assertEquals(c.convert(500, Convertor.FIRST_TO_SECOND), (double) 400);
japod@6
    80
    }
japod@6
    81
}
japod@6
    82