FileDocCategorySizeDatePackage
MonthDisplayHelperTest.javaAPI DocAndroid 5.1 API6980Thu Mar 12 22:22:12 GMT 2015android.util

MonthDisplayHelperTest

public class MonthDisplayHelperTest extends TestCase
Unit tests for {@link MonthDisplayHelper}.

Fields Summary
Constructors Summary
Methods Summary
private voidassertArraysEqual(int[] expected, int[] actual)

        assertEquals("array length", expected.length, actual.length);
        for (int i = 0; i < expected.length; i++) {
            assertEquals("index " + i,
                    expected[i], actual[i]);
        }
    
public voidtestFirstDayOfMonth()


        assertEquals("august 2007",
                Calendar.WEDNESDAY,
                new MonthDisplayHelper(2007, Calendar.AUGUST).getFirstDayOfMonth());

        assertEquals("september, 2007",
                Calendar.SATURDAY,
                new MonthDisplayHelper(2007, Calendar.SEPTEMBER).getFirstDayOfMonth());
    
public voidtestGetColumnOf()

        MonthDisplayHelper helper = new MonthDisplayHelper(2007,
                Calendar.AUGUST, Calendar.SUNDAY);

        assertEquals(3, helper.getColumnOf(1));
        assertEquals(4, helper.getColumnOf(9));
        assertEquals(5, helper.getColumnOf(17));
        assertEquals(6, helper.getColumnOf(25));
        assertEquals(0, helper.getColumnOf(26));
    
public voidtestGetDayAt()

        MonthDisplayHelper helper = new MonthDisplayHelper(2007,
                Calendar.SEPTEMBER, Calendar.SUNDAY);

        assertEquals(26, helper.getDayAt(0, 0));
        assertEquals(1, helper.getDayAt(0, 6));
        assertEquals(17, helper.getDayAt(3, 1));
        assertEquals(2, helper.getDayAt(5, 2));
    
public voidtestGetRowOf()

        MonthDisplayHelper helper = new MonthDisplayHelper(2007,
                Calendar.AUGUST, Calendar.SUNDAY);

        assertEquals(0, helper.getRowOf(2));
        assertEquals(0, helper.getRowOf(4));
        assertEquals(2, helper.getRowOf(12));
        assertEquals(2, helper.getRowOf(18));
        assertEquals(3, helper.getRowOf(19));
    
public voidtestMonthRows()

        MonthDisplayHelper helper = new MonthDisplayHelper(2007, Calendar.SEPTEMBER);

        assertArraysEqual(new int[]{26, 27, 28, 29, 30, 31, 1},
                helper.getDigitsForRow(0));
        assertArraysEqual(new int[]{2, 3, 4, 5, 6, 7, 8},
                helper.getDigitsForRow(1));
        assertArraysEqual(new int[]{30, 1, 2, 3, 4, 5, 6},
                helper.getDigitsForRow(5));

    
public voidtestMonthRowsWeekStartsMonday()

        MonthDisplayHelper helper = new MonthDisplayHelper(2007,
                Calendar.SEPTEMBER, Calendar.MONDAY);

        assertArraysEqual(new int[]{27, 28, 29, 30, 31, 1, 2},
                helper.getDigitsForRow(0));
        assertArraysEqual(new int[]{3, 4, 5, 6, 7, 8, 9},
                helper.getDigitsForRow(1));
        assertArraysEqual(new int[]{24, 25, 26, 27, 28, 29, 30},
                helper.getDigitsForRow(4));
        assertArraysEqual(new int[]{1, 2, 3, 4, 5, 6, 7},
                helper.getDigitsForRow(5));
    
public voidtestMonthRowsWeekStartsSaturday()

        MonthDisplayHelper helper = new MonthDisplayHelper(2007,
                Calendar.SEPTEMBER, Calendar.SATURDAY);

        assertArraysEqual(new int[]{1, 2, 3, 4, 5, 6, 7},
                helper.getDigitsForRow(0));
        assertArraysEqual(new int[]{8, 9, 10, 11, 12, 13, 14},
                helper.getDigitsForRow(1));
        assertArraysEqual(new int[]{29, 30, 1, 2, 3, 4, 5},
                helper.getDigitsForRow(4));


        helper = new MonthDisplayHelper(2007,
                Calendar.AUGUST, Calendar.SATURDAY);

        assertArraysEqual(new int[]{28, 29, 30, 31, 1, 2, 3},
                helper.getDigitsForRow(0));
        assertArraysEqual(new int[]{4, 5, 6, 7, 8, 9, 10},
                helper.getDigitsForRow(1));
        assertArraysEqual(new int[]{25, 26, 27, 28, 29, 30, 31},
                helper.getDigitsForRow(4));
    
public voidtestNextMonth()

        MonthDisplayHelper helper = new MonthDisplayHelper(2007,
                Calendar.AUGUST, Calendar.SUNDAY);

        assertArraysEqual(new int[]{29, 30, 31, 1, 2, 3, 4},
                helper.getDigitsForRow(0));

        helper.nextMonth();

        assertEquals(Calendar.SEPTEMBER, helper.getMonth());
        assertArraysEqual(new int[]{26, 27, 28, 29, 30, 31, 1},
                helper.getDigitsForRow(0));
    
public voidtestNumberOfDaysInCurrentMonth()

        assertEquals(30,
                new MonthDisplayHelper(2007, Calendar.SEPTEMBER).getNumberOfDaysInMonth());
    
public voidtestPrevMonth()

        MonthDisplayHelper helper = new MonthDisplayHelper(2007,
                Calendar.SEPTEMBER, Calendar.SUNDAY);

        assertArraysEqual(new int[]{26, 27, 28, 29, 30, 31, 1},
                helper.getDigitsForRow(0));

        helper.previousMonth();

        assertEquals(Calendar.AUGUST, helper.getMonth());
        assertArraysEqual(new int[]{29, 30, 31, 1, 2, 3, 4},
                helper.getDigitsForRow(0));
    
public voidtestPrevMonthRollOver()

        MonthDisplayHelper helper = new MonthDisplayHelper(2007,
                Calendar.JANUARY);

        helper.previousMonth();

        assertEquals(2006, helper.getYear());
        assertEquals(Calendar.DECEMBER, helper.getMonth());
    
public voidtestWithinCurrentMonth()

        MonthDisplayHelper helper = new MonthDisplayHelper(2007,
                Calendar.SEPTEMBER, Calendar.SUNDAY);

        // out of bounds
        assertFalse(helper.isWithinCurrentMonth(-1, 3));
        assertFalse(helper.isWithinCurrentMonth(6, 3));
        assertFalse(helper.isWithinCurrentMonth(2, -1));
        assertFalse(helper.isWithinCurrentMonth(2, 7));

        // last day of previous month
        assertFalse(helper.isWithinCurrentMonth(0, 5));

        // first day of next month
        assertFalse(helper.isWithinCurrentMonth(5, 1));

        // first day in month
        assertTrue(helper.isWithinCurrentMonth(0, 6));

        // last day in month
        assertTrue(helper.isWithinCurrentMonth(5, 0));