currency/test/org/apidesign/apifest08/test/Task1Test.java
author Jaroslav Tulach <jaroslav.tulach@apidesign.org>
Sun, 28 Sep 2008 20:05:56 +0200
changeset 12 b6c21003ddc9
parent 3 81bafaac7336
child 30 87751527ce97
permissions -rw-r--r--
More preciselly specified tasks for round "one and half"
jtulach@0
     1
package org.apidesign.apifest08.test;
jtulach@0
     2
jtulach@0
     3
import junit.framework.TestCase;
jaroslav@1
     4
import org.apidesign.apifest08.currency.Convertor;
jtulach@0
     5
jaroslav@1
     6
/** Finish the Convertor API, and then write bodies of methods inside
jaroslav@3
     7
 * of this class to match the given tasks. To fullfil your task, use the
jaroslav@3
     8
 * API define in the <code>org.apidesign.apifest08.currency</code> package.
jaroslav@3
     9
 * Do not you reflection, or other hacks as your code
jaroslav@3
    10
 * shall run without any runtime permissions.
jtulach@0
    11
 */
jtulach@0
    12
public class Task1Test extends TestCase {
jtulach@0
    13
    public Task1Test(String testName) {
jtulach@0
    14
        super(testName);
jtulach@0
    15
    }
jtulach@0
    16
jtulach@0
    17
    @Override
jtulach@0
    18
    protected void setUp() throws Exception {
jtulach@0
    19
    }
jtulach@0
    20
jtulach@0
    21
    @Override
jtulach@0
    22
    protected void tearDown() throws Exception {
jtulach@0
    23
    }
jaroslav@1
    24
jaroslav@12
    25
    //
jaroslav@12
    26
    // Imagine that there are three parts of the whole system:
jaroslav@12
    27
    // 1. there is someone who knows the current exchange rate
jaroslav@12
    28
    // 2. there is someone who wants to do the conversion
jaroslav@12
    29
    // 3. there is the API between 1. and 2. which allows them to communicate
jaroslav@12
    30
    // Please design such API
jaroslav@12
    31
    //
jaroslav@12
    32
jaroslav@1
    33
    /** Create convertor that understands two currencies, CZK and
jaroslav@12
    34
     *  USD. Make 1 USD == 17 CZK. This is a method provided for #1 group -
jaroslav@12
    35
     *  e.g. those that know the exchange rate. They somehow need to create
jaroslav@12
    36
     *  the objects from the API and tell them the exchange rate. The API itself
jaroslav@12
    37
     *  knows nothing about any rates, before the createCZKtoUSD method is called.
jaroslav@1
    38
     *
jaroslav@3
    39
     * Creation of the convertor shall not require subclassing of any class
jaroslav@3
    40
     * or interface on the client side.
jaroslav@3
    41
     *
jaroslav@1
    42
     * @return prepared convertor ready for converting USD to CZK and CZK to USD
jaroslav@1
    43
     */
jaroslav@1
    44
    public static Convertor createCZKtoUSD() {
jaroslav@1
    45
        return null;
jaroslav@1
    46
    }
jaroslav@1
    47
jaroslav@1
    48
    /** Create convertor that understands two currencies, CZK and
jaroslav@12
    49
     *  SKK. Make 100 SKK == 80 CZK. Again this is method for the #1 group -
jaroslav@12
    50
     *  it knows the exchange rate, and needs to use the API to create objects
jaroslav@12
    51
     *  with the exchange rate. Anyone shall be ready to call this method without
jaroslav@12
    52
     *  any other method being called previously. The API itself shall know
jaroslav@12
    53
     *  nothing about any rates, before this method is called.
jaroslav@1
    54
     *
jaroslav@3
    55
     * Creation of the convertor shall not require subclassing of any class
jaroslav@3
    56
     * or interface on the client side.
jaroslav@3
    57
     * 
jaroslav@1
    58
     * @return prepared convertor ready for converting SKK to CZK and CZK to SKK
jaroslav@1
    59
     */
jaroslav@1
    60
    public static Convertor createSKKtoCZK() {
jaroslav@1
    61
        return null;
jaroslav@1
    62
    }
jaroslav@12
    63
jaroslav@12
    64
    //
jaroslav@12
    65
    // now the methods for group #2 follow:
jaroslav@12
    66
    // this group knows nothing about exchange rates, but knows how to use
jaroslav@12
    67
    // the API to do conversions. It somehow (by calling one of the factory
jaroslav@12
    68
    // methods) gets objects from the API and uses them to do the conversions.
jaroslav@12
    69
    //
jtulach@0
    70
    
jaroslav@1
    71
    /** Use the convertor from <code>createCZKtoUSD</code> method and do few conversions
jaroslav@1
    72
     * with it.
jaroslav@1
    73
     */
jtulach@0
    74
    public void testCurrencyCZKUSD() throws Exception {
jaroslav@1
    75
        Convertor c = createCZKtoUSD();
jaroslav@1
    76
        // convert $5 to CZK using c:
jaroslav@1
    77
        // assertEquals("Result is 85 CZK");
jaroslav@1
    78
jaroslav@1
    79
        // convert $8 to CZK
jaroslav@1
    80
        // assertEquals("Result is 136 CZK");
jaroslav@1
    81
jaroslav@1
    82
        // convert 1003CZK to USD
jaroslav@1
    83
        // assertEquals("Result is 59 USD");
jaroslav@1
    84
    }
jaroslav@1
    85
jaroslav@1
    86
    /** Use the convertor from <code>createSKKtoCZK</code> method and do few conversions
jaroslav@1
    87
     * with it.
jaroslav@1
    88
     */
jaroslav@1
    89
    public void testCurrencySKKCZK() throws Exception {
jaroslav@1
    90
        Convertor c = createSKKtoCZK();
jaroslav@1
    91
        // convert 16CZK using c:
jaroslav@1
    92
        // assertEquals("Result is 20 SKK");
jaroslav@1
    93
jaroslav@1
    94
        // convert 500SKK to CZK
jaroslav@1
    95
        // assertEquals("Result is 400 CZK");
jtulach@0
    96
    }
jaroslav@12
    97
jaroslav@12
    98
    /** Verify that the CZK to USD convertor knows nothing about SKK.
jaroslav@12
    99
     */
jaroslav@12
   100
    public void testCannotConvertToSKKwithCZKUSDConvertor() throws Exception {
jaroslav@12
   101
        Convertor c = createCZKtoUSD();
jaroslav@12
   102
        // convert $5 to SKK, the API shall say this is not possible
jaroslav@12
   103
        // convert 500 SKK to CZK, the API shall say this is not possible
jaroslav@12
   104
    }
jaroslav@12
   105
jaroslav@12
   106
    /** Verify that the CZK to SKK convertor knows nothing about USD.
jaroslav@12
   107
     */
jaroslav@12
   108
    public void testCannotConvertToSKKwithCZKUSDConvertor() throws Exception {
jaroslav@12
   109
        Convertor c = createSKKtoCZK();
jaroslav@12
   110
        // convert $5 to SKK, the API shall say this is not possible
jaroslav@12
   111
        // convert 500 CZK to USD, the API shall say this is not possible
jaroslav@12
   112
    }
jtulach@0
   113
}