taskx/ked/against-solution14/test/apifest/CurrencyTest.java
author Jaroslav Tulach <jtulach@netbeans.org>
Sat, 25 Oct 2008 20:30:54 +0200
changeset 83 621462e58e22
permissions -rw-r--r--
Jan Zak managed to break solutions 4, 6, 13, 14
jtulach@83
     1
package apifest;
jtulach@83
     2
jtulach@83
     3
import junit.framework.TestCase;
jtulach@83
     4
import org.apidesign.apifest08.currency.Convertor;
jtulach@83
     5
import org.apidesign.apifest08.currency.ConvertorFactory;
jtulach@83
     6
import org.apidesign.apifest08.currency.CurrencyRate;
jtulach@83
     7
import org.apidesign.apifest08.currency.Rate;
jtulach@83
     8
jtulach@83
     9
jtulach@83
    10
/** Write a test that works with version from task A and fails with version B.
jtulach@83
    11
 */
jtulach@83
    12
public class CurrencyTest extends TestCase {
jtulach@83
    13
    public CurrencyTest(String n) {
jtulach@83
    14
        super(n);
jtulach@83
    15
    }
jtulach@83
    16
    
jtulach@83
    17
    public void testCompatibility() throws Exception {
jtulach@83
    18
        
jtulach@83
    19
        Convertor c = ConvertorFactory.newInstance().createConvertor(
jtulach@83
    20
                new MyOwnCurrencyRate("CZK", "USD", new Rate(1, 16), "ABCDEF"));
jtulach@83
    21
        
jtulach@83
    22
        MyOwnCurrencyRate[] arr = c.getCurrencyRates().toArray(new MyOwnCurrencyRate[1]);
jtulach@83
    23
        assertEquals("ABCDEF", arr[0].getMyImportantProperty());
jtulach@83
    24
    }
jtulach@83
    25
    
jtulach@83
    26
    class MyOwnCurrencyRate implements CurrencyRate {
jtulach@83
    27
jtulach@83
    28
        private final String currency1;
jtulach@83
    29
        private final String currency2;
jtulach@83
    30
        private final Rate rate;
jtulach@83
    31
        private final String myImportantProperty;
jtulach@83
    32
        
jtulach@83
    33
        public MyOwnCurrencyRate(String currency1, String currency2, Rate rate, String myImportantProperty) {
jtulach@83
    34
            this.currency1 = currency1;
jtulach@83
    35
            this.currency2 = currency2;
jtulach@83
    36
            this.rate = rate;
jtulach@83
    37
            this.myImportantProperty = myImportantProperty;
jtulach@83
    38
        }
jtulach@83
    39
        
jtulach@83
    40
        public String getCurrency1() {
jtulach@83
    41
            return currency1;
jtulach@83
    42
        }
jtulach@83
    43
jtulach@83
    44
        public String getCurrency2() {
jtulach@83
    45
            return currency2;
jtulach@83
    46
        }
jtulach@83
    47
jtulach@83
    48
        public Rate getRate() {
jtulach@83
    49
            return rate;
jtulach@83
    50
        }
jtulach@83
    51
jtulach@83
    52
        public String getMyImportantProperty() {
jtulach@83
    53
            return myImportantProperty;
jtulach@83
    54
        }
jtulach@83
    55
    }
jtulach@83
    56
}