task2/solution13/test/org/apidesign/apifest08/test/Task1Test.java
changeset 41 a7e6f84fb078
parent 29 f6073056b9fe
     1.1 --- a/task2/solution13/test/org/apidesign/apifest08/test/Task1Test.java	Wed Oct 01 10:43:05 2008 +0200
     1.2 +++ b/task2/solution13/test/org/apidesign/apifest08/test/Task1Test.java	Tue Oct 07 01:18:23 2008 +0200
     1.3 @@ -6,6 +6,7 @@
     1.4  import org.apidesign.apifest08.currency.Convertor;
     1.5  import org.apidesign.apifest08.currency.ConvertorCurrency;
     1.6  import org.apidesign.apifest08.currency.ExchangeRateProvider;
     1.7 +import org.apidesign.apifest08.currency.ConversionNotSupportedException;
     1.8  
     1.9  /** Finish the Convertor API, and then write bodies of methods inside
    1.10   * of this class to match the given tasks. To fullfil your task, use the
    1.11 @@ -34,7 +35,7 @@
    1.12       *
    1.13       * @return prepared convertor ready for converting USD to CZK and CZK to USD
    1.14       */
    1.15 -    public Convertor createCZKtoUSD() {
    1.16 +    public static Convertor createCZKtoUSD() {
    1.17          ConvertorCurrency fromCurrency = ConvertorCurrency.getInstance("CZK");
    1.18          ConvertorCurrency toCurrency = ConvertorCurrency.getInstance("USD");
    1.19          ExchangeRateProvider exchangeRateProvider = new ExchangeRateProvider(new BigDecimal(17), fromCurrency, new BigDecimal(1), toCurrency);
    1.20 @@ -50,7 +51,7 @@
    1.21       * 
    1.22       * @return prepared convertor ready for converting SKK to CZK and CZK to SKK
    1.23       */
    1.24 -    public Convertor createSKKtoCZK() {
    1.25 +    public static Convertor createSKKtoCZK() {
    1.26          ConvertorCurrency fromCurrency = ConvertorCurrency.getInstance("SKK");
    1.27          ConvertorCurrency toCurrency = ConvertorCurrency.getInstance("CZK");
    1.28          ExchangeRateProvider exchangeRateProvider = new ExchangeRateProvider(new BigDecimal(100), fromCurrency, new BigDecimal(80), toCurrency);
    1.29 @@ -59,7 +60,7 @@
    1.30      }
    1.31      
    1.32      
    1.33 -    public Convertor createCZKtoYEN() {
    1.34 +    public static Convertor createCZKtoYEN() {
    1.35          ConvertorCurrency fromCurrency = ConvertorCurrency.getInstance("CZK");
    1.36          ConvertorCurrency toCurrency = ConvertorCurrency.getInstance("JPY");
    1.37          ExchangeRateProvider exchangeRateProvider = new ExchangeRateProvider(new BigDecimal(1), fromCurrency, new BigDecimal(1), toCurrency);
    1.38 @@ -200,8 +201,21 @@
    1.39      public void testCannotConvertToSKKwithCZKUSDConvertor() throws Exception {
    1.40              Convertor c = createCZKtoUSD();
    1.41              // convert $5 to SKK, the API shall say this is not possible
    1.42 +            try {
    1.43 +                c.convert(ConvertorCurrency.getInstance("USD"), ConvertorCurrency.getInstance("SKK"), new BigDecimal(5));
    1.44 +                fail();
    1.45 +            } catch (ConversionNotSupportedException e) {
    1.46 +                //expected error;
    1.47 +                assertEquals("Exception From USD", "USD",e.getFromCurrecyCode());
    1.48 +                assertEquals("Exception To SKK", "SKK",e.getToCurrecyCode());
    1.49 +            }
    1.50              // convert 500 SKK to CZK, the API shall say this is not possible
    1.51 -            // ... no api for required call, should be here?
    1.52 +            try {
    1.53 +                c.convert(ConvertorCurrency.getInstance("SKK"), ConvertorCurrency.getInstance("CZK"), new BigDecimal(500));
    1.54 +                fail();
    1.55 +            } catch (ConversionNotSupportedException e) {
    1.56 +                assertEquals("Exception From USD", "SKK",e.getFromCurrecyCode());
    1.57 +                assertEquals("Exception To SKK", "CZK",e.getToCurrecyCode());            }
    1.58      }
    1.59      
    1.60