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