FileDocCategorySizeDatePackage
DayOfMonthCursorTest.javaAPI DocAndroid 1.5 API5480Wed May 06 22:42:02 BST 2009android.util

DayOfMonthCursorTest

public class DayOfMonthCursorTest extends TestCase
Unit tests for {@link DayOfMonthCursor}.

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 voidtestMonthRows()

        DayOfMonthCursor mc = new DayOfMonthCursor(2007,
                Calendar.SEPTEMBER, 11, Calendar.SUNDAY);

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

        DayOfMonthCursor mc = new DayOfMonthCursor(2007,
                Calendar.SEPTEMBER, 23, Calendar.SUNDAY);

        assertEquals(Calendar.SEPTEMBER, mc.getMonth());
        assertEquals(23, mc.getSelectedDayOfMonth());
        assertEquals(4, mc.getSelectedRow());
        assertEquals(0, mc.getSelectedColumn());

        // down, same month
        assertFalse(mc.down());
        assertEquals(30, mc.getSelectedDayOfMonth());
        assertEquals(5, mc.getSelectedRow());
        assertEquals(0, mc.getSelectedColumn());

        // down, next month
        assertTrue(mc.down());
        assertEquals(Calendar.OCTOBER, mc.getMonth());
        assertEquals(7, mc.getSelectedDayOfMonth());
        assertEquals(1, mc.getSelectedRow());
        assertEquals(0, mc.getSelectedColumn());
    
public voidtestMoveLeft()

        DayOfMonthCursor mc = new DayOfMonthCursor(2007,
                Calendar.SEPTEMBER, 3, Calendar.SUNDAY);

        assertEquals(Calendar.SEPTEMBER, mc.getMonth());
        assertEquals(3, mc.getSelectedDayOfMonth());
        assertEquals(1, mc.getSelectedRow());
        assertEquals(1, mc.getSelectedColumn());

        // move left, still same row
        assertFalse(mc.left());
        assertEquals(2, mc.getSelectedDayOfMonth());
        assertEquals(1, mc.getSelectedRow());
        assertEquals(0, mc.getSelectedColumn());

        // wrap over to previous column, same month
        assertFalse(mc.left());
        assertEquals(1, mc.getSelectedDayOfMonth());
        assertEquals(0, mc.getSelectedRow());
        assertEquals(6, mc.getSelectedColumn());

        // wrap to previous month
        assertTrue(mc.left());
        assertEquals(Calendar.AUGUST, mc.getMonth());
        assertEquals(31, mc.getSelectedDayOfMonth());
        assertEquals(4, mc.getSelectedRow());
        assertEquals(5, mc.getSelectedColumn());
    
public voidtestMoveRight()

        DayOfMonthCursor mc = new DayOfMonthCursor(2007,
                Calendar.SEPTEMBER, 28, Calendar.SUNDAY);

        assertEquals(Calendar.SEPTEMBER, mc.getMonth());
        assertEquals(28, mc.getSelectedDayOfMonth());
        assertEquals(4, mc.getSelectedRow());
        assertEquals(5, mc.getSelectedColumn());

        // same row
        assertFalse(mc.right());
        assertEquals(29, mc.getSelectedDayOfMonth());
        assertEquals(4, mc.getSelectedRow());
        assertEquals(6, mc.getSelectedColumn());

        // wrap to next column, same month
        assertFalse(mc.right());
        assertEquals(30, mc.getSelectedDayOfMonth());
        assertEquals(5, mc.getSelectedRow());
        assertEquals(0, mc.getSelectedColumn());

        // next month
        assertTrue(mc.right());
        assertEquals(Calendar.OCTOBER, mc.getMonth());
        assertEquals(1, mc.getSelectedDayOfMonth());
        assertEquals(0, mc.getSelectedRow());
        assertEquals(1, mc.getSelectedColumn());
    
public voidtestMoveUp()

        DayOfMonthCursor mc = new DayOfMonthCursor(2007,
                Calendar.SEPTEMBER, 13, Calendar.SUNDAY);

        assertEquals(Calendar.SEPTEMBER, mc.getMonth());
        assertEquals(13, mc.getSelectedDayOfMonth());
        assertEquals(2, mc.getSelectedRow());
        assertEquals(4, mc.getSelectedColumn());

        // up, same month
        assertFalse(mc.up());
        assertEquals(6, mc.getSelectedDayOfMonth());
        assertEquals(1, mc.getSelectedRow());
        assertEquals(4, mc.getSelectedColumn());

        // up, flips back
        assertTrue(mc.up());
        assertEquals(Calendar.AUGUST, mc.getMonth());
        assertEquals(30, mc.getSelectedDayOfMonth());
        assertEquals(4, mc.getSelectedRow());
        assertEquals(4, mc.getSelectedColumn());