taskx/ked/against-solution04/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-solution04/test/apifest/CurrencyTest.java	Sat Oct 25 20:30:54 2008 +0200
     1.3 @@ -0,0 +1,33 @@
     1.4 +package apifest;
     1.5 +
     1.6 +import java.math.BigDecimal;
     1.7 +import java.util.Currency;
     1.8 +import junit.framework.TestCase;
     1.9 +import org.apidesign.apifest08.currency.Convertor;
    1.10 +import org.apidesign.apifest08.currency.InvalidConversionException;
    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 +        Convertor myOwnImplementationOfConvertor =
    1.22 +                new MyOwnImplementationOfConvertor();
    1.23 +        
    1.24 +        BigDecimal result = myOwnImplementationOfConvertor.convert(
    1.25 +                Currency.getInstance("CZK"),
    1.26 +                Currency.getInstance("USD"),
    1.27 +                new BigDecimal("1"));
    1.28 +        assertEquals(1, result.intValue());
    1.29 +    }
    1.30 +    
    1.31 +    class MyOwnImplementationOfConvertor implements Convertor {
    1.32 +        public BigDecimal convert(Currency from, Currency to, BigDecimal amount) throws InvalidConversionException {
    1.33 +            return amount; // not very smart implementation
    1.34 +        }
    1.35 +    }
    1.36 +}