taskx/ked/against-solution13/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 junit.framework.TestCase;
     5 import org.apidesign.apifest08.currency.Convertor;
     6 import org.apidesign.apifest08.currency.ConvertorCurrency;
     7 import org.apidesign.apifest08.currency.ExchangeRateProvider;
     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     /** Fails because runtime incompatibility. */
    18     public void testCompatibility() throws Exception {
    19         ConvertorCurrency cur1 = ConvertorCurrency.getInstance("CZK");
    20         ConvertorCurrency cur2 = ConvertorCurrency.getInstance("CZK");
    21         
    22         assertEquals(false, cur1.equals(cur2));
    23     }
    24 
    25     /** Fails because source incompatibility. */
    26     public void testCompatibility2() throws Exception {
    27         MyOwnExchangeRateProvider provider = new MyOwnExchangeRateProvider(
    28                 new BigDecimal("1"), ConvertorCurrency.getInstance("USD"),
    29                 new BigDecimal("16"), ConvertorCurrency.getInstance("CZK"));
    30         Convertor c = Convertor.createConvertor(provider);
    31         
    32         boolean result = provider.addFixedCurencyRate(
    33                 ConvertorCurrency.getInstance("CZK"), new BigDecimal("80"),
    34                 ConvertorCurrency.getInstance("SKK"), new BigDecimal("100"));
    35         assertEquals(true, result);
    36     }
    37     
    38     class MyOwnExchangeRateProvider extends ExchangeRateProvider {
    39 
    40         public MyOwnExchangeRateProvider(BigDecimal fromValue, ConvertorCurrency fromCurrency, BigDecimal toValue, ConvertorCurrency toCurrency) {
    41             super(fromValue, fromCurrency, toValue, toCurrency);
    42         }
    43     
    44         public boolean addFixedCurencyRate(ConvertorCurrency fromCurrency, BigDecimal fromValue, ConvertorCurrency toCurrency, BigDecimal toValue) {
    45             return true; // great method - do nothing and is always satisfied ;-)
    46         }
    47 
    48     }
    49 }