taskx/ked/against-solution04/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 java.math.BigDecimal;
     4 import java.util.Currency;
     5 import junit.framework.TestCase;
     6 import org.apidesign.apifest08.currency.Convertor;
     7 import org.apidesign.apifest08.currency.InvalidConversionException;
     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         Convertor myOwnImplementationOfConvertor =
    19                 new MyOwnImplementationOfConvertor();
    20         
    21         BigDecimal result = myOwnImplementationOfConvertor.convert(
    22                 Currency.getInstance("CZK"),
    23                 Currency.getInstance("USD"),
    24                 new BigDecimal("1"));
    25         assertEquals(1, result.intValue());
    26     }
    27     
    28     class MyOwnImplementationOfConvertor implements Convertor {
    29         public BigDecimal convert(Currency from, Currency to, BigDecimal amount) throws InvalidConversionException {
    30             return amount; // not very smart implementation
    31         }
    32     }
    33 }