# HG changeset patch # User Jaroslav Tulach # Date 1224959454 -7200 # Node ID 621462e58e22ce63f5b6bce755733e0c9d530738 # Parent f2a4b0e116c24de9e841de8a7fccb7cfa758ee17 Jan Zak managed to break solutions 4, 6, 13, 14 diff -r f2a4b0e116c2 -r 621462e58e22 taskx/ked/against-solution04/build.xml --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/taskx/ked/against-solution04/build.xml Sat Oct 25 20:30:54 2008 +0200 @@ -0,0 +1,5 @@ + + + + + diff -r f2a4b0e116c2 -r 621462e58e22 taskx/ked/against-solution04/nbproject/project.xml --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/taskx/ked/against-solution04/nbproject/project.xml Sat Oct 25 20:30:54 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 f2a4b0e116c2 -r 621462e58e22 taskx/ked/against-solution04/project.properties --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/taskx/ked/against-solution04/project.properties Sat Oct 25 20:30:54 2008 +0200 @@ -0,0 +1,16 @@ + +# name of a project to test +apitotest=solution04 +#for example use: +#apitotest=solution01 + +# 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 f2a4b0e116c2 -r 621462e58e22 taskx/ked/against-solution04/test/apifest/CurrencyTest.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/taskx/ked/against-solution04/test/apifest/CurrencyTest.java Sat Oct 25 20:30:54 2008 +0200 @@ -0,0 +1,33 @@ +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.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 { + Convertor myOwnImplementationOfConvertor = + new MyOwnImplementationOfConvertor(); + + BigDecimal result = myOwnImplementationOfConvertor.convert( + Currency.getInstance("CZK"), + Currency.getInstance("USD"), + new BigDecimal("1")); + assertEquals(1, result.intValue()); + } + + class MyOwnImplementationOfConvertor implements Convertor { + public BigDecimal convert(Currency from, Currency to, BigDecimal amount) throws InvalidConversionException { + return amount; // not very smart implementation + } + } +} diff -r f2a4b0e116c2 -r 621462e58e22 taskx/ked/against-solution06/build.xml --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/taskx/ked/against-solution06/build.xml Sat Oct 25 20:30:54 2008 +0200 @@ -0,0 +1,5 @@ + + + + + diff -r f2a4b0e116c2 -r 621462e58e22 taskx/ked/against-solution06/nbproject/project.xml --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/taskx/ked/against-solution06/nbproject/project.xml Sat Oct 25 20:30:54 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 f2a4b0e116c2 -r 621462e58e22 taskx/ked/against-solution06/project.properties --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/taskx/ked/against-solution06/project.properties Sat Oct 25 20:30:54 2008 +0200 @@ -0,0 +1,16 @@ + +# name of a project to test +apitotest=solution06 +#for example use: +#apitotest=solution01 + +# 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 f2a4b0e116c2 -r 621462e58e22 taskx/ked/against-solution06/test/apifest/CurrencyTest.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/taskx/ked/against-solution06/test/apifest/CurrencyTest.java Sat Oct 25 20:30:54 2008 +0200 @@ -0,0 +1,19 @@ +package apifest; + +import java.math.BigDecimal; +import junit.framework.TestCase; +import org.apidesign.apifest08.currency.Convertor; + + +/** 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 { + BigDecimal iWantToUseThisAPIConstant = Convertor.one; + assertEquals(1, iWantToUseThisAPIConstant.intValue()); + } +} diff -r f2a4b0e116c2 -r 621462e58e22 taskx/ked/against-solution13/build.xml --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/taskx/ked/against-solution13/build.xml Sat Oct 25 20:30:54 2008 +0200 @@ -0,0 +1,5 @@ + + + + + diff -r f2a4b0e116c2 -r 621462e58e22 taskx/ked/against-solution13/nbproject/project.xml --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/taskx/ked/against-solution13/nbproject/project.xml Sat Oct 25 20:30:54 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 f2a4b0e116c2 -r 621462e58e22 taskx/ked/against-solution13/project.properties --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/taskx/ked/against-solution13/project.properties Sat Oct 25 20:30:54 2008 +0200 @@ -0,0 +1,16 @@ + +# name of a project to test +apitotest=solution13 +#for example use: +#apitotest=solution01 + +# 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 f2a4b0e116c2 -r 621462e58e22 taskx/ked/against-solution13/test/apifest/CurrencyTest.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/taskx/ked/against-solution13/test/apifest/CurrencyTest.java Sat Oct 25 20:30:54 2008 +0200 @@ -0,0 +1,49 @@ +package apifest; + +import java.math.BigDecimal; +import junit.framework.TestCase; +import org.apidesign.apifest08.currency.Convertor; +import org.apidesign.apifest08.currency.ConvertorCurrency; +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); + } + + /** Fails because runtime incompatibility. */ + public void testCompatibility() throws Exception { + ConvertorCurrency cur1 = ConvertorCurrency.getInstance("CZK"); + ConvertorCurrency cur2 = ConvertorCurrency.getInstance("CZK"); + + assertEquals(false, cur1.equals(cur2)); + } + + /** Fails because source incompatibility. */ + public void testCompatibility2() throws Exception { + MyOwnExchangeRateProvider provider = new MyOwnExchangeRateProvider( + new BigDecimal("1"), ConvertorCurrency.getInstance("USD"), + new BigDecimal("16"), ConvertorCurrency.getInstance("CZK")); + Convertor c = Convertor.createConvertor(provider); + + boolean result = provider.addFixedCurencyRate( + ConvertorCurrency.getInstance("CZK"), new BigDecimal("80"), + ConvertorCurrency.getInstance("SKK"), new BigDecimal("100")); + assertEquals(true, result); + } + + class MyOwnExchangeRateProvider extends ExchangeRateProvider { + + public MyOwnExchangeRateProvider(BigDecimal fromValue, ConvertorCurrency fromCurrency, BigDecimal toValue, ConvertorCurrency toCurrency) { + super(fromValue, fromCurrency, toValue, toCurrency); + } + + public boolean addFixedCurencyRate(ConvertorCurrency fromCurrency, BigDecimal fromValue, ConvertorCurrency toCurrency, BigDecimal toValue) { + return true; // great method - do nothing and is always satisfied ;-) + } + + } +} diff -r f2a4b0e116c2 -r 621462e58e22 taskx/ked/against-solution14/build.xml --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/taskx/ked/against-solution14/build.xml Sat Oct 25 20:30:54 2008 +0200 @@ -0,0 +1,5 @@ + + + + + diff -r f2a4b0e116c2 -r 621462e58e22 taskx/ked/against-solution14/nbproject/project.xml --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/taskx/ked/against-solution14/nbproject/project.xml Sat Oct 25 20:30:54 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 f2a4b0e116c2 -r 621462e58e22 taskx/ked/against-solution14/project.properties --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/taskx/ked/against-solution14/project.properties Sat Oct 25 20:30:54 2008 +0200 @@ -0,0 +1,16 @@ + +# name of a project to test +apitotest=solution14 +#for example use: +#apitotest=solution01 + +# 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 f2a4b0e116c2 -r 621462e58e22 taskx/ked/against-solution14/test/apifest/CurrencyTest.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/taskx/ked/against-solution14/test/apifest/CurrencyTest.java Sat Oct 25 20:30:54 2008 +0200 @@ -0,0 +1,56 @@ +package apifest; + +import junit.framework.TestCase; +import org.apidesign.apifest08.currency.Convertor; +import org.apidesign.apifest08.currency.ConvertorFactory; +import org.apidesign.apifest08.currency.CurrencyRate; +import org.apidesign.apifest08.currency.Rate; + + +/** 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 { + + Convertor c = ConvertorFactory.newInstance().createConvertor( + new MyOwnCurrencyRate("CZK", "USD", new Rate(1, 16), "ABCDEF")); + + MyOwnCurrencyRate[] arr = c.getCurrencyRates().toArray(new MyOwnCurrencyRate[1]); + assertEquals("ABCDEF", arr[0].getMyImportantProperty()); + } + + class MyOwnCurrencyRate implements CurrencyRate { + + private final String currency1; + private final String currency2; + private final Rate rate; + private final String myImportantProperty; + + public MyOwnCurrencyRate(String currency1, String currency2, Rate rate, String myImportantProperty) { + this.currency1 = currency1; + this.currency2 = currency2; + this.rate = rate; + this.myImportantProperty = myImportantProperty; + } + + public String getCurrency1() { + return currency1; + } + + public String getCurrency2() { + return currency2; + } + + public Rate getRate() { + return rate; + } + + public String getMyImportantProperty() { + return myImportantProperty; + } + } +}