1.1 --- a/task3/solution11/test/org/apidesign/apifest08/test/Task1Test.java Tue Oct 07 11:05:34 2008 +0200
1.2 +++ b/task3/solution11/test/org/apidesign/apifest08/test/Task1Test.java Fri Oct 10 21:58:12 2008 +0200
1.3 @@ -42,10 +42,10 @@
1.4 *
1.5 * @return prepared convertor ready for converting USD to CZK and CZK to USD
1.6 */
1.7 - public static Convertor<Integer, String> createCZKtoUSD() {
1.8 - return Convertor.getConvertorIntegerString(
1.9 - CurrencyValue.getCurrencyValue(1, "USD"),
1.10 - CurrencyValue.getCurrencyValue(17, "CZK")
1.11 + public static Convertor<Double, String> createCZKtoUSD() {
1.12 + return Convertor.getConvertorDoubleString(
1.13 + CurrencyValue.getCurrencyValue(1d, "USD"),
1.14 + CurrencyValue.getCurrencyValue(17d, "CZK")
1.15 );
1.16 }
1.17
1.18 @@ -61,10 +61,10 @@
1.19 *
1.20 * @return prepared convertor ready for converting SKK to CZK and CZK to SKK
1.21 */
1.22 - public static Convertor<Integer, String> createSKKtoCZK() {
1.23 - return Convertor.getConvertorIntegerString(
1.24 - CurrencyValue.getCurrencyValue(100, "SKK"),
1.25 - CurrencyValue.getCurrencyValue(80, "CZK")
1.26 + public static Convertor<Double, String> createSKKtoCZK() {
1.27 + return Convertor.getConvertorDoubleString(
1.28 + CurrencyValue.getCurrencyValue(100d, "SKK"),
1.29 + CurrencyValue.getCurrencyValue(80d, "CZK")
1.30 );
1.31 }
1.32
1.33 @@ -79,62 +79,60 @@
1.34 * with it.
1.35 */
1.36 public void testCurrencyCZKUSD() throws Exception {
1.37 - Convertor<Integer, String> c = createCZKtoUSD();
1.38 + Convertor<Double, String> c = createCZKtoUSD();
1.39
1.40 - CurrencyValue<Integer, String> result;
1.41 + CurrencyValue<Double, String> result;
1.42
1.43 // convert $5 to CZK using c:
1.44 // assertEquals("Result is 85 CZK");
1.45 - result = c.convert("CZK", CurrencyValue.getCurrencyValue(5, "USD"));
1.46 - assertEquals(CurrencyValue.getCurrencyValue(85, "CZK"), result);
1.47 + result = c.convert("CZK", CurrencyValue.getCurrencyValue(5d, "USD"));
1.48 + assertEquals(CurrencyValue.getCurrencyValue(85d, "CZK"), result);
1.49
1.50 // convert $8 to CZK
1.51 // assertEquals("Result is 136 CZK");
1.52 - result = c.convert("CZK", CurrencyValue.getCurrencyValue(8, "USD"));
1.53 - assertEquals(CurrencyValue.getCurrencyValue(136, "CZK"), result);
1.54 + result = c.convert("CZK", CurrencyValue.getCurrencyValue(8d, "USD"));
1.55 + assertEquals(CurrencyValue.getCurrencyValue(136d, "CZK"), result);
1.56
1.57 // convert 1003CZK to USD
1.58 // assertEquals("Result is 59 USD");
1.59 - result = c.convert("USD", CurrencyValue.getCurrencyValue(1003, "CZK"));
1.60 - assertEquals(CurrencyValue.getCurrencyValue(59, "USD"), result);
1.61 + result = c.convert("USD", CurrencyValue.getCurrencyValue(1003d, "CZK"));
1.62 + assertEquals(CurrencyValue.getCurrencyValue(59d, "USD"), result);
1.63 }
1.64
1.65 /** Use the convertor from <code>createSKKtoCZK</code> method and do few conversions
1.66 * with it.
1.67 */
1.68 public void testCurrencySKKCZK() throws Exception {
1.69 - Convertor<Integer, String> c = createSKKtoCZK();
1.70 + Convertor<Double, String> c = createSKKtoCZK();
1.71
1.72 - CurrencyValue<Integer, String> result;
1.73 + CurrencyValue<Double, String> result;
1.74
1.75 // convert 16CZK using c:
1.76 // assertEquals("Result is 20 SKK");
1.77 - result = c.convert("SKK", CurrencyValue.getCurrencyValue(16, "CZK"));
1.78 - assertEquals(CurrencyValue.getCurrencyValue(20, "SKK"), result);
1.79 + result = c.convert("SKK", CurrencyValue.getCurrencyValue(16d, "CZK"));
1.80 + assertEquals(CurrencyValue.getCurrencyValue(20d, "SKK"), result);
1.81
1.82 // convert 500SKK to CZK
1.83 // assertEquals("Result is 400 CZK");
1.84 - result = c.convert("CZK", CurrencyValue.getCurrencyValue(500, "SKK"));
1.85 - assertEquals(CurrencyValue.getCurrencyValue(400, "CZK"), result);
1.86 + result = c.convert("CZK", CurrencyValue.getCurrencyValue(500d, "SKK"));
1.87 + assertEquals(CurrencyValue.getCurrencyValue(400d, "CZK"), result);
1.88 }
1.89
1.90 /** Verify that the CZK to USD convertor knows nothing about SKK.
1.91 */
1.92 public void testCannotConvertToSKKwithCZKUSDConvertor() throws Exception {
1.93 - Convertor<Integer, String> c = createCZKtoUSD();
1.94 + Convertor<Double, String> c = createCZKtoUSD();
1.95 try {
1.96 // convert $5 to SKK, the API shall say this is not possible
1.97 - c.convert("SKK", CurrencyValue.getCurrencyValue(16, "CZK"));
1.98 - assertTrue("Should not convert", false);
1.99 + c.convert("SKK", CurrencyValue.getCurrencyValue(16d, "CZK"));
1.100 + fail("Should not convert");
1.101 } catch (Exception e) {
1.102 - assertTrue(true);
1.103 }
1.104 try {
1.105 // convert 500 SKK to CZK, the API shall say this is not possible
1.106 - c.convert("CZK", CurrencyValue.getCurrencyValue(500, "SKK"));
1.107 - assertTrue("Should not convert", false);
1.108 + c.convert("CZK", CurrencyValue.getCurrencyValue(500d, "SKK"));
1.109 + fail("Should not convert");
1.110 } catch (Exception e) {
1.111 - assertTrue(true);
1.112 }
1.113
1.114 }
1.115 @@ -142,20 +140,18 @@
1.116 /** Verify that the CZK to SKK convertor knows nothing about USD.
1.117 */
1.118 public void testCannotConvertToUSDwithSKKCZKConvertor() throws Exception {
1.119 - Convertor<Integer, String> c = createSKKtoCZK();
1.120 + Convertor<Double, String> c = createSKKtoCZK();
1.121 try {
1.122 // convert $5 to SKK, the API shall say this is not possible
1.123 - c.convert("SKK", CurrencyValue.getCurrencyValue(5, "USD"));
1.124 - assertTrue("Should not convert", false);
1.125 + c.convert("SKK", CurrencyValue.getCurrencyValue(5d, "USD"));
1.126 + fail("Should not convert");
1.127 } catch (Exception e) {
1.128 - assertTrue(true);
1.129 }
1.130 try {
1.131 // convert 500 CZK to USD, the API shall say this is not possible
1.132 - c.convert("USD", CurrencyValue.getCurrencyValue(500, "CZK"));
1.133 - assertTrue("Should not convert", false);
1.134 + c.convert("USD", CurrencyValue.getCurrencyValue(500d, "CZK"));
1.135 + fail("Should not convert");
1.136 } catch (Exception e) {
1.137 - assertTrue(true);
1.138 }
1.139 }
1.140 }