diff -r 14e78f48ac2b -r 58ec6da75f6f task4/solution04/test/org/apidesign/apifest08/test/TestExchangeRateFinder.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/task4/solution04/test/org/apidesign/apifest08/test/TestExchangeRateFinder.java Sat Oct 11 23:38:46 2008 +0200 @@ -0,0 +1,61 @@ +package org.apidesign.apifest08.test; + + +import java.math.BigDecimal; +import java.util.Currency; +import org.apidesign.apifest08.currency.ExchangeRate; +import org.apidesign.apifest08.currency.ExchangeRateFinder; + + +class TestExchangeRateFinder + implements ExchangeRateFinder +{ + private final BigDecimal min; + private final BigDecimal max; + private final BigDecimal stepUp; + private final BigDecimal stepDown; + private BigDecimal step; + private BigDecimal rate; + private boolean firstCall; + + TestExchangeRateFinder(final BigDecimal mn, + final BigDecimal mx, + final BigDecimal start, + final BigDecimal up, + final BigDecimal down) + { + min = mn; + max = mx; + rate = start; + stepUp = up; + stepDown = down; + firstCall = true; + } + + public ExchangeRate findRate(Currency a, Currency b) + { + final ExchangeRate value; + + if(rate.equals(max)) + { + step = stepDown; + } + else if(rate.equals(min)) + { + step = stepUp; + } + + value = new ExchangeRate(a, b, BigDecimal.ONE, rate); + + if(firstCall) + { + firstCall = false; + } + else + { + rate = rate.add(step); + } + + return (value); + } +}