Program: 142027
Project: 142027
Buggy source:
/** 
 * Test the auto-update pending calculations, which have several edge cases.
 */
@Test public void testAutoUpdateCalc(){
  long checkedThreeDaysAgo=DateTime.now().minusDays(3).getMillis();
  Assert.assertTrue(CommCareApplication.instance().isTimeForAutoUpdateCheck(checkedThreeDaysAgo,CommCarePreferences.FREQUENCY_DAILY));
  long checkedThreeHoursAgo=DateTime.now().minusHours(3).getMillis();
  if (isSameDayAsNow(checkedThreeHoursAgo)) {
    Assert.assertFalse(CommCareApplication.instance().isTimeForAutoUpdateCheck(checkedThreeHoursAgo,CommCarePreferences.FREQUENCY_DAILY));
  }
 else {
    Assert.assertTrue(CommCareApplication.instance().isTimeForAutoUpdateCheck(checkedThreeHoursAgo,CommCarePreferences.FREQUENCY_DAILY));
  }
  DateTime yesterdayNearMidnight=new DateTime();
  yesterdayNearMidnight=yesterdayNearMidnight.minusDays(1).withTimeAtStartOfDay().plusHours(23);
  DateTime now=new DateTime();
  long diff=yesterdayNearMidnight.minus(now.getMillis()).getMillis();
  Assert.assertTrue(diff < DateUtils.DAY_IN_MILLIS);
  Assert.assertTrue(CommCareApplication.instance().isTimeForAutoUpdateCheck(yesterdayNearMidnight.getMillis(),CommCarePreferences.FREQUENCY_DAILY));
  long hoursInTheFuture=DateTime.now().plusHours(2).getMillis();
  Assert.assertFalse(CommCareApplication.instance().isTimeForAutoUpdateCheck(hoursInTheFuture,CommCarePreferences.FREQUENCY_DAILY));
  long daysLater=DateTime.now().plusDays(2).getMillis();
  Assert.assertTrue(CommCareApplication.instance().isTimeForAutoUpdateCheck(daysLater,CommCarePreferences.FREQUENCY_DAILY));
  long weekLater=DateTime.now().plusWeeks(1).getMillis();
  Assert.assertTrue(CommCareApplication.instance().isTimeForAutoUpdateCheck(weekLater,CommCarePreferences.FREQUENCY_DAILY));
}

Fixed version (ground truth):
/** 
 * Test the auto-update pending calculations, which have several edge cases.
 */
@Test public void testAutoUpdateCalc(){
  long checkedThreeDaysAgo=DateTime.now().minusDays(3).getMillis();
  Assert.assertTrue(PendingCalcs.isTimeForAutoUpdateCheck(checkedThreeDaysAgo,CommCarePreferences.FREQUENCY_DAILY));
  long checkedThreeHoursAgo=DateTime.now().minusHours(3).getMillis();
  if (isSameDayAsNow(checkedThreeHoursAgo)) {
    Assert.assertFalse(PendingCalcs.isTimeForAutoUpdateCheck(checkedThreeHoursAgo,CommCarePreferences.FREQUENCY_DAILY));
  }
 else {
    Assert.assertTrue(PendingCalcs.isTimeForAutoUpdateCheck(checkedThreeHoursAgo,CommCarePreferences.FREQUENCY_DAILY));
  }
  DateTime yesterdayNearMidnight=new DateTime();
  yesterdayNearMidnight=yesterdayNearMidnight.minusDays(1).withTimeAtStartOfDay().plusHours(23);
  DateTime now=new DateTime();
  long diff=yesterdayNearMidnight.minus(now.getMillis()).getMillis();
  Assert.assertTrue(diff < DateUtils.DAY_IN_MILLIS);
  Assert.assertTrue(PendingCalcs.isTimeForAutoUpdateCheck(yesterdayNearMidnight.getMillis(),CommCarePreferences.FREQUENCY_DAILY));
  long hoursInTheFuture=DateTime.now().plusHours(2).getMillis();
  Assert.assertFalse(PendingCalcs.isTimeForAutoUpdateCheck(hoursInTheFuture,CommCarePreferences.FREQUENCY_DAILY));
  long daysLater=DateTime.now().plusDays(2).getMillis();
  Assert.assertTrue(PendingCalcs.isTimeForAutoUpdateCheck(daysLater,CommCarePreferences.FREQUENCY_DAILY));
  long weekLater=DateTime.now().plusWeeks(1).getMillis();
  Assert.assertTrue(PendingCalcs.isTimeForAutoUpdateCheck(weekLater,CommCarePreferences.FREQUENCY_DAILY));
}