1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/taskx/psmid/against-solution04/test/apifest/CurrencyTest.java Sat Oct 25 20:53:00 2008 +0200
1.3 @@ -0,0 +1,42 @@
1.4 +package apifest;
1.5 +
1.6 +import java.math.BigDecimal;
1.7 +import java.util.Currency;
1.8 +import junit.framework.TestCase;
1.9 +import org.apidesign.apifest08.currency.Convertor;
1.10 +import org.apidesign.apifest08.currency.ConvertorFactory;
1.11 +import org.apidesign.apifest08.currency.InvalidConversionException;
1.12 +
1.13 +
1.14 +/** Write a test that works with version from task A and fails with version B.
1.15 + */
1.16 +public class CurrencyTest extends TestCase {
1.17 + public CurrencyTest(String n) {
1.18 + super(n);
1.19 + }
1.20 +
1.21 + public void testCompatibility() throws Exception {
1.22 + incompatibility1();
1.23 + // incompatibility2(); //another test proving incompatibility in versions
1.24 + // incompatibility3(); //another test proving incompatibility in versions
1.25 + }
1.26 +
1.27 + private void incompatibility1() throws Exception {
1.28 + Convertor c = ConvertorFactory.getConvertor("CZK", BigDecimal.valueOf(17.0), "USD", BigDecimal.valueOf(1));
1.29 + assertTrue("", c.toString().startsWith("org.apidesign.apifest08.currency.ConvertorImpl"));
1.30 + }
1.31 +
1.32 + private void incompatibility2() throws Exception {
1.33 + Convertor c = ConvertorFactory.getConvertor("CZK", BigDecimal.valueOf(17.0), "USD", BigDecimal.valueOf(1));
1.34 + assertEquals("Testing hashcode", 961187025, c.hashCode());
1.35 + }
1.36 +
1.37 + private void incompatibility3() throws Exception {
1.38 + Convertor co = new Convertor() {
1.39 + public BigDecimal convert(Currency from, Currency to, BigDecimal amount) throws InvalidConversionException {
1.40 + return null;
1.41 + }
1.42 + };
1.43 + }
1.44 +
1.45 +}