1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/taskx/ked/against-solution13/test/apifest/CurrencyTest.java Sat Oct 25 20:30:54 2008 +0200
1.3 @@ -0,0 +1,49 @@
1.4 +package apifest;
1.5 +
1.6 +import java.math.BigDecimal;
1.7 +import junit.framework.TestCase;
1.8 +import org.apidesign.apifest08.currency.Convertor;
1.9 +import org.apidesign.apifest08.currency.ConvertorCurrency;
1.10 +import org.apidesign.apifest08.currency.ExchangeRateProvider;
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 + /** Fails because runtime incompatibility. */
1.21 + public void testCompatibility() throws Exception {
1.22 + ConvertorCurrency cur1 = ConvertorCurrency.getInstance("CZK");
1.23 + ConvertorCurrency cur2 = ConvertorCurrency.getInstance("CZK");
1.24 +
1.25 + assertEquals(false, cur1.equals(cur2));
1.26 + }
1.27 +
1.28 + /** Fails because source incompatibility. */
1.29 + public void testCompatibility2() throws Exception {
1.30 + MyOwnExchangeRateProvider provider = new MyOwnExchangeRateProvider(
1.31 + new BigDecimal("1"), ConvertorCurrency.getInstance("USD"),
1.32 + new BigDecimal("16"), ConvertorCurrency.getInstance("CZK"));
1.33 + Convertor c = Convertor.createConvertor(provider);
1.34 +
1.35 + boolean result = provider.addFixedCurencyRate(
1.36 + ConvertorCurrency.getInstance("CZK"), new BigDecimal("80"),
1.37 + ConvertorCurrency.getInstance("SKK"), new BigDecimal("100"));
1.38 + assertEquals(true, result);
1.39 + }
1.40 +
1.41 + class MyOwnExchangeRateProvider extends ExchangeRateProvider {
1.42 +
1.43 + public MyOwnExchangeRateProvider(BigDecimal fromValue, ConvertorCurrency fromCurrency, BigDecimal toValue, ConvertorCurrency toCurrency) {
1.44 + super(fromValue, fromCurrency, toValue, toCurrency);
1.45 + }
1.46 +
1.47 + public boolean addFixedCurencyRate(ConvertorCurrency fromCurrency, BigDecimal fromValue, ConvertorCurrency toCurrency, BigDecimal toValue) {
1.48 + return true; // great method - do nothing and is always satisfied ;-)
1.49 + }
1.50 +
1.51 + }
1.52 +}