# HG changeset patch # User Jaroslav Tulach # Date 1224960780 -7200 # Node ID 2ae6e4aa7aefbe7eec33dcbfddbdea846ccc13f6 # Parent 621462e58e22ce63f5b6bce755733e0c9d530738 Solutions by Petr Smid diff -r 621462e58e22 -r 2ae6e4aa7aef .hgignore --- a/.hgignore Sat Oct 25 20:30:54 2008 +0200 +++ b/.hgignore Sat Oct 25 20:53:00 2008 +0200 @@ -2,4 +2,5 @@ .*/dist/.* .*/build/.* .*orig +.*~ diff -r 621462e58e22 -r 2ae6e4aa7aef taskx/psmid/against-solution04/build.xml --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/taskx/psmid/against-solution04/build.xml Sat Oct 25 20:53:00 2008 +0200 @@ -0,0 +1,5 @@ + + + + + diff -r 621462e58e22 -r 2ae6e4aa7aef taskx/psmid/against-solution04/nbproject/project.xml --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/taskx/psmid/against-solution04/nbproject/project.xml Sat Oct 25 20:53:00 2008 +0200 @@ -0,0 +1,82 @@ + + + org.netbeans.modules.ant.freeform + + + + testing template + + build.xml + ../../../ + project.properties + ${apifest}/taskx/common.properties + + + + + java + test + + + + + + compile + + + + clean + + + + test + + + + test + + + + clean + compile + + + + folder + build/tests + + compile + + + + + + test + + + ${ant.script} + + + project.properties + + + + + + + + + + + + + + + test + ${apiA}:${junit.jar} + build/tests + 1.5 + + + + diff -r 621462e58e22 -r 2ae6e4aa7aef taskx/psmid/against-solution04/project.properties --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/taskx/psmid/against-solution04/project.properties Sat Oct 25 20:53:00 2008 +0200 @@ -0,0 +1,16 @@ + +# name of a project to test +#apitotest=todo:specify_this_property_in:project.properties +#for example use: +apitotest=solution04 + +# the test shall expose a problem between two versions +# of one API. select the first version - taskA and a second +# version of the of the API taskB +taskA=${apifest}/task1 +taskB=${apifest}/task2 + +# usual locations of API classes for each version +apiA=${taskA}/${apitotest}/build/classes/ +apiB=${taskB}/${apitotest}/build/classes/ + diff -r 621462e58e22 -r 2ae6e4aa7aef taskx/psmid/against-solution04/test/apifest/CurrencyTest.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/taskx/psmid/against-solution04/test/apifest/CurrencyTest.java Sat Oct 25 20:53:00 2008 +0200 @@ -0,0 +1,42 @@ +package apifest; + +import java.math.BigDecimal; +import java.util.Currency; +import junit.framework.TestCase; +import org.apidesign.apifest08.currency.Convertor; +import org.apidesign.apifest08.currency.ConvertorFactory; +import org.apidesign.apifest08.currency.InvalidConversionException; + + +/** Write a test that works with version from task A and fails with version B. + */ +public class CurrencyTest extends TestCase { + public CurrencyTest(String n) { + super(n); + } + + public void testCompatibility() throws Exception { + incompatibility1(); + // incompatibility2(); //another test proving incompatibility in versions + // incompatibility3(); //another test proving incompatibility in versions + } + + private void incompatibility1() throws Exception { + Convertor c = ConvertorFactory.getConvertor("CZK", BigDecimal.valueOf(17.0), "USD", BigDecimal.valueOf(1)); + assertTrue("", c.toString().startsWith("org.apidesign.apifest08.currency.ConvertorImpl")); + } + + private void incompatibility2() throws Exception { + Convertor c = ConvertorFactory.getConvertor("CZK", BigDecimal.valueOf(17.0), "USD", BigDecimal.valueOf(1)); + assertEquals("Testing hashcode", 961187025, c.hashCode()); + } + + private void incompatibility3() throws Exception { + Convertor co = new Convertor() { + public BigDecimal convert(Currency from, Currency to, BigDecimal amount) throws InvalidConversionException { + return null; + } + }; + } + +} diff -r 621462e58e22 -r 2ae6e4aa7aef taskx/psmid/against-solution06/build.xml --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/taskx/psmid/against-solution06/build.xml Sat Oct 25 20:53:00 2008 +0200 @@ -0,0 +1,5 @@ + + + + + diff -r 621462e58e22 -r 2ae6e4aa7aef taskx/psmid/against-solution06/nbproject/project.xml --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/taskx/psmid/against-solution06/nbproject/project.xml Sat Oct 25 20:53:00 2008 +0200 @@ -0,0 +1,82 @@ + + + org.netbeans.modules.ant.freeform + + + + testing template + + build.xml + ../../../ + project.properties + ${apifest}/taskx/common.properties + + + + + java + test + + + + + + compile + + + + clean + + + + test + + + + test + + + + clean + compile + + + + folder + build/tests + + compile + + + + + + test + + + ${ant.script} + + + project.properties + + + + + + + + + + + + + + + test + ${apiA}:${junit.jar} + build/tests + 1.5 + + + + diff -r 621462e58e22 -r 2ae6e4aa7aef taskx/psmid/against-solution06/project.properties --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/taskx/psmid/against-solution06/project.properties Sat Oct 25 20:53:00 2008 +0200 @@ -0,0 +1,16 @@ + +# name of a project to test +#apitotest=todo:specify_this_property_in:project.properties +#for example use: +apitotest=solution06 + +# the test shall expose a problem between two versions +# of one API. select the first version - taskA and a second +# version of the of the API taskB +taskA=${apifest}/task3 +taskB=${apifest}/task4 + +# usual locations of API classes for each version +apiA=${taskA}/${apitotest}/build/classes/ +apiB=${taskB}/${apitotest}/build/classes/ + diff -r 621462e58e22 -r 2ae6e4aa7aef taskx/psmid/against-solution06/test/apifest/CurrencyTest.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/taskx/psmid/against-solution06/test/apifest/CurrencyTest.java Sat Oct 25 20:53:00 2008 +0200 @@ -0,0 +1,34 @@ +package apifest; + +import java.math.BigDecimal; +import java.util.Currency; +import junit.framework.TestCase; +import org.apidesign.apifest08.currency.Amount; +import org.apidesign.apifest08.currency.Convertor; +import org.apidesign.apifest08.currency.UnsupportedConversionException; +//import static org.apidesign.apifest08.test.Currencies.CZK; +//import static org.apidesign.apifest08.test.Currencies.SKK; +//import static org.apidesign.apifest08.test.Currencies.USD; + +/** Write a test that works with version from task A and fails with version B. + */ +public class CurrencyTest extends TestCase { + public CurrencyTest(String n) { + super(n); + } + + public void testCompatibility() throws Exception { + Currency CZK = Currency.getInstance("CZK"); + Currency USD = Currency.getInstance("USD"); + Currency SKK = Currency.getInstance("SKK"); + + + Convertor c = new Convertor(new BigDecimal(17), USD, CZK); + try { + Amount a = c.convert(new BigDecimal("10"), USD, SKK); + //fail(); + } catch (UnsupportedConversionException e) { + assertEquals("Conversion from the currency USD to the currency SKK or vice versa in not supported.", e.getMessage()); + } + } +} diff -r 621462e58e22 -r 2ae6e4aa7aef taskx/psmid/against-solution11/build.xml --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/taskx/psmid/against-solution11/build.xml Sat Oct 25 20:53:00 2008 +0200 @@ -0,0 +1,5 @@ + + + + + diff -r 621462e58e22 -r 2ae6e4aa7aef taskx/psmid/against-solution11/nbproject/project.xml --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/taskx/psmid/against-solution11/nbproject/project.xml Sat Oct 25 20:53:00 2008 +0200 @@ -0,0 +1,82 @@ + + + org.netbeans.modules.ant.freeform + + + + testing template + + build.xml + ../../../ + project.properties + ${apifest}/taskx/common.properties + + + + + java + test + + + + + + compile + + + + clean + + + + test + + + + test + + + + clean + compile + + + + folder + build/tests + + compile + + + + + + test + + + ${ant.script} + + + project.properties + + + + + + + + + + + + + + + test + ${apiA}:${junit.jar} + build/tests + 1.5 + + + + diff -r 621462e58e22 -r 2ae6e4aa7aef taskx/psmid/against-solution11/project.properties --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/taskx/psmid/against-solution11/project.properties Sat Oct 25 20:53:00 2008 +0200 @@ -0,0 +1,16 @@ + +# name of a project to test +#apitotest=todo:specify_this_property_in:project.properties +#for example use: +apitotest=solution11 + +# the test shall expose a problem between two versions +# of one API. select the first version - taskA and a second +# version of the of the API taskB +taskA=${apifest}/task1 +taskB=${apifest}/task2 + +# usual locations of API classes for each version +apiA=${taskA}/${apitotest}/build/classes/ +apiB=${taskB}/${apitotest}/build/classes/ + diff -r 621462e58e22 -r 2ae6e4aa7aef taskx/psmid/against-solution11/test/apifest/CurrencyTest.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/taskx/psmid/against-solution11/test/apifest/CurrencyTest.java Sat Oct 25 20:53:00 2008 +0200 @@ -0,0 +1,29 @@ +package apifest; + +import junit.framework.TestCase; +import org.apidesign.apifest08.currency.Convertor; +import org.apidesign.apifest08.currency.CurrencyValue; +//import static org.apidesign.apifest08.test.Currencies.CZK; +//import static org.apidesign.apifest08.test.Currencies.SKK; +//import static org.apidesign.apifest08.test.Currencies.USD; + +/** Write a test that works with version from task A and fails with version B. + */ +public class CurrencyTest extends TestCase { + public CurrencyTest(String n) { + super(n); + } + + public void testCompatibility() throws Exception { + try { + Convertor c = Convertor.getConvertorIntegerString( + CurrencyValue.getCurrencyValue(1, "CZK"), + CurrencyValue.getCurrencyValue(1, "CZK") + ); + c.convert("CZK", CurrencyValue.getCurrencyValue(10, "CZK")); + fail("Should throw exception"); + } catch (IllegalArgumentException e) { + //ok + } + } +} diff -r 621462e58e22 -r 2ae6e4aa7aef taskx/psmid/against-solution13/build.xml --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/taskx/psmid/against-solution13/build.xml Sat Oct 25 20:53:00 2008 +0200 @@ -0,0 +1,5 @@ + + + + + diff -r 621462e58e22 -r 2ae6e4aa7aef taskx/psmid/against-solution13/nbproject/project.xml --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/taskx/psmid/against-solution13/nbproject/project.xml Sat Oct 25 20:53:00 2008 +0200 @@ -0,0 +1,82 @@ + + + org.netbeans.modules.ant.freeform + + + + testing template + + build.xml + ../../../ + project.properties + ${apifest}/taskx/common.properties + + + + + java + test + + + + + + compile + + + + clean + + + + test + + + + test + + + + clean + compile + + + + folder + build/tests + + compile + + + + + + test + + + ${ant.script} + + + project.properties + + + + + + + + + + + + + + + test + ${apiA}:${junit.jar} + build/tests + 1.5 + + + + diff -r 621462e58e22 -r 2ae6e4aa7aef taskx/psmid/against-solution13/project.properties --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/taskx/psmid/against-solution13/project.properties Sat Oct 25 20:53:00 2008 +0200 @@ -0,0 +1,16 @@ + +# name of a project to test +#apitotest=todo:specify_this_property_in:project.properties +#for example use: +apitotest=solution13 + +# the test shall expose a problem between two versions +# of one API. select the first version - taskA and a second +# version of the of the API taskB +taskA=${apifest}/task1 +taskB=${apifest}/task2 + +# usual locations of API classes for each version +apiA=${taskA}/${apitotest}/build/classes/ +apiB=${taskB}/${apitotest}/build/classes/ + diff -r 621462e58e22 -r 2ae6e4aa7aef taskx/psmid/against-solution13/test/apifest/CurrencyTest.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/taskx/psmid/against-solution13/test/apifest/CurrencyTest.java Sat Oct 25 20:53:00 2008 +0200 @@ -0,0 +1,26 @@ +package apifest; + +import junit.framework.TestCase; +import org.apidesign.apifest08.currency.ConvertorCurrency; +import org.apidesign.apifest08.currency.ExchangeRate; +import org.apidesign.apifest08.currency.ExchangeRateProvider; + + +/** Write a test that works with version from task A and fails with version B. + */ + +public class CurrencyTest extends TestCase { + + + public CurrencyTest(String n) { + super(n); + } + + public void testCompatibility() throws Exception { + ExchangeRateProvider e = new ExchangeRateProvider(null, null, null, null) { + private ExchangeRate getExchangeRate(ConvertorCurrency a, ConvertorCurrency b) { //in version B it shouln't compile + return null; + } + }; + } +}