taskx/psmid/against-solution04/test/apifest/CurrencyTest.java
author Jaroslav Tulach <jtulach@netbeans.org>
Sat, 25 Oct 2008 20:53:00 +0200
changeset 84 2ae6e4aa7aef
permissions -rw-r--r--
Solutions by Petr Smid
jtulach@84
     1
package apifest;
jtulach@84
     2
jtulach@84
     3
import java.math.BigDecimal;
jtulach@84
     4
import java.util.Currency;
jtulach@84
     5
import junit.framework.TestCase;
jtulach@84
     6
import org.apidesign.apifest08.currency.Convertor;
jtulach@84
     7
import org.apidesign.apifest08.currency.ConvertorFactory;
jtulach@84
     8
import org.apidesign.apifest08.currency.InvalidConversionException;
jtulach@84
     9
jtulach@84
    10
jtulach@84
    11
/** Write a test that works with version from task A and fails with version B.
jtulach@84
    12
 */
jtulach@84
    13
public class CurrencyTest extends TestCase {
jtulach@84
    14
    public CurrencyTest(String n) {
jtulach@84
    15
        super(n);
jtulach@84
    16
    }
jtulach@84
    17
    
jtulach@84
    18
    public void testCompatibility() throws Exception {
jtulach@84
    19
        incompatibility1();
jtulach@84
    20
      //  incompatibility2(); //another test proving incompatibility in versions
jtulach@84
    21
      //  incompatibility3(); //another test proving incompatibility in versions
jtulach@84
    22
    }
jtulach@84
    23
jtulach@84
    24
    private void incompatibility1() throws Exception {
jtulach@84
    25
          Convertor c = ConvertorFactory.getConvertor("CZK", BigDecimal.valueOf(17.0), "USD", BigDecimal.valueOf(1));
jtulach@84
    26
          assertTrue("", c.toString().startsWith("org.apidesign.apifest08.currency.ConvertorImpl"));
jtulach@84
    27
    }
jtulach@84
    28
jtulach@84
    29
    private void incompatibility2() throws Exception {
jtulach@84
    30
          Convertor c = ConvertorFactory.getConvertor("CZK", BigDecimal.valueOf(17.0), "USD", BigDecimal.valueOf(1));
jtulach@84
    31
          assertEquals("Testing hashcode", 961187025, c.hashCode());
jtulach@84
    32
    }
jtulach@84
    33
jtulach@84
    34
    private void incompatibility3() throws Exception {
jtulach@84
    35
        Convertor co = new Convertor() {
jtulach@84
    36
            public BigDecimal convert(Currency from, Currency to, BigDecimal amount) throws InvalidConversionException {
jtulach@84
    37
                return null;
jtulach@84
    38
            }
jtulach@84
    39
        };
jtulach@84
    40
    }
jtulach@84
    41
jtulach@84
    42
}