# HG changeset patch # User Jaroslav Tulach # Date 1224258136 -7200 # Node ID 6f4b6952f98833eedef3170925d74bdc01019dfa # Parent 420baec87dc5488afa0ae3b73805073702c89b54 Owner of solution 2 did not sent the solution for task 4, as far as I can tell diff -r 420baec87dc5 -r 6f4b6952f988 task4/solution02/build.xml --- a/task4/solution02/build.xml Fri Oct 17 17:40:14 2008 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,69 +0,0 @@ - - - - - - Builds, tests, and runs the project. - - - diff -r 420baec87dc5 -r 6f4b6952f988 task4/solution02/nbproject/build-impl.xml --- a/task4/solution02/nbproject/build-impl.xml Fri Oct 17 17:40:14 2008 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,642 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Must set src.dir - Must set test.src.dir - Must set build.dir - Must set dist.dir - Must set build.classes.dir - Must set dist.javadoc.dir - Must set build.test.classes.dir - Must set build.test.results.dir - Must set build.classes.excludes - Must set dist.jar - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Must set javac.includes - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Must select some files in the IDE or set javac.includes - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - To run this application from the command line without Ant, try: - - - - - - - java -cp "${run.classpath.with.dist.jar}" ${main.class} - - - - - - - - - - - - - - - - - - - - - - - To run this application from the command line without Ant, try: - - java -jar "${dist.jar.resolved}" - - - - - - - - - - - - - - - - - - - Must select one file in the IDE or set run.class - - - - - - - - - - - - - - - - - - - - Must select one file in the IDE or set debug.class - - - - - Must set fix.includes - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Must select some files in the IDE or set javac.includes - - - - - - - - - - - - - - - - - - - - Some tests failed; see details above. - - - - - - - - - Must select some files in the IDE or set test.includes - - - - Some tests failed; see details above. - - - - - Must select one file in the IDE or set test.class - - - - - - - - - - - - - - - - - - - - - - - - - - - Must select one file in the IDE or set applet.url - - - - - - - - - Must select one file in the IDE or set applet.url - - - - - - - - - - - - - - - - - - - diff -r 420baec87dc5 -r 6f4b6952f988 task4/solution02/nbproject/genfiles.properties --- a/task4/solution02/nbproject/genfiles.properties Fri Oct 17 17:40:14 2008 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,8 +0,0 @@ -build.xml.data.CRC32=2ab820eb -build.xml.script.CRC32=58a52595 -build.xml.stylesheet.CRC32=be360661 -# This file is used by a NetBeans-based IDE to track changes in generated files such as build-impl.xml. -# Do not edit this file. You may delete it but then the IDE will never regenerate such files for you. -nbproject/build-impl.xml.data.CRC32=848e6267 -nbproject/build-impl.xml.script.CRC32=6be86987 -nbproject/build-impl.xml.stylesheet.CRC32=e55b27f5 diff -r 420baec87dc5 -r 6f4b6952f988 task4/solution02/nbproject/project.properties --- a/task4/solution02/nbproject/project.properties Fri Oct 17 17:40:14 2008 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,68 +0,0 @@ -application.title=currency -application.vendor=apidesign.org -auxiliary.org-netbeans-modules-editor-indent.CodeStyle.project.tab-size=8 -auxiliary.org-netbeans-modules-editor-indent.CodeStyle.project.text-limit-width=80 -auxiliary.org-netbeans-modules-editor-indent.CodeStyle.usedProfile=default -build.classes.dir=${build.dir}/classes -build.classes.excludes=**/*.java,**/*.form -# This directory is removed when the project is cleaned: -build.dir=build -build.generated.dir=${build.dir}/generated -# Only compile against the classpath explicitly listed here: -build.sysclasspath=ignore -build.test.classes.dir=${build.dir}/test/classes -build.test.results.dir=${build.dir}/test/results -debug.classpath=\ - ${run.classpath} -debug.test.classpath=\ - ${run.test.classpath} -# This directory is removed when the project is cleaned: -dist.dir=dist -dist.jar=${dist.dir}/currency.jar -dist.javadoc.dir=${dist.dir}/javadoc -excludes= -file.reference.junit-4.4.jar=../../libs/junit-4.4.jar -file.reference.src-apifest08=.. -includes=** -jar.compress=false -javac.classpath= -# Space-separated list of extra javac options -javac.compilerargs= -javac.deprecation=false -javac.source=1.5 -javac.target=1.5 -javac.test.classpath=\ - ${javac.classpath}:\ - ${build.classes.dir}:\ - ${file.reference.junit-4.4.jar} -javadoc.additionalparam= -javadoc.author=false -javadoc.encoding= -javadoc.noindex=false -javadoc.nonavbar=false -javadoc.notree=false -javadoc.private=false -javadoc.splitindex=true -javadoc.use=true -javadoc.version=false -javadoc.windowtitle= -jnlp.codebase.type=local -jnlp.codebase.url=file:/home/jarda/src/apifest08/currency/dist -jnlp.descriptor=application -jnlp.enabled=false -jnlp.offline-allowed=false -jnlp.signed=false -meta.inf.dir=${src.dir}/META-INF -platform.active=default_platform -run.classpath=\ - ${javac.classpath}:\ - ${build.classes.dir} -# Space-separated list of JVM arguments used when running the project -# (you may also define separate properties like run-sys-prop.name=value instead of -Dname=value -# or test-sys-prop.name=value to set system properties for unit tests): -run.jvmargs= -run.test.classpath=\ - ${javac.test.classpath}:\ - ${build.test.classes.dir} -src.dir=src -test.src.dir=test diff -r 420baec87dc5 -r 6f4b6952f988 task4/solution02/nbproject/project.xml --- a/task4/solution02/nbproject/project.xml Fri Oct 17 17:40:14 2008 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,16 +0,0 @@ - - - org.netbeans.modules.java.j2seproject - - - Currency Convertor Solution 02 - 1.6.5 - - - - - - - - - diff -r 420baec87dc5 -r 6f4b6952f988 task4/solution02/src/org/apidesign/apifest08/currency/CompositeConvertor.java --- a/task4/solution02/src/org/apidesign/apifest08/currency/CompositeConvertor.java Fri Oct 17 17:40:14 2008 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,75 +0,0 @@ -package org.apidesign.apifest08.currency; - -import java.io.Serializable; -import java.util.Arrays; -import java.util.Currency; - -/** - * Convertor that is composed from other convertors. - * @author lukas - * - */ -class CompositeConvertor implements ExtendedConvertor, Serializable { - - private static final long serialVersionUID = -2702026568249130055L; - - private final ExtendedConvertor[] convertors; - - - public CompositeConvertor(ExtendedConvertor... convertors) { - this.convertors = convertors.clone(); - for (ExtendedConvertor convertor: this.convertors) - { - if (convertor==null) - { - throw new NullPointerException("One of the convertors to be merged is null"); - } - } - } - - /** - * Returns true if the composite contains convertor that supports given conversion. - */ - public boolean isConversionSupported(Currency from, Currency to) { - return findConvertorFor(from, to)!=null; - } - - - /** - * If the composite contains convertor that supports given conversion, delegates to its convert method. - * Throws {@link IllegalArgumentException} convertor supporting given conversion is not found. - */ - public Money convert(Money amount, Currency destinationCurrency) throws IllegalArgumentException { - ExtendedConvertor convertor = findConvertorFor(amount.getCurrency(), destinationCurrency); - if (convertor!=null) - { - return convertor.convert(amount, destinationCurrency); - } - throw new IllegalArgumentException("Conversion not supported. Can not convert to "+destinationCurrency+"."); - } - - /** - * Finds convertor for given currencies. If not found, returns null. - * @param from - * @param to - * @return - */ - ExtendedConvertor findConvertorFor(Currency from, Currency to) { - //does linear search, in the future can cache the results. - for (ExtendedConvertor convertor:convertors) - { - if (convertor.isConversionSupported(from, to)) - { - return convertor; - } - } - return null; - } - - - @Override - public String toString() { - return getClass().getName()+" converts "+Arrays.toString(convertors); - } - -} diff -r 420baec87dc5 -r 6f4b6952f988 task4/solution02/src/org/apidesign/apifest08/currency/Convertor.java --- a/task4/solution02/src/org/apidesign/apifest08/currency/Convertor.java Fri Oct 17 17:40:14 2008 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,18 +0,0 @@ -package org.apidesign.apifest08.currency; - -import java.util.Currency; - - -/** - * Converts currencies. To create an instance call {@link ConvertorFactory#createConvertor(Money, Money)}. - */ -public interface Convertor { - /** - * Converts amount to its equivalent in the destination currency. - * @param amount - * @param destinationCurrency - * @return - * @throws IllegalArgumentException if currency of the amount is not supported or if it is not possible to convert it to the destination currency. - */ - public Money convert(Money amount, Currency destinationCurrency) throws IllegalArgumentException; -} diff -r 420baec87dc5 -r 6f4b6952f988 task4/solution02/src/org/apidesign/apifest08/currency/ConvertorFactory.java --- a/task4/solution02/src/org/apidesign/apifest08/currency/ConvertorFactory.java Fri Oct 17 17:40:14 2008 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,46 +0,0 @@ -package org.apidesign.apifest08.currency; - - - -/** - * Creates {@link Convertor} implementations. - * @author lukas - * - */ -public class ConvertorFactory { - private ConvertorFactory() - { - //nothing - } - - /** - * Creates {@link Convertor} that converts from sourceEquivalent.currency to destinationEquivalent.currency. - * Exchange rate is set as equivalents. It means if you want to create USD to CZK convertor where USD1 = CZK17 - * call createConvertor(new MoneyImpl(1, USD), new MoneyImpl(17, CZK)). Convertor created by this method - * rounds the result to two decimal places. Convertor created by this method is thread safe. - * @param sourceEquivalent - * @param destinationEquivalent - * @return - */ - public static final ExtendedConvertor createConvertor(Money sourceEquivalent, Money destinationEquivalent) - { - return mergeConvertors( - new DefaultConvertor(sourceEquivalent, destinationEquivalent), - new DefaultConvertor(destinationEquivalent ,sourceEquivalent) - ); - } - - /** - * Merges convertors. The resulting convertor has ability to do all conversions that its underlying - * convertors could do. No consistency validation is done, inconsistent input will result in a convertor with - * inconsistent behavior. Convertor created by this method is thread safe. - * @param convertors - * @return - */ - public static final ExtendedConvertor mergeConvertors(ExtendedConvertor... convertors) - { - return new CompositeConvertor(convertors); - } - - -} diff -r 420baec87dc5 -r 6f4b6952f988 task4/solution02/src/org/apidesign/apifest08/currency/DefaultConvertor.java --- a/task4/solution02/src/org/apidesign/apifest08/currency/DefaultConvertor.java Fri Oct 17 17:40:14 2008 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,95 +0,0 @@ -package org.apidesign.apifest08.currency; - -import java.io.Serializable; -import java.math.BigDecimal; -import java.math.RoundingMode; -import java.util.Currency; - -/** - * Default {@link Convertor} implementation. Exchange rate is stored as equivalents. It means if we have USD to CZK convertor and USD1 = CZK17 - * we store 1 in sourceEquivalent and 17 in destinationEquivalent. This class is immutable. - * @author lukas - * - */ -class DefaultConvertor implements ExtendedConvertor, Serializable { - - private static final long serialVersionUID = 6660014633685135034L; - - /** - * Equivalent in source currency. - */ - private final BigDecimal sourceEquivalent; - - /** - * Equivalent in destination currency. - */ - private final BigDecimal destinationEquivalent; - - private final Currency sourceCurrency; - - private final Currency destinationCurrency; - - public DefaultConvertor(Money sourceEquivalent, Money destinationEquivalent) { - super(); - if (BigDecimal.ZERO.compareTo(sourceEquivalent.getAmount())==0) - { - throw new IllegalArgumentException("Source equivalent amount can not be 0."); - } - if (BigDecimal.ZERO.compareTo(destinationEquivalent.getAmount())==0) - { - throw new IllegalArgumentException("Destination equivalent amount can not be 0."); - } - this.sourceEquivalent = sourceEquivalent.getAmount(); - this.destinationEquivalent = destinationEquivalent.getAmount(); - this.sourceCurrency = sourceEquivalent.getCurrency(); - this.destinationCurrency = destinationEquivalent.getCurrency(); - } - - public Money convert(Money amount, Currency destinationCurrency) { - if (amount==null) - { - throw new NullPointerException("Money is null"); - } - if (destinationCurrency==null) - { - throw new NullPointerException("destionationCurrency is null"); - } - if (!amount.getCurrency().equals(getSourceCurrency())) - { - throw new IllegalArgumentException("Can not convert from "+amount.getCurrency()+". Converts between "+getSourceCurrency()+" and "+getDestinationCurrency()); - } - if (!getDestinationCurrency().equals(destinationCurrency)) - { - throw new IllegalArgumentException("Can not convert to "+destinationCurrency+". Converts between "+getSourceCurrency()+" and "+getDestinationCurrency()); - } - BigDecimal sourceAmount = amount.getAmount(); - BigDecimal destinationAmount = sourceAmount.multiply(destinationEquivalent).divide(sourceEquivalent, 2, RoundingMode.HALF_UP); - return new MoneyImpl(destinationAmount, getDestinationCurrency()); - } - - public boolean isConversionSupported(Currency from, Currency to) { - return sourceCurrency.equals(from) && destinationCurrency.equals(to); - } - - public BigDecimal getSourceEquivalent() { - return sourceEquivalent; - } - - public BigDecimal getDestinationEquivalent() { - return destinationEquivalent; - } - - public Currency getSourceCurrency() { - return sourceCurrency; - } - - public Currency getDestinationCurrency() { - return destinationCurrency; - } - - @Override - public String toString() { - return getClass().getName()+" converts "+getSourceCurrency()+" to "+getDestinationCurrency()+" " - +getSourceCurrency()+getSourceEquivalent()+"="+getDestinationCurrency()+getDestinationEquivalent(); - } -} diff -r 420baec87dc5 -r 6f4b6952f988 task4/solution02/src/org/apidesign/apifest08/currency/ExtendedConvertor.java --- a/task4/solution02/src/org/apidesign/apifest08/currency/ExtendedConvertor.java Fri Oct 17 17:40:14 2008 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,18 +0,0 @@ -package org.apidesign.apifest08.currency; - -import java.util.Currency; - -/** - * Extended convertor interface. - * @author lukas - * - */ -public interface ExtendedConvertor extends Convertor { - /** - * Returns true if given conversion is supported. - * @param from - * @param to - * @return - */ - public boolean isConversionSupported(Currency from, Currency to); -} diff -r 420baec87dc5 -r 6f4b6952f988 task4/solution02/src/org/apidesign/apifest08/currency/Money.java --- a/task4/solution02/src/org/apidesign/apifest08/currency/Money.java Fri Oct 17 17:40:14 2008 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,29 +0,0 @@ -package org.apidesign.apifest08.currency; - -import java.math.BigDecimal; -import java.util.Currency; - -/** - * Money representation. Default implementation {@link MoneyImpl} is provided. This interface can - * be implemented by a DTO used in client application. - * @author lukas - * - */ -/* - * Whether we need such interface depends on the context. I can imagine than in a desktop application this interface - * would be useless, Money could be a class. In J2EE environment it can be useful. - */ -public interface Money { - - /** - * Returns amount. - * @return - */ - public BigDecimal getAmount(); - - /** - * Returns currency. - */ - public Currency getCurrency(); - -} \ No newline at end of file diff -r 420baec87dc5 -r 6f4b6952f988 task4/solution02/src/org/apidesign/apifest08/currency/MoneyImpl.java --- a/task4/solution02/src/org/apidesign/apifest08/currency/MoneyImpl.java Fri Oct 17 17:40:14 2008 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,121 +0,0 @@ -package org.apidesign.apifest08.currency; - -import java.io.Serializable; -import java.math.BigDecimal; -import java.util.Currency; - -/** - * Default implementation of {@link Money} interface. This class is immutable. - * @author lukas - * - */ -public final class MoneyImpl implements Serializable, Money{ - private static final long serialVersionUID = -6091808475616516136L; - - private final BigDecimal amount; - - private final Currency currency; - - public MoneyImpl(BigDecimal amount, Currency currency) { - if (amount==null) throw new NullPointerException("Amount is null"); - if (currency==null) throw new NullPointerException("Currency is null"+currency); - this.amount = amount; - this.currency = currency; - } - - - - public MoneyImpl(long amount, Currency currency) { - this(BigDecimal.valueOf(amount), currency); - } - - public MoneyImpl(double amount, Currency currency) { - this(BigDecimal.valueOf(amount), currency); - } - - /** - * Factory method. - * @param amount - * @param currency - * @return - */ - public static final Money money(BigDecimal amount, Currency currency) - { - return new MoneyImpl(amount, currency); - } - /** - * Factory method. - * @param amount - * @param currency - * @return - */ - public static final Money money(long amount, Currency currency) - { - return new MoneyImpl(amount, currency); - } - /** - * Factory method. - * @param amount - * @param currency - * @return - */ - public static final Money money(double amount, Currency currency) - { - return new MoneyImpl(amount, currency); - } - - /** - * Returns amount. - * @return - */ - public BigDecimal getAmount() { - return amount; - } - - /** - * Returns currency. - */ - public Currency getCurrency() { - return currency; - } - - @Override - public int hashCode() { - final int prime = 31; - int result = 1; - result = prime * result + ((amount == null) ? 0 : amount.hashCode()); - result = prime * result - + ((currency == null) ? 0 : currency.hashCode()); - return result; - } - - @Override - public boolean equals(Object obj) { - if (this == obj) - return true; - if (obj == null) - return false; - if (!(obj instanceof MoneyImpl)) - return false; - MoneyImpl other = (MoneyImpl) obj; - if (amount == null) { - if (other.amount != null) - return false; - } else if (amount.compareTo(other.amount)!=0) - return false; - if (currency == null) { - if (other.currency != null) - return false; - } else if (!currency.equals(other.currency)) - return false; - return true; - } - - @Override - public String toString() { - return getClass().getName()+"["+currency+amount+"]"; - } - - - -} diff -r 420baec87dc5 -r 6f4b6952f988 task4/solution02/test/org/apidesign/apifest08/currency/CompositeConvertorTest.java --- a/task4/solution02/test/org/apidesign/apifest08/currency/CompositeConvertorTest.java Fri Oct 17 17:40:14 2008 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,56 +0,0 @@ -package org.apidesign.apifest08.currency; - -import static junit.framework.Assert.assertEquals; -import static junit.framework.Assert.assertFalse; -import static junit.framework.Assert.assertTrue; -import static junit.framework.Assert.fail; -import static org.apidesign.apifest08.test.Task1Test.CZK; -import static org.apidesign.apifest08.test.Task1Test.SKK; -import static org.apidesign.apifest08.test.Task1Test.USD; - -import org.junit.Test; - -public class CompositeConvertorTest { - private static final ExtendedConvertor USD_CZK_CONVERTOR = ConvertorFactory.createConvertor(new MoneyImpl(1,USD), new MoneyImpl(17,CZK)); - private static final ExtendedConvertor SKK_CZK_CONVERTOR = ConvertorFactory.createConvertor(new MoneyImpl(100,SKK), new MoneyImpl(80,CZK)); - - @Test - public void testCompose() - { - ExtendedConvertor convertor = new CompositeConvertor(USD_CZK_CONVERTOR, SKK_CZK_CONVERTOR); - assertTrue(convertor.isConversionSupported(CZK, SKK)); - assertTrue(convertor.isConversionSupported(CZK, USD)); - assertFalse(convertor.isConversionSupported(SKK, USD)); - assertEquals(new MoneyImpl(10,SKK), convertor.convert(new MoneyImpl(8,CZK), SKK)); - assertEquals(new MoneyImpl(2,USD), convertor.convert(new MoneyImpl(34,CZK), USD)); - try - { - convertor.convert(new MoneyImpl(34,SKK), USD); - fail("Exception expected"); - } - catch(IllegalArgumentException e) - { - assertTrue("Ok", true); - } - } - @Test - public void testEmpty() - { - ExtendedConvertor convertor = new CompositeConvertor(); - assertFalse(convertor.isConversionSupported(SKK, USD)); - try - { - convertor.convert(new MoneyImpl(34,SKK), USD); - fail("Exception expected"); - } - catch(IllegalArgumentException e) - { - assertTrue("Ok", true); - } - } - @Test(expected=NullPointerException.class) - public void testCreateNull() - { - new CompositeConvertor(USD_CZK_CONVERTOR, null); - } -} diff -r 420baec87dc5 -r 6f4b6952f988 task4/solution02/test/org/apidesign/apifest08/test/ConvertorFactoryTest.java --- a/task4/solution02/test/org/apidesign/apifest08/test/ConvertorFactoryTest.java Fri Oct 17 17:40:14 2008 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,52 +0,0 @@ -package org.apidesign.apifest08.test; - -import static junit.framework.Assert.assertNotNull; -import static org.apidesign.apifest08.test.Task1Test.CZK; -import static org.apidesign.apifest08.test.Task1Test.USD; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; -import static org.junit.Assert.fail; - -import org.apidesign.apifest08.currency.Convertor; -import org.apidesign.apifest08.currency.ConvertorFactory; -import org.apidesign.apifest08.currency.MoneyImpl; -import org.junit.Test; - - -public class ConvertorFactoryTest { - @Test(expected=NullPointerException.class) - public void testNullSource() - { - ConvertorFactory.createConvertor(null, new MoneyImpl(1,USD)); - } - @Test(expected=NullPointerException.class) - public void testNullDestination() - { - ConvertorFactory.createConvertor(new MoneyImpl(17,CZK), null); - } - @Test - public void testOk() - { - assertNotNull(ConvertorFactory.createConvertor(new MoneyImpl(17,CZK), new MoneyImpl(1,USD))); - } - @Test - public void testOkDecimalRate() - { - Convertor c = ConvertorFactory.createConvertor(new MoneyImpl(1,CZK), new MoneyImpl(1d/17d,USD)); - assertNotNull(c); - assertEquals(new MoneyImpl(17,CZK),c.convert(new MoneyImpl(1,USD), CZK)); - } - @Test - public void testZeroEquivalentRate() - { - try - { - ConvertorFactory.createConvertor(new MoneyImpl(1,CZK), new MoneyImpl(0,USD)); - fail("Exception expected"); - } - catch(IllegalArgumentException e) - { - assertTrue("OK",true); - } - } -} diff -r 420baec87dc5 -r 6f4b6952f988 task4/solution02/test/org/apidesign/apifest08/test/ConvertorTest.java --- a/task4/solution02/test/org/apidesign/apifest08/test/ConvertorTest.java Fri Oct 17 17:40:14 2008 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,44 +0,0 @@ -package org.apidesign.apifest08.test; - -import static junit.framework.Assert.assertEquals; -import static junit.framework.Assert.assertFalse; -import static junit.framework.Assert.assertTrue; -import static org.apidesign.apifest08.test.Task1Test.CZK; -import static org.apidesign.apifest08.test.Task1Test.SKK; -import static org.apidesign.apifest08.test.Task1Test.USD; - -import java.math.BigDecimal; - -import org.apidesign.apifest08.currency.ConvertorFactory; -import org.apidesign.apifest08.currency.ExtendedConvertor; -import org.apidesign.apifest08.currency.Money; -import org.apidesign.apifest08.currency.MoneyImpl; -import org.junit.Test; - - -public class ConvertorTest { - - private static final ExtendedConvertor CZK_TO_USD_CONVERTOR = ConvertorFactory.createConvertor(new MoneyImpl(17,CZK), new MoneyImpl(1,USD)); - @Test - public void testConvertSmall() - { - Money converted = CZK_TO_USD_CONVERTOR.convert(new MoneyImpl(0.17,CZK),USD); - assertEquals(new MoneyImpl(new BigDecimal("0.01"),USD),converted); - assertEquals(USD,converted.getCurrency()); - } - @Test - public void testConvertSmallReverse() - { - Money converted = CZK_TO_USD_CONVERTOR.convert(new MoneyImpl(0.01,USD),CZK); - assertEquals(new MoneyImpl(new BigDecimal("0.17"),CZK),converted); - } - @Test - public void testSupports() - { - assertTrue(CZK_TO_USD_CONVERTOR.isConversionSupported(USD,CZK)); - assertTrue(CZK_TO_USD_CONVERTOR.isConversionSupported(CZK,USD)); - assertFalse(CZK_TO_USD_CONVERTOR.isConversionSupported(CZK,CZK)); - assertFalse(CZK_TO_USD_CONVERTOR.isConversionSupported(CZK,SKK)); - - } -} diff -r 420baec87dc5 -r 6f4b6952f988 task4/solution02/test/org/apidesign/apifest08/test/MoneyTest.java --- a/task4/solution02/test/org/apidesign/apifest08/test/MoneyTest.java Fri Oct 17 17:40:14 2008 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,24 +0,0 @@ -package org.apidesign.apifest08.test; - -import static junit.framework.Assert.assertEquals; -import static org.apidesign.apifest08.test.Task1Test.CZK; - -import java.math.BigDecimal; - -import org.apidesign.apifest08.currency.MoneyImpl; -import org.junit.Test; - -public class MoneyTest { - @Test(expected=NullPointerException.class) - public void testNullAmount(){ - new MoneyImpl(null,CZK); - } - @Test(expected=NullPointerException.class) - public void testNullCurrency(){ - new MoneyImpl(1,null); - } - @Test - public void testOk(){ - assertEquals(0,new MoneyImpl(123,CZK).getAmount().compareTo(new BigDecimal("123"))); - } -} diff -r 420baec87dc5 -r 6f4b6952f988 task4/solution02/test/org/apidesign/apifest08/test/OnlineConvertor.java --- a/task4/solution02/test/org/apidesign/apifest08/test/OnlineConvertor.java Fri Oct 17 17:40:14 2008 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,54 +0,0 @@ -package org.apidesign.apifest08.test; - -import java.math.BigDecimal; -import java.util.Currency; - -import org.apidesign.apifest08.currency.ConvertorFactory; -import org.apidesign.apifest08.currency.ExtendedConvertor; -import org.apidesign.apifest08.currency.Money; -import org.apidesign.apifest08.currency.MoneyImpl; - -/** - * Third party implementation of the convertor. IT IS NOT THREAD SAFE. - * @author lukas - * - */ -class OnlineConvertor implements ExtendedConvertor { - - private static final BigDecimal LOWER_LIMIT = BigDecimal.valueOf(15); - private static final BigDecimal HIGHER_LIMIT = BigDecimal.valueOf(16); - - private static final Currency USD = Currency.getInstance("USD"); - private static final Currency CZK = Currency.getInstance("CZK"); - private static final MoneyImpl ONE_USD = new MoneyImpl(1,USD); - - private ExtendedConvertor wrappedConvertor = ConvertorFactory.createConvertor(ONE_USD, new MoneyImpl(16, CZK)); - - private BigDecimal increment = new BigDecimal("-0.01"); - - public boolean isConversionSupported(Currency from, Currency to) { - return wrappedConvertor.isConversionSupported(from, to); - } - - public Money convert(Money amount, Currency destinationCurrency) - throws IllegalArgumentException { - Money result = wrappedConvertor.convert(amount, destinationCurrency); - updateConvertor(); - return result; - } - - /** - * Prepares convertor for the next conversion. - */ - private void updateConvertor() { - BigDecimal currentRate = wrappedConvertor.convert(ONE_USD, CZK).getAmount(); - BigDecimal newRate = currentRate.add(increment); - - if (LOWER_LIMIT.compareTo(newRate)==0 || HIGHER_LIMIT.compareTo(newRate)==0) - { - increment = increment.negate(); - } - wrappedConvertor = ConvertorFactory.createConvertor(ONE_USD, new MoneyImpl(newRate, CZK)); - } - -} diff -r 420baec87dc5 -r 6f4b6952f988 task4/solution02/test/org/apidesign/apifest08/test/OnlineConvertorTest.java --- a/task4/solution02/test/org/apidesign/apifest08/test/OnlineConvertorTest.java Fri Oct 17 17:40:14 2008 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,44 +0,0 @@ -package org.apidesign.apifest08.test; -import static junit.framework.Assert.assertEquals; -import static org.apidesign.apifest08.currency.MoneyImpl.money; -import static org.apidesign.apifest08.test.Task1Test.CZK; -import static org.apidesign.apifest08.test.Task1Test.USD; - -import java.math.BigDecimal; - -import org.apidesign.apifest08.currency.Convertor; -import org.apidesign.apifest08.currency.Money; -import org.junit.Test; - -public class OnlineConvertorTest { - private static final Money ONE_USD = money(1, USD); - - @Test - public void testBounce() - { - Convertor c = Task3Test.createOnlineCZKUSDConvertor(); - - doBounceTest(c); - doBounceTest(c); - - } - - private void doBounceTest(Convertor c) { - BigDecimal expectedRate = new BigDecimal(16); - BigDecimal increment = new BigDecimal("0.01"); - - for (int i=0;i<100;i++) - { - assertEquals(money(expectedRate,CZK), c.convert(ONE_USD, CZK)); - expectedRate = expectedRate.subtract(increment); - } - - assertEquals(money(15,CZK), c.convert(ONE_USD, CZK)); - - for (int i=0;i<99;i++) - { - expectedRate = expectedRate.add(increment); - assertEquals(money(expectedRate,CZK), c.convert(ONE_USD, CZK)); - } - } -} diff -r 420baec87dc5 -r 6f4b6952f988 task4/solution02/test/org/apidesign/apifest08/test/Task1Test.java --- a/task4/solution02/test/org/apidesign/apifest08/test/Task1Test.java Fri Oct 17 17:40:14 2008 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,160 +0,0 @@ -package org.apidesign.apifest08.test; - -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.MoneyImpl; - -/** Finish the Convertor API, and then write bodies of methods inside - * of this class to match the given tasks. To fullfil your task, use the - * API define in the org.apidesign.apifest08.currency package. - * Do not you reflection, or other hacks as your code - * shall run without any runtime permissions. - */ -public class Task1Test extends TestCase { - - public static final Currency USD = Currency.getInstance("USD"); - public static final Currency CZK = Currency.getInstance("CZK"); - public static final Currency SKK = Currency.getInstance("SKK"); - - public Task1Test(String testName) { - super(testName); - } - - @Override - protected void setUp() throws Exception { - } - - @Override - 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. 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. - * - * @return prepared convertor ready for converting USD to CZK and CZK to USD - */ - public static Convertor createCZKtoUSD() { - return ConvertorFactory.createConvertor(new MoneyImpl(17,CZK), new MoneyImpl(1,USD)); - } - - /** Create convertor that understands two currencies, CZK and - * 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. - * - * @return prepared convertor ready for converting SKK to CZK and CZK to SKK - */ - public static Convertor createSKKtoCZK() { - return ConvertorFactory.createConvertor(new MoneyImpl(100,SKK), new MoneyImpl(80,CZK)); - } - - // - // 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. - */ - public void testCurrencyCZKUSD() throws Exception { - Convertor c = createCZKtoUSD(); - // convert $5 to CZK using c: - assertEquals("Result is 85 CZK",new MoneyImpl(85,CZK), c.convert(new MoneyImpl(5,USD),CZK)); - - // convert $8 to CZK - assertEquals("Result is 136 CZK",new MoneyImpl(136,CZK), c.convert(new MoneyImpl(8,USD),CZK)); - - // convert 1003CZK to USD - assertEquals("Result is 59 USD", new MoneyImpl(59,USD), c.convert(new MoneyImpl(1003,CZK),USD)); - - } - - /** Use the convertor from createSKKtoCZK method and do few conversions - * with it. - */ - public void testCurrencySKKCZK() throws Exception { - Convertor c = createSKKtoCZK(); - // convert 16CZK using c: - assertEquals("Result is 20 SKK", new MoneyImpl(20,SKK), c.convert(new MoneyImpl(16,CZK),SKK)); - - // convert 500SKK to CZK - assertEquals("Result is 400 CZK", new MoneyImpl(400,CZK), c.convert(new MoneyImpl(500,SKK),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 - try - { - c.convert(new MoneyImpl(5, USD), SKK); - fail("Exception expected"); - } - catch(IllegalArgumentException e) - { - assertTrue("Ok",true); - } - // convert 500 SKK to CZK, the API shall say this is not possible - try - { - c.convert(new MoneyImpl(500, SKK), CZK); - fail("Exception expected"); - } - catch(IllegalArgumentException e) - { - assertTrue("Ok",true); - } - } - - /** Verify that the CZK to SKK convertor knows nothing about USD. - */ - public void testCannotConvertToUSDwithCZKSKKConvertor() throws Exception { - Convertor c = createSKKtoCZK(); - // convert $5 to SKK, the API shall say this is not possible - try - { - c.convert(new MoneyImpl(5, USD), SKK); - fail("Exception expected"); - } - catch(IllegalArgumentException e) - { - assertTrue("Ok",true); - } - // convert 500 CZK to USD, the API shall say this is not possible - try - { - c.convert(new MoneyImpl(500, CZK), USD); - fail("Exception expected"); - } - catch(IllegalArgumentException e) - { - assertTrue("Ok",true); - } - } -} diff -r 420baec87dc5 -r 6f4b6952f988 task4/solution02/test/org/apidesign/apifest08/test/Task2Test.java --- a/task4/solution02/test/org/apidesign/apifest08/test/Task2Test.java Fri Oct 17 17:40:14 2008 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,119 +0,0 @@ -package org.apidesign.apifest08.test; - -import static org.apidesign.apifest08.currency.ConvertorFactory.createConvertor; -import static org.apidesign.apifest08.currency.ConvertorFactory.mergeConvertors; -import static org.apidesign.apifest08.currency.MoneyImpl.money; -import static org.apidesign.apifest08.test.Task1Test.CZK; -import static org.apidesign.apifest08.test.Task1Test.SKK; -import static org.apidesign.apifest08.test.Task1Test.USD; -import junit.framework.TestCase; - -import org.apidesign.apifest08.currency.Convertor; -import org.apidesign.apifest08.currency.ExtendedConvertor; - -/** There are many currencies around the world and many banks manipulate - * with more than one or two at the same time. As banks are usually the - * best paying clients, which is true even in case of your Convertor API, - * it is reasonable to listen to their requests. - *

- * The quest for today is to enhance your existing convertor API to hold - * information about many currencies and allow conversions between any of them. - * Also, as conversion rates for diferent currencies usually arise from various - * bank departments, there is another important need. There is a need to - * compose two convertors into one by merging all the information about - * currencies they know about. - */ -public class Task2Test extends TestCase { - public Task2Test(String testName) { - super(testName); - } - - @Override - protected void setUp() throws Exception { - } - - @Override - protected void tearDown() throws Exception { - } - - // As in Task1Test, keep in mind, 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 backward compatibly enhance your existing API to support following - // usecases: - // - - /** Create convertor that understands two currencies, CZK and - * SKK. Make 100 SKK == 75 CZK. This is method for the group of users that - * 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. - */ - public static Convertor createTripleConvertor() { - // Rates: 1USD = 15CZK - // Rates: 1USD = 20SKK - // Rates: 75CZK = 100SKK - return mergeConvertors( - createConvertor(money(1, USD), money(15, CZK)), - createConvertor(money(1, USD), money(20, SKK)), - createConvertor(money(75, CZK), money(100, SKK)) - ); - } - - /** Define convertor that understands three currencies. Use it. - */ - public void testConvertorForUSDandCZKandSKK() throws Exception { - Convertor c = createTripleConvertor(); - - // convert $5 to CZK using c: - assertEquals("Result is 75 CZK", money(75, CZK),c.convert(money(5,USD), CZK)); - - // convert $5 to SKK using c: - assertEquals("Result is 100 SKK", money(100, SKK),c.convert(money(5,USD), SKK)); - - // convert 200SKK to CZK using c: - assertEquals("Result is 150 CZK", money(150, CZK),c.convert(money(200,SKK), CZK)); - - // convert 200SKK to USK using c: - assertEquals("Result is 10 USD", money(10, USD),c.convert(money(200,SKK), USD)); - } - - /** Merge all currency rates of convertor 1 with convertor 2. - * Implement this using your API, preferably this method just delegates - * into some API method which does the actual work, without requiring - * API clients to code anything complex. - */ - public static Convertor merge(Convertor one, Convertor two) { - return mergeConvertors((ExtendedConvertor)one, (ExtendedConvertor)two); - } - - /** Join the convertors from previous task, Task1Test and show that it - * can be used to do reasonable conversions. - */ - public void testConvertorComposition() throws Exception { - Convertor c = merge( - Task1Test.createCZKtoUSD(), - Task1Test.createSKKtoCZK() - ); - - // convert $5 to CZK using c: - assertEquals("Result is 85 CZK", money(85, CZK),c.convert(money(5,USD), CZK)); - - // convert $8 to CZK using c: - assertEquals("Result is 136 CZK", money(136, CZK),c.convert(money(8,USD), CZK)); - - // convert 1003CZK to USD using c: - assertEquals("Result is 59 USD", money(59, USD),c.convert(money(1003,CZK), USD)); - - // convert 16CZK using c: - assertEquals("Result is 20 SKK", money(20, SKK),c.convert(money(16,CZK), SKK)); - - // convert 500SKK to CZK using c: - assertEquals("Result is 400 CZK", money(400, CZK),c.convert(money(500,SKK), CZK)); - - } -} diff -r 420baec87dc5 -r 6f4b6952f988 task4/solution02/test/org/apidesign/apifest08/test/Task3Test.java --- a/task4/solution02/test/org/apidesign/apifest08/test/Task3Test.java Fri Oct 17 17:40:14 2008 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,100 +0,0 @@ -package org.apidesign.apifest08.test; - -import static org.apidesign.apifest08.currency.MoneyImpl.money; -import static org.apidesign.apifest08.test.Task1Test.CZK; -import static org.apidesign.apifest08.test.Task1Test.SKK; -import static org.apidesign.apifest08.test.Task1Test.USD; -import junit.framework.TestCase; - -import org.apidesign.apifest08.currency.Convertor; - -/** The exchange rates are not always the same. They are changing. Day by day, - * hour by hour, minute by minute. For every bank it is important to always - * have the actual exchange rate available in the system. That is why let's - * create a pluggable convertor that will always have up to date value of its - * exchange rate. - *

- * The quest for today is to allow 3rd party developer to write a convertor - * that adjusts its exchange rate everytime it is queried. This convertor is - * written by independent vendor, the vendor knows only your Convertor API, - * he does not know how the whole system looks and how the convertor is supposed - * to be used. - */ -public class Task3Test extends TestCase { - public Task3Test(String testName) { - super(testName); - } - - @Override - protected void setUp() throws Exception { - } - - @Override - protected void tearDown() throws Exception { - } - - // Backward compatibly enhance your existing API to support following - // usecases: - // - - - /** Without knowing anything about the surrounding system, write an - * implementation of convertor that will return different rates everytime - * it is queried. Convert USD to CZK and vice versa. Start with the rate of - * 1USD = 16CZK and adjust it in favor of CZK by 0.01 CZK with every query. - * As soon as you reach 1USD = 15CZK adjust it by 0.01 CZK in favor of USD - * until you reach 1USD = 16CZK - * - * @return new instance of "online" USD and CZK convertor starting with rate 1USD = 16CZK - */ - public static Convertor createOnlineCZKUSDConvertor() { - // initial rate: 1USD = 16CZK - // 2nd query 1USD = 15.99CZK - // 3rd query 1USD = 15.98CZK - // until 1USD = 15.00CZK - // then 1USD = 15.01CZK - // then 1USD = 15.02CZK - // and so on and on up to 1USD = 16CZK - // and then another round to 15, etc. - return new OnlineConvertor(); - } - - public void testFewQueriesForOnlineConvertor() { - Convertor c = createOnlineCZKUSDConvertor(); - doFewQueriesForOnlineConvertor(c); - } - - static void doFewQueriesForOnlineConvertor(Convertor c) { - // convert $5 to CZK using c: - assertEquals("Result is 80 CZK", money(80,CZK), c.convert(money(5,USD), CZK)); - - // convert $8 to CZK using c: - assertEquals("Result is 127.92 CZK", money(127.92,CZK), c.convert(money(8,USD), CZK)); - - // convert $1 to CZK using c: - assertEquals("Result is 15.98 CZK", money(15.98,CZK), c.convert(money(1,USD), CZK)); - - // convert 15.97CZK to USD using c: - assertEquals("Result is 1 USD", money(1,USD), c.convert(money(15.97,CZK), USD)); - //assertEquals("Result is 1$"); - - } - - /** Join the convertors and show they behave sane. - */ - public void testOnlineConvertorComposition() throws Exception { - - Convertor c = Task2Test.merge( - createOnlineCZKUSDConvertor(), - Task1Test.createSKKtoCZK() - ); - - // convert 16CZK to SKK using c: - assertEquals("Result is 20 SKK", money(20,SKK), c.convert(money(16,CZK), SKK)); - - // convert 500SKK to CZK using c: - assertEquals("Result is 400 CZK", money(400,CZK), c.convert(money(500,SKK), CZK)); - - doFewQueriesForOnlineConvertor(c); - } -} diff -r 420baec87dc5 -r 6f4b6952f988 task4/solution02/test/org/apidesign/apifest08/test/Task4Test.java --- a/task4/solution02/test/org/apidesign/apifest08/test/Task4Test.java Fri Oct 17 17:40:14 2008 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,132 +0,0 @@ -package org.apidesign.apifest08.test; - -import java.util.Date; -import junit.framework.TestCase; -import org.apidesign.apifest08.currency.Convertor; - -/** The exchange rates are not always the same. They are changing. However - * as in order to predict the future, one needs to understand own past. That is - * why it is important to know the exchange rate as it was at any time during - * the past. - *

- * Today's quest is to enhance the convertor API to deal with dates. - * One shall be able to convert a currency at any date. Each currencies rate shall - * be associated with a range between two Date objects. In order - * to keep compatibility with old API that knew nothing about dates, the - * rates associated then are applicable "for eternity". Any use of existing - * convert methods that do not accept a Date argument, uses the current - * System.currentTimeMillis() as default date. - */ -public class Task4Test extends TestCase { - public Task4Test(String testName) { - super(testName); - } - - @Override - protected void setUp() throws Exception { - } - - @Override - protected void tearDown() throws Exception { - } - - // Backward compatibly enhance your existing API to support following - // usecases: - // - - /** Takes a convertor with any rates associated and creates new convertor - * that returns the same values as the old one for time between from to till. - * Otherwise it returns no results. This is just a helper method that - * shall call some real one in the API. - * - * @param old existing convertor - * @param from initial date (inclusive) - * @param till final date (exclusive) - * @return new convertor - */ - public static Convertor limitTo(Convertor old, Date from, Date till) { - return null; - } - - - public void testCompositionOfLimitedConvertors() throws Exception { - if (Boolean.getBoolean("ignore.failing")) { - // implement me! then delete this if statement - return; - } - - Date d1 = null; // 2008-10-01 0:00 GMT - Date d2 = null; // 2008-10-02 0:00 GMT - Date d3 = null; // 2008-10-03 0:00 GMT - - Convertor c = Task2Test.merge( - limitTo(Task1Test.createCZKtoUSD(), d1, d2), - limitTo(Task1Test.createSKKtoCZK(), d2, d3) - ); - - // convert $5 to CZK using c: - // cannot convert as no rate is applicable to current date - - // convert $8 to CZK using c: - // cannot convert as no rate is applicable to current date - - // convert 1003CZK to USD using c: - // cannot convert as no rate is applicable to current date - - // convert 16CZK using c: - // cannot convert as no rate is applicable to current date - - // convert 500SKK to CZK using c: - // cannot convert as no rate is applicable to current date - - // convert $5 to CZK using c at 2008-10-01 6:00 GMT: - // assertEquals("Result is 85 CZK"); - - // convert $8 to CZK using c at 2008-10-01 6:00 GMT: - // assertEquals("Result is 136 CZK"); - - // convert 1003CZK to USD using c at 2008-10-01 6:00 GMT: - // assertEquals("Result is 59 USD"); - - // convert 16CZK using c at 2008-10-02 9:00 GMT: - // assertEquals("Result is 20 SKK"); - - // convert 500SKK to CZK using c at 2008-10-02 9:00 GMT: - // assertEquals("Result is 400 CZK"); - - // convert 500SKK to CZK using c at 2008-10-01 6:00 GMT: - // cannot convert as no rate is applicable to current date - } - - /** Create convertor that understands two currencies, CZK and - * SKK. Make 100 SKK == 90 CZK. - * - * @return prepared convertor ready for converting SKK to CZK and CZK to SKK - */ - public static Convertor createSKKtoCZK2() { - return null; - } - - public void testDateConvetorWithTwoDifferentRates() throws Exception { - if (Boolean.getBoolean("ignore.failing")) { - // implement me! then delete this if statement - return; - } - - Date d1 = null; // 2008-10-01 0:00 GMT - Date d2 = null; // 2008-10-02 0:00 GMT - Date d3 = null; // 2008-10-03 0:00 GMT - - Convertor c = Task2Test.merge( - limitTo(createSKKtoCZK2(), d1, d2), - limitTo(Task1Test.createSKKtoCZK(), d2, d3) - ); - - // convert 500SKK to CZK using c at 2008-10-02 9:00 GMT: - // assertEquals("Result is 400 CZK"); - - // convert 500SKK to CZK using c at 2008-10-01 6:00 GMT: - // assertEquals("Result is 450 CZK"); - } - -}