# HG changeset patch # User Jaroslav Tulach # Date 1222625224 -7200 # Node ID 1ca35892ef26c5a91b3c742c5050ccb052fc8543 # Parent 89ce9f671e76d92717483e333330425c3e392e9e# Parent b6c21003ddc98bf378109e4ead6be6ca01e433ba Merge: More preciselly specified tasks diff -r 89ce9f671e76 -r 1ca35892ef26 .hgignore --- a/.hgignore Sun Sep 28 18:44:34 2008 +0200 +++ b/.hgignore Sun Sep 28 20:07:04 2008 +0200 @@ -1,4 +1,5 @@ .*/private/.* .*/dist/.* .*/build/.* +.*orig diff -r 89ce9f671e76 -r 1ca35892ef26 currency/test/org/apidesign/apifest08/test/Task1Test.java --- a/currency/test/org/apidesign/apifest08/test/Task1Test.java Sun Sep 28 18:44:34 2008 +0200 +++ b/currency/test/org/apidesign/apifest08/test/Task1Test.java Sun Sep 28 20:07:04 2008 +0200 @@ -22,8 +22,19 @@ protected void tearDown() throws Exception { } + // + // Imagine that there are three parts of the whole system: + // 1. there is someone who knows the current exchange rate + // 2. there is someone who wants to do the conversion + // 3. there is the API between 1. and 2. which allows them to communicate + // Please design such API + // + /** Create convertor that understands two currencies, CZK and - * USD. Make 1 USD == 17 CZK. + * USD. Make 1 USD == 17 CZK. This is a method provided for #1 group - + * e.g. those that know the exchange rate. They somehow need to create + * the objects from the API and tell them the exchange rate. The API itself + * knows nothing about any rates, before the createCZKtoUSD method is called. * * Creation of the convertor shall not require subclassing of any class * or interface on the client side. @@ -35,7 +46,11 @@ } /** Create convertor that understands two currencies, CZK and - * SKK. Make 100 SKK == 80 CZK. + * SKK. Make 100 SKK == 80 CZK. Again this is method for the #1 group - + * it knows the exchange rate, and needs to use the API to create objects + * with the exchange rate. Anyone shall be ready to call this method without + * any other method being called previously. The API itself shall know + * nothing about any rates, before this method is called. * * Creation of the convertor shall not require subclassing of any class * or interface on the client side. @@ -45,6 +60,13 @@ public static Convertor createSKKtoCZK() { return null; } + + // + // now the methods for group #2 follow: + // this group knows nothing about exchange rates, but knows how to use + // the API to do conversions. It somehow (by calling one of the factory + // methods) gets objects from the API and uses them to do the conversions. + // /** Use the convertor from createCZKtoUSD method and do few conversions * with it. @@ -72,5 +94,20 @@ // convert 500SKK to CZK // assertEquals("Result is 400 CZK"); } + + /** Verify that the CZK to USD convertor knows nothing about SKK. + */ + public void testCannotConvertToSKKwithCZKUSDConvertor() throws Exception { + Convertor c = createCZKtoUSD(); + // convert $5 to SKK, the API shall say this is not possible + // convert 500 SKK to CZK, the API shall say this is not possible + } + + /** Verify that the CZK to SKK convertor knows nothing about USD. + */ + public void testCannotConvertToSKKwithCZKUSDConvertor() throws Exception { + Convertor c = createSKKtoCZK(); + // convert $5 to SKK, the API shall say this is not possible + // convert 500 CZK to USD, the API shall say this is not possible + } } -