Android Open Source - DisposableIncome-OldJava Withdraw Date Comparer 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  ww w . java2 s.c  om
import android.util.Log;
import junit.framework.TestCase;

import java.util.Calendar;

import uk.co.wilka.disposableincome.Cash;
import uk.co.wilka.disposableincome.CashWithdraw;
import uk.co.wilka.disposableincome.IProvideCalendar;
import uk.co.wilka.disposableincome.WithdrawDateComparer;
import uk.co.wilka.disposableincome.WithdrawType;

public class WithdrawDateComparerTests extends TestCase {

    public void test_isAfterThisMonth_returnsFalseForDatesInThePast() {
        WithdrawDateComparer dateComparer = createWithdrawDateComparer();

        assertEquals(false, dateComparer.isAfterThisMonth(withdrawalFor(2002, 5, 3)));
        assertEquals(false, dateComparer.isAfterThisMonth(withdrawalFor(2006, 11, 25)));
        assertEquals(false, dateComparer.isAfterThisMonth(withdrawalFor(2012, 2, 1)));
        assertEquals(false, dateComparer.isAfterThisMonth(withdrawalFor(2012, 8, 30)));
    }

    public void test_isAfterThisMonth_returnsFalseForThisMonth() {
        WithdrawDateComparer dateComparer = createWithdrawDateComparer();

        assertEquals(false, dateComparer.isAfterThisMonth(withdrawalFor(2012, 9, 1)));
        assertEquals(false, dateComparer.isAfterThisMonth(withdrawalFor(2012, 9, 30)));
        assertEquals(false, dateComparer.isAfterThisMonth(withdrawalFor(2012, 9, 31)));
    }

    public void test_isAfterThisMonth_returnsTrueForNextMonthOnwards() {
        WithdrawDateComparer dateComparer = createWithdrawDateComparer();

        assertEquals(true, dateComparer.isAfterThisMonth(withdrawalFor(2012, 10, 1)));
        assertEquals(true, dateComparer.isAfterThisMonth(withdrawalFor(2012, 10, 30)));
        assertEquals(true, dateComparer.isAfterThisMonth(withdrawalFor(2013, 8, 30)));
    }

    public void test_isBeforeThisMonth_returnsTruePreviousMonthAndEarlier() {
        WithdrawDateComparer dateComparer = createWithdrawDateComparer();

        assertTrue(dateComparer.isBeforeThisMonth(withdrawalFor(2001, 10, 1)));
        assertTrue(dateComparer.isBeforeThisMonth(withdrawalFor(2012, 3, 1)));
        assertTrue(dateComparer.isBeforeThisMonth(withdrawalFor(2012, 8, 30)));
    }

    public void test_isBeforeThisMonth_returnsFalseForThisMonth() {
        WithdrawDateComparer dateComparer = createWithdrawDateComparer();

        assertFalse(dateComparer.isBeforeThisMonth(withdrawalFor(2012, 9, 1)));
        assertFalse(dateComparer.isBeforeThisMonth(withdrawalFor(2012, 9, 14)));
        assertFalse(dateComparer.isBeforeThisMonth(withdrawalFor(2012, 9, 30)));
    }

    public void test_isBeforeThisMonth_returnsFalseForNextMonthAndOnwards() {
        WithdrawDateComparer dateComparer = createWithdrawDateComparer();

        assertEquals(false, dateComparer.isBeforeThisMonth(withdrawalFor(2012, 10, 1)));
        assertEquals(false, dateComparer.isBeforeThisMonth(withdrawalFor(2012, 10, 14)));
        assertEquals(false, dateComparer.isBeforeThisMonth(withdrawalFor(2016, 3, 0)));
    }

    public void test_isThisMonth_returnsTrueOnlyForItemsWithMonth() {
        WithdrawDateComparer dateComparer = createWithdrawDateComparer();

        assertFalse(dateComparer.isThisMonth(withdrawalFor(2012, 8, 1)));
        assertFalse(dateComparer.isThisMonth(withdrawalFor(2012, 8, 30)));

        assertTrue(dateComparer.isThisMonth(withdrawalFor(2012, 9, 1)));
        assertTrue(dateComparer.isThisMonth(withdrawalFor(2012, 9, 5)));
        assertTrue(dateComparer.isThisMonth(withdrawalFor(2012, 9, 30)));

        assertFalse(dateComparer.isThisMonth(withdrawalFor(2012, 10, 14)));
        assertFalse(dateComparer.isThisMonth(withdrawalFor(2016, 3, 0)));
    }


    public void test_getDaysUntilMonthEnd_returnsCorrectNumberOfDays() {
        final int february = 1;
        final int october = 9;
        final int november = 10;

        // We start on the first day, so that means there's max_days - 1 left in the month
        assertEquals(28, createWithdrawDateComparerForFirstOf(february).getDaysUntilMonthEnd());
        assertEquals(30, createWithdrawDateComparerForFirstOf(october).getDaysUntilMonthEnd());
        assertEquals(29, createWithdrawDateComparerForFirstOf(november).getDaysUntilMonthEnd());

        assertEquals(9, createWithdrawDateComparerForTwentiethOf(february).getDaysUntilMonthEnd());
        assertEquals(11, createWithdrawDateComparerForTwentiethOf(october).getDaysUntilMonthEnd());
        assertEquals(10, createWithdrawDateComparerForTwentiethOf(november).getDaysUntilMonthEnd());
    }

    private CashWithdraw withdrawalFor(int year, int month, int day) {
        Calendar calendar = Calendar.getInstance();
        calendar.set(year, month, day, 1, 1, 1);

        return new CashWithdraw(calendar.getTime(), Cash.fromPounds(10), WithdrawType.Predicted, "");
    }

    private WithdrawDateComparer createWithdrawDateComparer() {
        IProvideCalendar provider = new FakeCalendarProvider(2012, 9, 24, 17, 54, 33);

        return new WithdrawDateComparer(provider);
    }

    private WithdrawDateComparer createWithdrawDateComparerForFirstOf(int month) {
        IProvideCalendar provider = new FakeCalendarProvider(2012, month, 1, 17, 54, 33);

        return new WithdrawDateComparer(provider);
    }

    private WithdrawDateComparer createWithdrawDateComparerForTwentiethOf(int month) {
        IProvideCalendar provider = new FakeCalendarProvider(2012, month, 20, 17, 54, 33);

        return new WithdrawDateComparer(provider);
    }
}




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