Program: 25695
Project: 25695
Buggy source:
@Test public void getScheduledActivityHistoryV2() throws Exception {
  DateTimeZone MSK=DateTimeZone.forOffsetHours(3);
  DateTime endsOn=DateTime.now(MSK).plus(Period.parse("String_Node_Str"));
  DateTime startDateTime=DateTime.now().minusDays(20);
  DateTime endDateTime=DateTime.now().plusDays(20);
  ScheduleContext context=new ScheduleContext.Builder().withHealthCode(healthCode).withStudyIdentifier(TEST_STUDY_IDENTIFIER).withClientInfo(ClientInfo.UNKNOWN_CLIENT).withInitialTimeZone(MSK).withEndsOn(endsOn).withEvents(eventMap()).build();
  Schedule schedule=plan.getStrategy().getScheduleForUser(plan,context);
  List<ScheduledActivity> activitiesToSchedule=schedule.getScheduler().getScheduledActivities(plan,context);
  activityDao.saveActivities(activitiesToSchedule);
  String activityGuid=extractActivityGuid();
  ForwardCursorPagedResourceList<ScheduledActivity> history=activityDao.getActivityHistoryV2(healthCode,activityGuid,startDateTime,endDateTime,null,10);
  assertEquals(10,history.getItems().size());
  Set<String> allTaskGuids=history.getItems().stream().map(ScheduledActivity::getGuid).collect(toSet());
  history=activityDao.getActivityHistoryV2(healthCode,activityGuid,startDateTime,endDateTime,history.getOffsetBy(),10);
  assertEquals(10,history.getItems().size());
  allTaskGuids.addAll(history.getItems().stream().map(ScheduledActivity::getGuid).collect(toSet()));
  assertEquals(20,allTaskGuids.size());
  history=activityDao.getActivityHistoryV2(healthCode,activityGuid,startDateTime,startDateTime,null,10);
  assertEquals(0,history.getItems().size());
  assertNull(history.getOffsetBy());
}

Fixed version (ground truth):
@Test public void getScheduledActivityHistoryV2() throws Exception {
  DateTimeZone MSK=DateTimeZone.forOffsetHours(3);
  DateTime endsOn=DateTime.now(MSK).plus(Period.parse("String_Node_Str"));
  DateTime startDateTime=DateTime.now().minusDays(20);
  DateTime endDateTime=DateTime.now().plusDays(20);
  ScheduleContext context=new ScheduleContext.Builder().withHealthCode(healthCode).withStudyIdentifier(TEST_STUDY_IDENTIFIER).withClientInfo(ClientInfo.UNKNOWN_CLIENT).withInitialTimeZone(MSK).withEndsOn(endsOn).withEvents(eventMap()).build();
  Schedule schedule=plan.getStrategy().getScheduleForUser(plan,context);
  List<ScheduledActivity> activitiesToSchedule=schedule.getScheduler().getScheduledActivities(plan,context);
  activityDao.saveActivities(activitiesToSchedule);
  String activityGuid=extractActivityGuid();
  ForwardCursorPagedResourceList<ScheduledActivity> history=activityDao.getActivityHistoryV2(healthCode,activityGuid,startDateTime,endDateTime,MSK,null,10);
  assertEquals(10,history.getItems().size());
  history.getItems().stream().forEach(scheduledActivity -> assertEquals(MSK,scheduledActivity.getTimeZone()));
  Set<String> allTaskGuids=history.getItems().stream().map(ScheduledActivity::getGuid).collect(toSet());
  history=activityDao.getActivityHistoryV2(healthCode,activityGuid,startDateTime,endDateTime,MSK,history.getOffsetBy(),10);
  assertEquals(10,history.getItems().size());
  history.getItems().stream().forEach(scheduledActivity -> assertEquals(MSK,scheduledActivity.getTimeZone()));
  allTaskGuids.addAll(history.getItems().stream().map(ScheduledActivity::getGuid).collect(toSet()));
  assertEquals(20,allTaskGuids.size());
  history=activityDao.getActivityHistoryV2(healthCode,activityGuid,startDateTime,startDateTime,MSK,null,10);
  assertEquals(0,history.getItems().size());
  assertNull(history.getOffsetBy());
}