1.1 --- a/currency/test/org/apidesign/apifest08/test/Task1Test.java Sun Sep 28 18:41:43 2008 +0200
1.2 +++ b/currency/test/org/apidesign/apifest08/test/Task1Test.java Sun Sep 28 20:05:56 2008 +0200
1.3 @@ -22,8 +22,19 @@
1.4 protected void tearDown() throws Exception {
1.5 }
1.6
1.7 + //
1.8 + // Imagine that there are three parts of the whole system:
1.9 + // 1. there is someone who knows the current exchange rate
1.10 + // 2. there is someone who wants to do the conversion
1.11 + // 3. there is the API between 1. and 2. which allows them to communicate
1.12 + // Please design such API
1.13 + //
1.14 +
1.15 /** Create convertor that understands two currencies, CZK and
1.16 - * USD. Make 1 USD == 17 CZK.
1.17 + * USD. Make 1 USD == 17 CZK. This is a method provided for #1 group -
1.18 + * e.g. those that know the exchange rate. They somehow need to create
1.19 + * the objects from the API and tell them the exchange rate. The API itself
1.20 + * knows nothing about any rates, before the createCZKtoUSD method is called.
1.21 *
1.22 * Creation of the convertor shall not require subclassing of any class
1.23 * or interface on the client side.
1.24 @@ -35,7 +46,11 @@
1.25 }
1.26
1.27 /** Create convertor that understands two currencies, CZK and
1.28 - * SKK. Make 100 SKK == 80 CZK.
1.29 + * SKK. Make 100 SKK == 80 CZK. Again this is method for the #1 group -
1.30 + * it knows the exchange rate, and needs to use the API to create objects
1.31 + * with the exchange rate. Anyone shall be ready to call this method without
1.32 + * any other method being called previously. The API itself shall know
1.33 + * nothing about any rates, before this method is called.
1.34 *
1.35 * Creation of the convertor shall not require subclassing of any class
1.36 * or interface on the client side.
1.37 @@ -45,6 +60,13 @@
1.38 public static Convertor createSKKtoCZK() {
1.39 return null;
1.40 }
1.41 +
1.42 + //
1.43 + // now the methods for group #2 follow:
1.44 + // this group knows nothing about exchange rates, but knows how to use
1.45 + // the API to do conversions. It somehow (by calling one of the factory
1.46 + // methods) gets objects from the API and uses them to do the conversions.
1.47 + //
1.48
1.49 /** Use the convertor from <code>createCZKtoUSD</code> method and do few conversions
1.50 * with it.
1.51 @@ -72,5 +94,20 @@
1.52 // convert 500SKK to CZK
1.53 // assertEquals("Result is 400 CZK");
1.54 }
1.55 +
1.56 + /** Verify that the CZK to USD convertor knows nothing about SKK.
1.57 + */
1.58 + public void testCannotConvertToSKKwithCZKUSDConvertor() throws Exception {
1.59 + Convertor c = createCZKtoUSD();
1.60 + // convert $5 to SKK, the API shall say this is not possible
1.61 + // convert 500 SKK to CZK, the API shall say this is not possible
1.62 + }
1.63 +
1.64 + /** Verify that the CZK to SKK convertor knows nothing about USD.
1.65 + */
1.66 + public void testCannotConvertToSKKwithCZKUSDConvertor() throws Exception {
1.67 + Convertor c = createSKKtoCZK();
1.68 + // convert $5 to SKK, the API shall say this is not possible
1.69 + // convert 500 CZK to USD, the API shall say this is not possible
1.70 + }
1.71 }
1.72 -