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
     1 package org.apidesign.apifest08.test;
     2 
     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;
     7 
     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.
    13  */
    14 public class Task1Test extends TestCase {
    15     public Task1Test(String testName) {
    16         super(testName);
    17     }
    18 
    19 
    20     /** Create convertor that understands two currencies, CZK and
    21      *  USD. Make 1 USD == 17 CZK.
    22      *
    23      * Creation of the convertor shall not require subclassing of any class
    24      * or interface on the client side.
    25      *
    26      * @return prepared convertor ready for converting USD to CZK and CZK to USD
    27      */
    28     public static Convertor createCZKtoUSD() {
    29         return ConvertorFactory.getConvertor(CurrencyType.CZK, CurrencyType.USD);
    30     }
    31 
    32     /** Create convertor that understands two currencies, CZK and
    33      *  SKK. Make 100 SKK == 80 CZK.
    34      *
    35      * Creation of the convertor shall not require subclassing of any class
    36      * or interface on the client side.
    37      * 
    38      * @return prepared convertor ready for converting SKK to CZK and CZK to SKK
    39      */
    40     public static Convertor createSKKtoCZK() {
    41         return ConvertorFactory.getConvertor(CurrencyType.SKK, CurrencyType.CZK);
    42     }
    43     
    44     /** Use the convertor from <code>createCZKtoUSD</code> method and do few conversions
    45      * with it.
    46      */
    47     public void testCurrencyCZKUSD() throws Exception {
    48         Convertor c = createCZKtoUSD();
    49 
    50         // convert $5 to CZK using c:
    51         // assertEquals("Result is 85 CZK");
    52         assertEquals(85, c.convertTo(5));
    53 
    54         // convert $8 to CZK
    55         // assertEquals("Result is 136 CZK");
    56         assertEquals(136, c.convertTo(8));
    57 
    58         // convert 1003CZK to USD
    59         // assertEquals("Result is 59 USD");
    60         assertEquals(59, c.convertFrom(1003));
    61     }
    62 
    63     /** Use the convertor from <code>createSKKtoCZK</code> method and do few conversions
    64      * with it.
    65      */
    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));
    71 
    72         // convert 500SKK to CZK
    73         // assertEquals("Result is 400 CZK");
    74         assertEquals(400, c.convertTo(500));
    75     }
    76 }
    77