task2/solution09/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/solution09/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
import org.apidesign.apifest08.currency.ConvertorFactory;
japod@6
     6
import org.apidesign.apifest08.currency.CurrencyType;
japod@6
     7
japod@6
     8
/** Finish the Convertor API, and then write bodies of methods inside
japod@6
     9
 * of this class to match the given tasks. To fullfil your task, use the
japod@6
    10
 * API define in the <code>org.apidesign.apifest08.currency</code> package.
japod@6
    11
 * Do not you reflection, or other hacks as your code
japod@6
    12
 * shall run without any runtime permissions.
japod@6
    13
 */
japod@6
    14
public class Task1Test extends TestCase {
japod@6
    15
    public Task1Test(String testName) {
japod@6
    16
        super(testName);
japod@6
    17
    }
japod@6
    18
japod@6
    19
japod@6
    20
    /** Create convertor that understands two currencies, CZK and
japod@6
    21
     *  USD. Make 1 USD == 17 CZK.
japod@6
    22
     *
japod@6
    23
     * Creation of the convertor shall not require subclassing of any class
japod@6
    24
     * or interface on the client side.
japod@6
    25
     *
japod@6
    26
     * @return prepared convertor ready for converting USD to CZK and CZK to USD
japod@6
    27
     */
japod@6
    28
    public static Convertor createCZKtoUSD() {
japod@6
    29
        return ConvertorFactory.getConvertor(CurrencyType.CZK, CurrencyType.USD);
japod@6
    30
    }
japod@6
    31
japod@6
    32
    /** Create convertor that understands two currencies, CZK and
japod@6
    33
     *  SKK. Make 100 SKK == 80 CZK.
japod@6
    34
     *
japod@6
    35
     * Creation of the convertor shall not require subclassing of any class
japod@6
    36
     * or interface on the client side.
japod@6
    37
     * 
japod@6
    38
     * @return prepared convertor ready for converting SKK to CZK and CZK to SKK
japod@6
    39
     */
japod@6
    40
    public static Convertor createSKKtoCZK() {
japod@6
    41
        return ConvertorFactory.getConvertor(CurrencyType.SKK, CurrencyType.CZK);
japod@6
    42
    }
japod@6
    43
    
japod@6
    44
    /** Use the convertor from <code>createCZKtoUSD</code> method and do few conversions
japod@6
    45
     * with it.
japod@6
    46
     */
japod@6
    47
    public void testCurrencyCZKUSD() throws Exception {
japod@6
    48
        Convertor c = createCZKtoUSD();
japod@6
    49
japod@6
    50
        // convert $5 to CZK using c:
japod@6
    51
        // assertEquals("Result is 85 CZK");
japod@6
    52
        assertEquals(85, c.convertTo(5));
japod@6
    53
japod@6
    54
        // convert $8 to CZK
japod@6
    55
        // assertEquals("Result is 136 CZK");
japod@6
    56
        assertEquals(136, c.convertTo(8));
japod@6
    57
japod@6
    58
        // convert 1003CZK to USD
japod@6
    59
        // assertEquals("Result is 59 USD");
japod@6
    60
        assertEquals(59, c.convertFrom(1003));
japod@6
    61
    }
japod@6
    62
japod@6
    63
    /** Use the convertor from <code>createSKKtoCZK</code> method and do few conversions
japod@6
    64
     * with it.
japod@6
    65
     */
japod@6
    66
    public void testCurrencySKKCZK() throws Exception {
japod@6
    67
        Convertor c = createSKKtoCZK();
japod@6
    68
        // convert 16CZK using c:
japod@6
    69
        // assertEquals("Result is 20 SKK");
japod@6
    70
        assertEquals(20, c.convertFrom(16));
japod@6
    71
japod@6
    72
        // convert 500SKK to CZK
japod@6
    73
        // assertEquals("Result is 400 CZK");
japod@6
    74
        assertEquals(400, c.convertTo(500));
japod@6
    75
    }
japod@6
    76
}
japod@6
    77