CalendarUtil { public static long getNextMonthTimeInMillis(long currTimeInMillis) { calendar.setTimeInMillis(currTimeInMillis); int nextMonth = (calendar.get(Calendar.MONTH) + 1) % 12; calendar.set(Calendar.MONTH, nextMonth); if (nextMonth == 0) { calendar.set(Calendar.YEAR, calendar.get(Calendar.YEAR) + 1); } return calendar.getTimeInMillis(); }  static long getNextMonthTimeInMillis(long currTimeInMillis); static String convertDateToString(Context context, Calendar calendar); static String convertDateToString(Context context, long timeInMillis); static String convertTimeToString(Context context, Calendar calendar); static String convertTimeToString(Context context, long timeInMillis);  }
@Test public void testGetNextMonthTimeInMillis() { Calendar calendar = new GregorianCalendar(2015, 11, 21); calendar.setTimeInMillis(CalendarUtil.getNextMonthTimeInMillis(calendar.getTimeInMillis())); assertEquals(0, calendar.get(Calendar.MONTH)); assertEquals(2016, calendar.get(Calendar.YEAR)); for (int expectedMonth = 1; expectedMonth < 12; expectedMonth++) { int dayBeforeChange = calendar.get(Calendar.DAY_OF_MONTH); int hourBeforeChange = calendar.get(Calendar.HOUR_OF_DAY); int minuteBeforeChange = calendar.get(Calendar.MINUTE); int yearBeforeChange = calendar.get(Calendar.YEAR); calendar.setTimeInMillis(CalendarUtil.getNextMonthTimeInMillis(calendar.getTimeInMillis())); assertEquals(calendar.get(Calendar.MONTH), expectedMonth); assertEquals(dayBeforeChange, calendar.get(Calendar.DAY_OF_MONTH)); assertEquals(hourBeforeChange, calendar.get(Calendar.HOUR_OF_DAY)); assertEquals(minuteBeforeChange, calendar.get(Calendar.MINUTE)); assertEquals(yearBeforeChange, calendar.get(Calendar.YEAR)); } }