Back to project page DisposableIncome-OldJava.
The source code is released under:
MIT License
If you think the Android project DisposableIncome-OldJava listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.
package uk.co.wilka.disposableincome.test; /*from w w w . j av a 2 s . c o m*/ import android.util.Log; import junit.framework.TestCase; import java.text.SimpleDateFormat; import java.util.ArrayList; import java.util.Calendar; import java.util.Date; import uk.co.wilka.disposableincome.Cash; import uk.co.wilka.disposableincome.CashWithdraw; import uk.co.wilka.disposableincome.WithdrawDateComparer; import uk.co.wilka.disposableincome.WithdrawType; import uk.co.wilka.disposableincome.WithdrawalForMonthCalculator; public class WithdrawalForMonthCalculatorTests extends TestCase { public static final int MARCH = 2; private ArrayList<CashWithdraw> withdrawals; private WithdrawDateComparer dateComparer; @Override protected void setUp() throws Exception { super.setUp(); dateComparer = new WithdrawDateComparer(new uk.co.wilka.disposableincome.test.FakeCalendarProvider(1979, MARCH, 1, 5, 5, 5)); withdrawals = new ArrayList<CashWithdraw>(); } public void test_sumsActualAndPredictedWithdrawsCorrectlyForSameMonth() { withdrawals.add(new CashWithdraw(createDate(1979, MARCH, 5), Cash.fromPounds(10), WithdrawType.Actual, "")); withdrawals.add(new CashWithdraw(createDate(1979, MARCH, 5),Cash.fromPounds(20), WithdrawType.Actual, "")); withdrawals.add(new CashWithdraw(createDate(1979, MARCH, 20),Cash.fromPounds(55), WithdrawType.Predicted, "")); WithdrawalForMonthCalculator calculator = new WithdrawalForMonthCalculator(dateComparer, withdrawals); assertEquals(30, calculator.getTotalActual().getPounds()); assertEquals(55, calculator.getTotalPredicted().getPounds()); } public void test_sumsActualAndPredictedWithdrawsIgnoringValuesForPreviousMonth() { withdrawals.add(new CashWithdraw(createDate(1979, MARCH-1, 5), Cash.fromPounds(66), WithdrawType.Actual, "Not this month")); withdrawals.add(new CashWithdraw(createDate(1979, MARCH-1, 5), Cash.fromPounds(66), WithdrawType.Predicted, "Not this month")); withdrawals.add(new CashWithdraw(createDate(1979, MARCH, 5), Cash.fromPounds(10), WithdrawType.Actual, "")); withdrawals.add(new CashWithdraw(createDate(1979, MARCH, 5),Cash.fromPounds(20), WithdrawType.Actual, "")); withdrawals.add(new CashWithdraw(createDate(1979, MARCH, 20),Cash.fromPounds(55), WithdrawType.Predicted, "")); WithdrawalForMonthCalculator calculator = new WithdrawalForMonthCalculator(dateComparer, withdrawals); assertEquals(30, calculator.getTotalActual().getPounds()); assertEquals(55, calculator.getTotalPredicted().getPounds()); } public void test_sumsActualAndPredictedWithdrawsIgnoringValuesForNextMonth() { withdrawals.add(new CashWithdraw(createDate(1979, MARCH+1, 5), Cash.fromPounds(666), WithdrawType.Actual, "Not this month")); withdrawals.add(new CashWithdraw(createDate(1979, MARCH+1, 5), Cash.fromPounds(666), WithdrawType.Predicted, "Not this month")); withdrawals.add(new CashWithdraw(createDate(1979, MARCH, 5), Cash.fromPounds(10), WithdrawType.Actual, "")); withdrawals.add(new CashWithdraw(createDate(1979, MARCH, 5),Cash.fromPounds(20), WithdrawType.Actual, "")); withdrawals.add(new CashWithdraw(createDate(1979, MARCH, 20),Cash.fromPounds(55), WithdrawType.Predicted, "")); WithdrawalForMonthCalculator calculator = new WithdrawalForMonthCalculator(dateComparer, withdrawals); assertEquals(30, calculator.getTotalActual().getPounds()); assertEquals(55, calculator.getTotalPredicted().getPounds()); } private Date createDate(int year, int month, int day) { Calendar cal = Calendar.getInstance(); cal.set(year, month, day); return cal.getTime(); } }