List of usage examples for java.time ZonedDateTime toLocalDateTime
@Override
public LocalDateTime toLocalDateTime()
From source file:nu.yona.server.analysis.service.ActivityUpdateServiceTest.java
@Test public void addActivity_appActivityOnNewDay_newDayActivityButNoGoalConflictMessageCreated() { ZonedDateTime today = now().truncatedTo(ChronoUnit.DAYS); // mock earlier activity at yesterday 23:59:58, // add new activity at today 00:00:01 ZonedDateTime existingActivityTime = today.minusDays(1).withHour(23).withMinute(59).withSecond(58); DayActivity existingDayActivity = mockExistingActivity(gamblingGoal, existingActivityTime); ActivityDto lastRegisteredActivity = ActivityDto.createInstance(existingDayActivity.getActivities().get(0)); ZonedDateTime startTime = today.withHour(0).withMinute(0).withSecond(1); ZonedDateTime endTime = today.withHour(0).withMinute(10); service.addActivity(userAnonEntity, createPayload(startTime, endTime), GoalDto.createInstance(gamblingGoal), Optional.of(lastRegisteredActivity)); verifyNoGoalConflictMessagesCreated(); // Verify there are now two day activities verify(mockUserAnonymizedService, atLeastOnce()).updateUserAnonymized(userAnonEntity); List<WeekActivity> weekActivities = gamblingGoal.getWeekActivities(); assertThat("One week activity created", weekActivities.size(), equalTo(1)); List<DayActivity> dayActivities = weekActivities.get(0).getDayActivities(); assertThat("Two day activities created", dayActivities.size(), equalTo(2)); DayActivity yesterdaysDayActivity;/* ww w . ja v a2s .co m*/ DayActivity todaysDayActivity; if (dayActivities.get(0).getStartDate().isBefore(dayActivities.get(1).getStartDate())) { yesterdaysDayActivity = dayActivities.get(0); todaysDayActivity = dayActivities.get(1); } else { yesterdaysDayActivity = dayActivities.get(1); todaysDayActivity = dayActivities.get(0); } // Double check yesterday's activity List<Activity> yesterdaysActivities = yesterdaysDayActivity.getActivities(); assertThat("One activity created for yesterday", yesterdaysActivities.size(), equalTo(1)); Activity yesterdaysActivity = yesterdaysActivities.get(0); assertThat("Expect right goal set to yesterday's activity", yesterdaysActivity.getActivityCategory(), equalTo(gamblingGoal.getActivityCategory())); // Verify one activity was created, with the right goal List<Activity> activities = todaysDayActivity.getActivities(); assertThat("One activity created", activities.size(), equalTo(1)); Activity activity = activities.get(0); assertThat("Expect right goal set to activity", activity.getActivityCategory(), equalTo(gamblingGoal.getActivityCategory())); assertThat("Expect new day", todaysDayActivity, not(equalTo(existingDayActivity))); assertThat("Expect right date", todaysDayActivity.getStartDate(), equalTo(today.toLocalDate())); assertThat("Expect activity added", todaysDayActivity.getLastActivity(deviceAnonId), notNullValue()); assertThat("Expect matching start time", todaysDayActivity.getLastActivity(deviceAnonId).getStartTime(), equalTo(startTime.toLocalDateTime())); assertThat("Expect matching end time", todaysDayActivity.getLastActivity(deviceAnonId).getEndTime(), equalTo(endTime.toLocalDateTime())); // Verify that there is an activity cached verify(mockAnalysisEngineCacheService, atLeastOnce()).updateLastActivityForUser(eq(userAnonId), eq(deviceAnonId), eq(gamblingGoal.getId()), any()); }
From source file:nu.yona.server.analysis.service.ActivityServiceTest.java
@Test public void getUserDayActivityDetail_activityPresent_resultWithActivity() { ZonedDateTime today = getDayStartTime(ZonedDateTime.now(userAnonZone)); ZonedDateTime yesterday = today.minusDays(1); LocalTime activityStartTimeOnDay = LocalTime.parse("20:14:57"); LocalTime activityEndTimeOnDay = LocalTime.parse("20:21:00"); int hour = 20; int[] expectedSpread = getEmptySpread(); expectedSpread[hour * 4] = 1;/*from w w w.j av a 2 s . c o m*/ expectedSpread[hour * 4 + 1] = 6; // gambling goal was created 2 weeks ago, see above // mock some activity on yesterday DayActivity yesterdayRecordedActivity = DayActivity.createInstance(userAnonEntity, gamblingGoal, userAnonZone, yesterday.toLocalDate()); ZonedDateTime activityStartTime = yesterday.withHour(activityStartTimeOnDay.getHour()) .withMinute(activityStartTimeOnDay.getMinute()).withSecond(activityStartTimeOnDay.getSecond()); ZonedDateTime activityEndTime = yesterday.withHour(activityEndTimeOnDay.getHour()) .withMinute(activityEndTimeOnDay.getMinute()).withSecond(activityEndTimeOnDay.getSecond()); Activity recordedActivity = Activity.createInstance(userAnonZone, activityStartTime.toLocalDateTime(), activityEndTime.toLocalDateTime(), Optional.empty()); yesterdayRecordedActivity.addActivity(recordedActivity); when(mockDayActivityRepository.findOne(userAnonId, yesterday.toLocalDate(), gamblingGoal.getId())) .thenReturn(yesterdayRecordedActivity); DayActivityDto activityDay = service.getUserDayActivityDetail(userId, yesterday.toLocalDate(), gamblingGoal.getId()); verify(mockDayActivityRepository, times(1)).findOne(userAnonId, yesterday.toLocalDate(), gamblingGoal.getId()); assertThat(activityDay.getSpread(), equalTo(Arrays.asList(ArrayUtils.toObject((expectedSpread))))); }