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