taskx/ked/against-solution14/test/apifest/CurrencyTest.java
changeset 83 621462e58e22
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/taskx/ked/against-solution14/test/apifest/CurrencyTest.java	Sat Oct 25 20:30:54 2008 +0200
     1.3 @@ -0,0 +1,56 @@
     1.4 +package apifest;
     1.5 +
     1.6 +import junit.framework.TestCase;
     1.7 +import org.apidesign.apifest08.currency.Convertor;
     1.8 +import org.apidesign.apifest08.currency.ConvertorFactory;
     1.9 +import org.apidesign.apifest08.currency.CurrencyRate;
    1.10 +import org.apidesign.apifest08.currency.Rate;
    1.11 +
    1.12 +
    1.13 +/** Write a test that works with version from task A and fails with version B.
    1.14 + */
    1.15 +public class CurrencyTest extends TestCase {
    1.16 +    public CurrencyTest(String n) {
    1.17 +        super(n);
    1.18 +    }
    1.19 +    
    1.20 +    public void testCompatibility() throws Exception {
    1.21 +        
    1.22 +        Convertor c = ConvertorFactory.newInstance().createConvertor(
    1.23 +                new MyOwnCurrencyRate("CZK", "USD", new Rate(1, 16), "ABCDEF"));
    1.24 +        
    1.25 +        MyOwnCurrencyRate[] arr = c.getCurrencyRates().toArray(new MyOwnCurrencyRate[1]);
    1.26 +        assertEquals("ABCDEF", arr[0].getMyImportantProperty());
    1.27 +    }
    1.28 +    
    1.29 +    class MyOwnCurrencyRate implements CurrencyRate {
    1.30 +
    1.31 +        private final String currency1;
    1.32 +        private final String currency2;
    1.33 +        private final Rate rate;
    1.34 +        private final String myImportantProperty;
    1.35 +        
    1.36 +        public MyOwnCurrencyRate(String currency1, String currency2, Rate rate, String myImportantProperty) {
    1.37 +            this.currency1 = currency1;
    1.38 +            this.currency2 = currency2;
    1.39 +            this.rate = rate;
    1.40 +            this.myImportantProperty = myImportantProperty;
    1.41 +        }
    1.42 +        
    1.43 +        public String getCurrency1() {
    1.44 +            return currency1;
    1.45 +        }
    1.46 +
    1.47 +        public String getCurrency2() {
    1.48 +            return currency2;
    1.49 +        }
    1.50 +
    1.51 +        public Rate getRate() {
    1.52 +            return rate;
    1.53 +        }
    1.54 +
    1.55 +        public String getMyImportantProperty() {
    1.56 +            return myImportantProperty;
    1.57 +        }
    1.58 +    }
    1.59 +}