@Test public void testManualScrollAndGestureScrollPlayNicelyTogether() { // Set width of view so that scrolling will return a correct value underTest.onMeasure(720, 1080, 0, 0); Calendar cal = Calendar.getInstance(); // Sun, 08 Feb 2015 00:00:00 GMT underTest.setCurrentDate(new Date(setTimeToMidnightAndGet(cal, 1423353600000L))); underTest.showNextMonth(); // Sun, 01 Mar 2015 00:00:00 GMT - expected assertEquals( new Date(setTimeToMidnightAndGet(cal, 1425168000000L)), underTest.getFirstDayOfCurrentMonth()); when(motionEvent.getAction()).thenReturn(MotionEvent.ACTION_UP); // Scroll enough to push calender to next month underTest.onScroll(motionEvent, motionEvent, 600, 0); underTest.onDraw(canvas); underTest.onTouch(motionEvent); // Wed, 01 Apr 2015 00:00:00 GMT assertEquals( new Date(setTimeToMidnightAndGet(cal, 1427842800000L)), underTest.getFirstDayOfCurrentMonth()); }
@Test public void testItReturnsFirstDayOfMonthAfterDateHasBeenSet() { // Sun, 01 Feb 2015 00:00:00 GMT Date expectedDate = new Date(1422748800000L); // Sun, 08 Feb 2015 00:00:00 GMT underTest.setCurrentDate(new Date(1423353600000L)); Date actualDate = underTest.getFirstDayOfCurrentMonth(); assertEquals(expectedDate, actualDate); }
@Test public void testItScrollsToPreviousMonth() { // Sun, 08 Feb 2015 00:00:00 GMT underTest.setCurrentDate(new Date(1423353600000L)); underTest.showPreviousMonth(); Date actualDate = underTest.getFirstDayOfCurrentMonth(); // Thu, 01 Jan 2015 00:00:00 GMT - expected assertEquals(new Date(1420070400000L), actualDate); }
@Test public void testItScrollsToNextMonth() { // Sun, 08 Feb 2015 00:00:00 GMT underTest.setCurrentDate(new Date(1423353600000L)); underTest.showNextMonth(); Date actualDate = underTest.getFirstDayOfCurrentMonth(); // Sun, 01 Mar 2015 00:00:00 GMT - expected assertEquals(new Date(1425168000000L), actualDate); }
@Test public void testListenerIsCalledOnMonthScroll() { // Sun, 01 Mar 2015 00:00:00 GMT Date expectedDateOnScroll = new Date(1425168000000L); when(motionEvent.getAction()).thenReturn(MotionEvent.ACTION_UP); // Set width of view so that scrolling will return a correct value underTest.onMeasure(720, 1080, 0, 0); // Sun, 08 Feb 2015 00:00:00 GMT underTest.setCurrentDate(new Date(1423353600000L)); // Scroll enough to push calender to next month underTest.onScroll(motionEvent, motionEvent, 600, 0); underTest.onDraw(canvas); underTest.onTouch(motionEvent); assertEquals(expectedDateOnScroll, underTest.getFirstDayOfCurrentMonth()); }