Android Open Source - DisposableIncome-OldJava Withdrawal For Month Calculator Tests






From Project

Back to project page DisposableIncome-OldJava.

License

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.

Java Source Code

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();
    }
}




Java Source Code List

uk.co.wilka.disposableincome.CalendarAccess.java
uk.co.wilka.disposableincome.CalendarProvider.java
uk.co.wilka.disposableincome.CashWithdraw.java
uk.co.wilka.disposableincome.CashWithdrawalDetailsActivity.java
uk.co.wilka.disposableincome.Cash.java
uk.co.wilka.disposableincome.DatabaseHelper.java
uk.co.wilka.disposableincome.IAccessData.java
uk.co.wilka.disposableincome.IProvideCalendar.java
uk.co.wilka.disposableincome.MainActivity.java
uk.co.wilka.disposableincome.PlusOneMonthCalendarProvider.java
uk.co.wilka.disposableincome.WithdrawDateComparer.java
uk.co.wilka.disposableincome.WithdrawType.java
uk.co.wilka.disposableincome.WithdrawalForMonthCalculator.java
uk.co.wilka.disposableincome.test.CashTest.java
uk.co.wilka.disposableincome.test.CashWithdrawTest.java
uk.co.wilka.disposableincome.test.FakeCalendarProvider.java
uk.co.wilka.disposableincome.test.PlusOneMonthCalendarProviderTests.java
uk.co.wilka.disposableincome.test.WithdrawDateComparerTests.java
uk.co.wilka.disposableincome.test.WithdrawalForMonthCalculatorTests.java