コード例 #1
0
  @Test
  public void testItDrawsDaysOnCalender() {
    // simulate Feb month
    underTest.setGrowProgress(
        1000); // set grow progress so that it simulates the calendar being open
    when(calendar.get(Calendar.DAY_OF_WEEK)).thenReturn(1);
    when(calendar.get(Calendar.MONTH)).thenReturn(1);
    when(calendar.getActualMaximum(Calendar.DAY_OF_MONTH)).thenReturn(28);

    underTest.drawMonth(canvas, calendar, 0);

    for (int dayColumn = 0, dayRow = 0; dayColumn <= 6; dayRow++) {
      if (dayRow == 7) {
        dayRow = 0;
        if (dayColumn <= 6) {
          dayColumn++;
        }
      }
      if (dayColumn == dayColumnNames.length) {
        break;
      }
      if (dayColumn == 0) {
        verify(canvas).drawText(eq(dayColumnNames[dayColumn]), anyInt(), anyInt(), eq(paint));
      } else {
        int day = ((dayRow - 1) * 7 + dayColumn + 1) - 6;
        if (day > 0 && day <= 28) {
          verify(canvas).drawText(eq(String.valueOf(day)), anyInt(), anyInt(), eq(paint));
        }
      }
    }
  }
コード例 #2
0
  @Test
  public void testItAbbreviatesDayNames() {
    // simulate Feb month
    when(calendar.get(Calendar.DAY_OF_WEEK)).thenReturn(1);
    when(calendar.get(Calendar.MONTH)).thenReturn(1);
    when(calendar.getActualMaximum(Calendar.DAY_OF_MONTH)).thenReturn(28);

    underTest.setGrowProgress(
        1000); // set grow progress so that it simulates the calendar being open
    underTest.setLocale(Locale.FRANCE);
    reset(canvas); // reset because invalidate is called
    underTest.setUseWeekDayAbbreviation(true);
    reset(canvas); // reset because invalidate is called
    underTest.drawMonth(canvas, calendar, 0);

    DateFormatSymbols dateFormatSymbols = new DateFormatSymbols(Locale.FRANCE);
    String[] dayNames = dateFormatSymbols.getShortWeekdays();

    InOrder inOrder = inOrder(canvas);
    inOrder.verify(canvas).drawText(eq(dayNames[2]), anyInt(), anyInt(), eq(paint));
    inOrder.verify(canvas).drawText(eq(dayNames[3]), anyInt(), anyInt(), eq(paint));
    inOrder.verify(canvas).drawText(eq(dayNames[4]), anyInt(), anyInt(), eq(paint));
    inOrder.verify(canvas).drawText(eq(dayNames[5]), anyInt(), anyInt(), eq(paint));
    inOrder.verify(canvas).drawText(eq(dayNames[6]), anyInt(), anyInt(), eq(paint));
    inOrder.verify(canvas).drawText(eq(dayNames[7]), anyInt(), anyInt(), eq(paint));
    inOrder.verify(canvas).drawText(eq(dayNames[1]), anyInt(), anyInt(), eq(paint));
  }
コード例 #3
0
  @Test
  public void testItDrawsFirstLetterOfEachDay() {
    // simulate Feb month
    when(calendar.get(Calendar.DAY_OF_WEEK)).thenReturn(1);
    when(calendar.get(Calendar.MONTH)).thenReturn(1);
    when(calendar.getActualMaximum(Calendar.DAY_OF_MONTH)).thenReturn(28);

    underTest.setGrowProgress(
        1000); // set grow progress so that it simulates the calendar being open
    underTest.drawMonth(canvas, calendar, 0);

    InOrder inOrder = inOrder(canvas);
    inOrder.verify(canvas).drawText(eq("M"), anyInt(), anyInt(), eq(paint));
    inOrder.verify(canvas).drawText(eq("T"), anyInt(), anyInt(), eq(paint));
    inOrder.verify(canvas).drawText(eq("W"), anyInt(), anyInt(), eq(paint));
    inOrder.verify(canvas).drawText(eq("T"), anyInt(), anyInt(), eq(paint));
    inOrder.verify(canvas).drawText(eq("F"), anyInt(), anyInt(), eq(paint));
    inOrder.verify(canvas).drawText(eq("S"), anyInt(), anyInt(), eq(paint));
    inOrder.verify(canvas).drawText(eq("S"), anyInt(), anyInt(), eq(paint));
  }
コード例 #4
0
  @Test
  public void testItDrawsSundayAsFirstDay() {
    // simulate Feb month
    when(calendar.get(Calendar.DAY_OF_WEEK)).thenReturn(1);
    when(calendar.get(Calendar.MONTH)).thenReturn(1);
    when(calendar.getActualMaximum(Calendar.DAY_OF_MONTH)).thenReturn(28);

    underTest.setGrowProgress(
        1000); // set grow progress so that it simulates the calendar being open
    underTest.setShouldShowMondayAsFirstDay(false);
    underTest.setUseWeekDayAbbreviation(true);
    underTest.drawMonth(canvas, calendar, 0);

    InOrder inOrder = inOrder(canvas);
    inOrder.verify(canvas).drawText(eq("Sun"), anyInt(), anyInt(), eq(paint));
    inOrder.verify(canvas).drawText(eq("Mon"), anyInt(), anyInt(), eq(paint));
    inOrder.verify(canvas).drawText(eq("Tue"), anyInt(), anyInt(), eq(paint));
    inOrder.verify(canvas).drawText(eq("Wed"), anyInt(), anyInt(), eq(paint));
    inOrder.verify(canvas).drawText(eq("Thu"), anyInt(), anyInt(), eq(paint));
    inOrder.verify(canvas).drawText(eq("Fri"), anyInt(), anyInt(), eq(paint));
    inOrder.verify(canvas).drawText(eq("Sat"), anyInt(), anyInt(), eq(paint));
  }
コード例 #5
0
  @Test
  public void testItSetsDayColumns() {
    // simulate Feb month
    when(calendar.get(Calendar.DAY_OF_WEEK)).thenReturn(1);
    when(calendar.get(Calendar.MONTH)).thenReturn(1);
    when(calendar.getActualMaximum(Calendar.DAY_OF_MONTH)).thenReturn(28);

    String[] dayNames = {"Mon", "Tue", "Wed", "Thur", "Fri", "Sat", "Sun"};
    underTest.setGrowProgress(
        1000); // set grow progress so that it simulates the calendar being open
    underTest.setDayColumnNames(dayNames);
    underTest.drawMonth(canvas, calendar, 0);

    InOrder inOrder = inOrder(canvas);
    inOrder.verify(canvas).drawText(eq("Mon"), anyInt(), anyInt(), eq(paint));
    inOrder.verify(canvas).drawText(eq("Tue"), anyInt(), anyInt(), eq(paint));
    inOrder.verify(canvas).drawText(eq("Wed"), anyInt(), anyInt(), eq(paint));
    inOrder.verify(canvas).drawText(eq("Thur"), anyInt(), anyInt(), eq(paint));
    inOrder.verify(canvas).drawText(eq("Fri"), anyInt(), anyInt(), eq(paint));
    inOrder.verify(canvas).drawText(eq("Sat"), anyInt(), anyInt(), eq(paint));
    inOrder.verify(canvas).drawText(eq("Sun"), anyInt(), anyInt(), eq(paint));
  }