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
     1 package apifest;
     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.CurrencyRate;
     7 import org.apidesign.apifest08.currency.Rate;
     8 
     9 
    10 /** Write a test that works with version from task A and fails with version B.
    11  */
    12 public class CurrencyTest extends TestCase {
    13     public CurrencyTest(String n) {
    14         super(n);
    15     }
    16     
    17     public void testCompatibility() throws Exception {
    18         
    19         Convertor c = ConvertorFactory.newInstance().createConvertor(
    20                 new MyOwnCurrencyRate("CZK", "USD", new Rate(1, 16), "ABCDEF"));
    21         
    22         MyOwnCurrencyRate[] arr = c.getCurrencyRates().toArray(new MyOwnCurrencyRate[1]);
    23         assertEquals("ABCDEF", arr[0].getMyImportantProperty());
    24     }
    25     
    26     class MyOwnCurrencyRate implements CurrencyRate {
    27 
    28         private final String currency1;
    29         private final String currency2;
    30         private final Rate rate;
    31         private final String myImportantProperty;
    32         
    33         public MyOwnCurrencyRate(String currency1, String currency2, Rate rate, String myImportantProperty) {
    34             this.currency1 = currency1;
    35             this.currency2 = currency2;
    36             this.rate = rate;
    37             this.myImportantProperty = myImportantProperty;
    38         }
    39         
    40         public String getCurrency1() {
    41             return currency1;
    42         }
    43 
    44         public String getCurrency2() {
    45             return currency2;
    46         }
    47 
    48         public Rate getRate() {
    49             return rate;
    50         }
    51 
    52         public String getMyImportantProperty() {
    53             return myImportantProperty;
    54         }
    55     }
    56 }