@Test public void getEventsFilterOnTarget() throws Exception { Event event = createMockedEvent(); when(event.getType()).thenReturn("update"); when(event.getTarget()).thenReturn(new HashSet<>(Arrays.asList("Foo.bar"))); when(authorizationManager.hasAccess(eq(Right.VIEW), eq(userReference), any())).thenReturn(true); when(contextualAuthorizationManager.hasAccess(eq(Right.VIEW), any())).thenReturn(true); when(eventStream.searchEvents(query)).thenReturn(Arrays.asList(event)); NotificationParameters parameters = new NotificationParameters(); parameters.user = this.userReference; parameters.expectedCount = 1; when(serializer.serialize(this.userReference)).thenReturn("XWiki.UserA"); List<CompositeEvent> results = this.defaultParametrizedNotificationManager.getEvents(parameters); assertTrue(results.isEmpty()); verify(this.groupManager, times(1)).getGroups(this.userReference, null, true); when(event.getTarget()).thenReturn(new HashSet<>(Arrays.asList("Foo.bar", "XWiki.UserA"))); results = this.defaultParametrizedNotificationManager.getEvents(parameters); assertEquals(1, results.size()); verify(this.groupManager, times(1)).getGroups(this.userReference, null, true); DocumentReference groupReference = mock(DocumentReference.class); when(this.groupManager.getGroups(this.userReference, null, true)).thenReturn(Arrays.asList(groupReference)); when(this.serializer.serialize(groupReference)).thenReturn("Foo.bar"); when(event.getTarget()).thenReturn(new HashSet<>(Arrays.asList("Foo.bar"))); results = this.defaultParametrizedNotificationManager.getEvents(parameters); assertEquals(1, results.size()); verify(this.groupManager, times(2)).getGroups(this.userReference, null, true); when(event.getTarget()).thenReturn(new HashSet<>(Arrays.asList("Foo.bar", "XWiki.UserA"))); results = this.defaultParametrizedNotificationManager.getEvents(parameters); assertEquals(1, results.size()); verify(this.groupManager, times(2)).getGroups(this.userReference, null, true); }
@Override public List<CompositeEvent> getEvents(NotificationParameters parameters) throws NotificationException { if (Boolean.TRUE.equals(parameters.onlyUnread) && !parameters.filters.contains(eventReadAlertFilter)) { parameters.filters.add(eventReadAlertFilter); } if (Boolean.TRUE.equals(parameters.onlyUnread) && !parameters.filters.contains(eventReadEmailFilter)) { parameters.filters.add(eventReadEmailFilter); } return getEvents(new ArrayList<>(), parameters); }
DefaultParametrizedNotificationManager implements ParametrizedNotificationManager { @Override public List<CompositeEvent> getEvents(NotificationParameters parameters) throws NotificationException { if (Boolean.TRUE.equals(parameters.onlyUnread) && !parameters.filters.contains(eventReadAlertFilter)) { parameters.filters.add(eventReadAlertFilter); } if (Boolean.TRUE.equals(parameters.onlyUnread) && !parameters.filters.contains(eventReadEmailFilter)) { parameters.filters.add(eventReadEmailFilter); } return getEvents(new ArrayList<>(), parameters); } }
DefaultParametrizedNotificationManager implements ParametrizedNotificationManager { @Override public List<CompositeEvent> getEvents(NotificationParameters parameters) throws NotificationException { if (Boolean.TRUE.equals(parameters.onlyUnread) && !parameters.filters.contains(eventReadAlertFilter)) { parameters.filters.add(eventReadAlertFilter); } if (Boolean.TRUE.equals(parameters.onlyUnread) && !parameters.filters.contains(eventReadEmailFilter)) { parameters.filters.add(eventReadEmailFilter); } return getEvents(new ArrayList<>(), parameters); }  }
DefaultParametrizedNotificationManager implements ParametrizedNotificationManager { @Override public List<CompositeEvent> getEvents(NotificationParameters parameters) throws NotificationException { if (Boolean.TRUE.equals(parameters.onlyUnread) && !parameters.filters.contains(eventReadAlertFilter)) { parameters.filters.add(eventReadAlertFilter); } if (Boolean.TRUE.equals(parameters.onlyUnread) && !parameters.filters.contains(eventReadEmailFilter)) { parameters.filters.add(eventReadEmailFilter); } return getEvents(new ArrayList<>(), parameters); }  @Override List<CompositeEvent> getEvents(NotificationParameters parameters); }
DefaultParametrizedNotificationManager implements ParametrizedNotificationManager { @Override public List<CompositeEvent> getEvents(NotificationParameters parameters) throws NotificationException { if (Boolean.TRUE.equals(parameters.onlyUnread) && !parameters.filters.contains(eventReadAlertFilter)) { parameters.filters.add(eventReadAlertFilter); } if (Boolean.TRUE.equals(parameters.onlyUnread) && !parameters.filters.contains(eventReadEmailFilter)) { parameters.filters.add(eventReadEmailFilter); } return getEvents(new ArrayList<>(), parameters); }  @Override List<CompositeEvent> getEvents(NotificationParameters parameters);  }