Source:
public void messageAggregation() { AnalysisServiceProperties p = new AnalysisServiceProperties(); p.setUpdateSkipWindow("PT0S"); when(mockYonaProperties.getAnalysisService()).thenReturn(p); ZonedDateTime t = nowInAmsterdam(); DayActivity dayActivity = mockExistingActivity(gamblingGoal, t); Activity existingActivityEntity = dayActivity.getLastActivity(); Set<String> conflictCategories1 = new HashSet<>(Arrays.asList("lotto")); Set<String> conflictCategories2 = new HashSet<>(Arrays.asList("poker")); Set<String> conflictCategoriesNotMatching1 = new HashSet<>(Arrays.asList("refdag")); service.analyze(userAnonId, new NetworkActivityDto(conflictCategoriesNotMatching1, "http://localhost/test", Optional.empty())); service.analyze(userAnonId, new NetworkActivityDto(conflictCategories1, "http://localhost/test1", Optional.empty())); service.analyze(userAnonId, new NetworkActivityDto(conflictCategories2, "http://localhost/test2", Optional.empty())); service.analyze(userAnonId, new NetworkActivityDto(conflictCategoriesNotMatching1, "http://localhost/test3", Optional.empty())); ZonedDateTime t2 = nowInAmsterdam(); service.analyze(userAnonId, new NetworkActivityDto(conflictCategories2, "http://localhost/test4", Optional.empty())); verify(mockAnalysisEngineCacheService, times(3)).fetchLastActivityForUser(userAnonId, gamblingGoal.getId()); ArgumentCaptor<MessageDestination> messageDestination = ArgumentCaptor.forClass(MessageDestination.class); verify(mockMessageService, never()).sendMessage(any(), messageDestination.capture()); verifyActivityUpdate(gamblingGoal); verify(mockAnalysisEngineCacheService, times(3)).updateLastActivityForUser(eq(userAnonId), eq(gamblingGoal.getId()), any()); assertThat("Expect start time to remain the same", existingActivityEntity.getStartTime(), equalTo(t.toLocalDateTime())); assertThat("Expect end time updated at the last executed analysis matching the goals", existingActivityEntity.getEndTimeAsZonedDateTime(), greaterThanOrEqualTo(t2)); when(mockYonaProperties.getAnalysisService()).thenReturn(new AnalysisServiceProperties()); }

Target:
public void messageAggregation() { AnalysisServiceProperties p = new AnalysisServiceProperties(); p.setUpdateSkipWindow("PT0S"); when(mockYonaProperties.getAnalysisService()).thenReturn(p); ZonedDateTime t = nowInAmsterdam(); DayActivity dayActivity = mockExistingActivity(gamblingGoal, t); Activity existingActivityEntity = dayActivity.getLastActivity(); Set<String> conflictCategories1 = new HashSet<>(Arrays.asList("lotto")); Set<String> conflictCategories2 = new HashSet<>(Arrays.asList("poker")); Set<String> conflictCategoriesNotMatching1 = new HashSet<>(Arrays.asList("refdag")); service.analyze(userAnonId, new NetworkActivityDto(conflictCategoriesNotMatching1, "http://localhost/test", Optional.empty())); service.analyze(userAnonId, new NetworkActivityDto(conflictCategories1, "http://localhost/test1", Optional.empty())); service.analyze(userAnonId, new NetworkActivityDto(conflictCategories2, "http://localhost/test2", Optional.empty())); service.analyze(userAnonId, new NetworkActivityDto(conflictCategoriesNotMatching1, "http://localhost/test3", Optional.empty())); ZonedDateTime t2 = nowInAmsterdam(); service.analyze(userAnonId, new NetworkActivityDto(conflictCategories2, "http://localhost/test4", Optional.empty())); verify(mockAnalysisEngineCacheService, times(3)).fetchLastActivityForUser(userAnonId, gamblingGoal.getId()); verifyNoMessagesCreated(); verifyActivityUpdate(gamblingGoal); verify(mockAnalysisEngineCacheService, times(3)).updateLastActivityForUser(eq(userAnonId), eq(gamblingGoal.getId()), any()); assertThat("Expect start time to remain the same", existingActivityEntity.getStartTime(), equalTo(t.toLocalDateTime())); assertThat("Expect end time updated at the last executed analysis matching the goals", existingActivityEntity.getEndTimeAsZonedDateTime(), greaterThanOrEqualTo(t2)); when(mockYonaProperties.getAnalysisService()).thenReturn(new AnalysisServiceProperties()); }