diff -r f6073056b9fe -r a7e6f84fb078 task2/solution13/test/org/apidesign/apifest08/test/Task1Test.java --- a/task2/solution13/test/org/apidesign/apifest08/test/Task1Test.java Wed Oct 01 10:43:05 2008 +0200 +++ b/task2/solution13/test/org/apidesign/apifest08/test/Task1Test.java Tue Oct 07 01:18:23 2008 +0200 @@ -6,6 +6,7 @@ import org.apidesign.apifest08.currency.Convertor; import org.apidesign.apifest08.currency.ConvertorCurrency; import org.apidesign.apifest08.currency.ExchangeRateProvider; +import org.apidesign.apifest08.currency.ConversionNotSupportedException; /** Finish the Convertor API, and then write bodies of methods inside * of this class to match the given tasks. To fullfil your task, use the @@ -34,7 +35,7 @@ * * @return prepared convertor ready for converting USD to CZK and CZK to USD */ - public Convertor createCZKtoUSD() { + public static Convertor createCZKtoUSD() { ConvertorCurrency fromCurrency = ConvertorCurrency.getInstance("CZK"); ConvertorCurrency toCurrency = ConvertorCurrency.getInstance("USD"); ExchangeRateProvider exchangeRateProvider = new ExchangeRateProvider(new BigDecimal(17), fromCurrency, new BigDecimal(1), toCurrency); @@ -50,7 +51,7 @@ * * @return prepared convertor ready for converting SKK to CZK and CZK to SKK */ - public Convertor createSKKtoCZK() { + public static Convertor createSKKtoCZK() { ConvertorCurrency fromCurrency = ConvertorCurrency.getInstance("SKK"); ConvertorCurrency toCurrency = ConvertorCurrency.getInstance("CZK"); ExchangeRateProvider exchangeRateProvider = new ExchangeRateProvider(new BigDecimal(100), fromCurrency, new BigDecimal(80), toCurrency); @@ -59,7 +60,7 @@ } - public Convertor createCZKtoYEN() { + public static Convertor createCZKtoYEN() { ConvertorCurrency fromCurrency = ConvertorCurrency.getInstance("CZK"); ConvertorCurrency toCurrency = ConvertorCurrency.getInstance("JPY"); ExchangeRateProvider exchangeRateProvider = new ExchangeRateProvider(new BigDecimal(1), fromCurrency, new BigDecimal(1), toCurrency); @@ -200,8 +201,21 @@ public void testCannotConvertToSKKwithCZKUSDConvertor() throws Exception { Convertor c = createCZKtoUSD(); // convert $5 to SKK, the API shall say this is not possible + try { + c.convert(ConvertorCurrency.getInstance("USD"), ConvertorCurrency.getInstance("SKK"), new BigDecimal(5)); + fail(); + } catch (ConversionNotSupportedException e) { + //expected error; + assertEquals("Exception From USD", "USD",e.getFromCurrecyCode()); + assertEquals("Exception To SKK", "SKK",e.getToCurrecyCode()); + } // convert 500 SKK to CZK, the API shall say this is not possible - // ... no api for required call, should be here? + try { + c.convert(ConvertorCurrency.getInstance("SKK"), ConvertorCurrency.getInstance("CZK"), new BigDecimal(500)); + fail(); + } catch (ConversionNotSupportedException e) { + assertEquals("Exception From USD", "SKK",e.getFromCurrecyCode()); + assertEquals("Exception To SKK", "CZK",e.getToCurrecyCode()); } }