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;
10 /** Write a test that works with version from task A and fails with version B.
12 public class CurrencyTest extends TestCase {
13 public CurrencyTest(String n) {
17 /** Fails because runtime incompatibility. */
18 public void testCompatibility() throws Exception {
19 ConvertorCurrency cur1 = ConvertorCurrency.getInstance("CZK");
20 ConvertorCurrency cur2 = ConvertorCurrency.getInstance("CZK");
22 assertEquals(false, cur1.equals(cur2));
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);
32 boolean result = provider.addFixedCurencyRate(
33 ConvertorCurrency.getInstance("CZK"), new BigDecimal("80"),
34 ConvertorCurrency.getInstance("SKK"), new BigDecimal("100"));
35 assertEquals(true, result);
38 class MyOwnExchangeRateProvider extends ExchangeRateProvider {
40 public MyOwnExchangeRateProvider(BigDecimal fromValue, ConvertorCurrency fromCurrency, BigDecimal toValue, ConvertorCurrency toCurrency) {
41 super(fromValue, fromCurrency, toValue, toCurrency);
44 public boolean addFixedCurencyRate(ConvertorCurrency fromCurrency, BigDecimal fromValue, ConvertorCurrency toCurrency, BigDecimal toValue) {
45 return true; // great method - do nothing and is always satisfied ;-)