jtulach@83
|
1 |
package apifest;
|
jtulach@83
|
2 |
|
jtulach@83
|
3 |
import java.math.BigDecimal;
|
jtulach@83
|
4 |
import junit.framework.TestCase;
|
jtulach@83
|
5 |
import org.apidesign.apifest08.currency.Convertor;
|
jtulach@83
|
6 |
import org.apidesign.apifest08.currency.ConvertorCurrency;
|
jtulach@83
|
7 |
import org.apidesign.apifest08.currency.ExchangeRateProvider;
|
jtulach@83
|
8 |
|
jtulach@83
|
9 |
|
jtulach@83
|
10 |
/** Write a test that works with version from task A and fails with version B.
|
jtulach@83
|
11 |
*/
|
jtulach@83
|
12 |
public class CurrencyTest extends TestCase {
|
jtulach@83
|
13 |
public CurrencyTest(String n) {
|
jtulach@83
|
14 |
super(n);
|
jtulach@83
|
15 |
}
|
jtulach@83
|
16 |
|
jtulach@83
|
17 |
/** Fails because runtime incompatibility. */
|
jtulach@83
|
18 |
public void testCompatibility() throws Exception {
|
jtulach@83
|
19 |
ConvertorCurrency cur1 = ConvertorCurrency.getInstance("CZK");
|
jtulach@83
|
20 |
ConvertorCurrency cur2 = ConvertorCurrency.getInstance("CZK");
|
jtulach@83
|
21 |
|
jtulach@83
|
22 |
assertEquals(false, cur1.equals(cur2));
|
jtulach@83
|
23 |
}
|
jtulach@83
|
24 |
|
jtulach@83
|
25 |
/** Fails because source incompatibility. */
|
jtulach@83
|
26 |
public void testCompatibility2() throws Exception {
|
jtulach@83
|
27 |
MyOwnExchangeRateProvider provider = new MyOwnExchangeRateProvider(
|
jtulach@83
|
28 |
new BigDecimal("1"), ConvertorCurrency.getInstance("USD"),
|
jtulach@83
|
29 |
new BigDecimal("16"), ConvertorCurrency.getInstance("CZK"));
|
jtulach@83
|
30 |
Convertor c = Convertor.createConvertor(provider);
|
jtulach@83
|
31 |
|
jtulach@83
|
32 |
boolean result = provider.addFixedCurencyRate(
|
jtulach@83
|
33 |
ConvertorCurrency.getInstance("CZK"), new BigDecimal("80"),
|
jtulach@83
|
34 |
ConvertorCurrency.getInstance("SKK"), new BigDecimal("100"));
|
jtulach@83
|
35 |
assertEquals(true, result);
|
jtulach@83
|
36 |
}
|
jtulach@83
|
37 |
|
jtulach@83
|
38 |
class MyOwnExchangeRateProvider extends ExchangeRateProvider {
|
jtulach@83
|
39 |
|
jtulach@83
|
40 |
public MyOwnExchangeRateProvider(BigDecimal fromValue, ConvertorCurrency fromCurrency, BigDecimal toValue, ConvertorCurrency toCurrency) {
|
jtulach@83
|
41 |
super(fromValue, fromCurrency, toValue, toCurrency);
|
jtulach@83
|
42 |
}
|
jtulach@83
|
43 |
|
jtulach@83
|
44 |
public boolean addFixedCurencyRate(ConvertorCurrency fromCurrency, BigDecimal fromValue, ConvertorCurrency toCurrency, BigDecimal toValue) {
|
jtulach@83
|
45 |
return true; // great method - do nothing and is always satisfied ;-)
|
jtulach@83
|
46 |
}
|
jtulach@83
|
47 |
|
jtulach@83
|
48 |
}
|
jtulach@83
|
49 |
}
|