@Test public void filterEvent() throws Exception { DocumentReference user1 = new DocumentReference("xwiki", "XWiki", "User"); DocumentReference user2 = new DocumentReference("xwiki", "XWiki", "User2"); when(serializer.serialize(user1)).thenReturn("xwiki:XWiki.User1"); when(serializer.serialize(user2)).thenReturn("xwiki:XWiki.User2"); Event event1 = mock(Event.class); Event event2 = mock(Event.class); Event event3 = mock(Event.class); when(event1.getUser()).thenReturn(user1); when(event2.getUser()).thenReturn(user2); when(event3.getUser()).thenReturn(user2); when(event1.getType()).thenReturn("personalMessage"); when(event2.getType()).thenReturn("personalMessage"); when(event3.getType()).thenReturn("otherType"); when(preferencesGetter.isUsedFollowed("xwiki:XWiki.User1", null, NotificationFormat.ALERT)) .thenReturn(true); when(preferencesGetter.isUsedFollowed("xwiki:XWiki.User2", null, NotificationFormat.ALERT)) .thenReturn(false); assertEquals(NotificationFilter.FilterPolicy.KEEP, mocker.getComponentUnderTest().filterEvent(event1, null, null, NotificationFormat.ALERT)); assertEquals(NotificationFilter.FilterPolicy.FILTER, mocker.getComponentUnderTest().filterEvent(event2, null, null, NotificationFormat.ALERT)); assertEquals(NotificationFilter.FilterPolicy.NO_EFFECT, mocker.getComponentUnderTest().filterEvent(event3, null, null, NotificationFormat.ALERT)); }
@Override public FilterPolicy filterEvent(Event event, DocumentReference user, Collection<NotificationFilterPreference> filterPreferences, NotificationFormat format) { if (!PersonalMessageDescriptor.EVENT_TYPE.equals(event.getType())) { return FilterPolicy.NO_EFFECT; } String sender = serializer.serialize(event.getUser()); return preferencesGetter.isUsedFollowed(sender, filterPreferences, format) ? FilterPolicy.KEEP : FilterPolicy.FILTER; }
PersonalMessageStreamNotificationFilter implements NotificationFilter { @Override public FilterPolicy filterEvent(Event event, DocumentReference user, Collection<NotificationFilterPreference> filterPreferences, NotificationFormat format) { if (!PersonalMessageDescriptor.EVENT_TYPE.equals(event.getType())) { return FilterPolicy.NO_EFFECT; } String sender = serializer.serialize(event.getUser()); return preferencesGetter.isUsedFollowed(sender, filterPreferences, format) ? FilterPolicy.KEEP : FilterPolicy.FILTER; } }
PersonalMessageStreamNotificationFilter implements NotificationFilter { @Override public FilterPolicy filterEvent(Event event, DocumentReference user, Collection<NotificationFilterPreference> filterPreferences, NotificationFormat format) { if (!PersonalMessageDescriptor.EVENT_TYPE.equals(event.getType())) { return FilterPolicy.NO_EFFECT; } String sender = serializer.serialize(event.getUser()); return preferencesGetter.isUsedFollowed(sender, filterPreferences, format) ? FilterPolicy.KEEP : FilterPolicy.FILTER; }  }
PersonalMessageStreamNotificationFilter implements NotificationFilter { @Override public FilterPolicy filterEvent(Event event, DocumentReference user, Collection<NotificationFilterPreference> filterPreferences, NotificationFormat format) { if (!PersonalMessageDescriptor.EVENT_TYPE.equals(event.getType())) { return FilterPolicy.NO_EFFECT; } String sender = serializer.serialize(event.getUser()); return preferencesGetter.isUsedFollowed(sender, filterPreferences, format) ? FilterPolicy.KEEP : FilterPolicy.FILTER; }  @Override FilterPolicy filterEvent(Event event, DocumentReference user,
            Collection<NotificationFilterPreference> filterPreferences, NotificationFormat format); @Override boolean matchesPreference(NotificationPreference preference); @Override ExpressionNode filterExpression(DocumentReference user,
            Collection<NotificationFilterPreference> filterPreferences, NotificationPreference preference); @Override ExpressionNode filterExpression(DocumentReference user,
            Collection<NotificationFilterPreference> filterPreferences, NotificationFilterType type,
            NotificationFormat format); @Override String getName(); }
PersonalMessageStreamNotificationFilter implements NotificationFilter { @Override public FilterPolicy filterEvent(Event event, DocumentReference user, Collection<NotificationFilterPreference> filterPreferences, NotificationFormat format) { if (!PersonalMessageDescriptor.EVENT_TYPE.equals(event.getType())) { return FilterPolicy.NO_EFFECT; } String sender = serializer.serialize(event.getUser()); return preferencesGetter.isUsedFollowed(sender, filterPreferences, format) ? FilterPolicy.KEEP : FilterPolicy.FILTER; }  @Override FilterPolicy filterEvent(Event event, DocumentReference user,
            Collection<NotificationFilterPreference> filterPreferences, NotificationFormat format); @Override boolean matchesPreference(NotificationPreference preference); @Override ExpressionNode filterExpression(DocumentReference user,
            Collection<NotificationFilterPreference> filterPreferences, NotificationPreference preference); @Override ExpressionNode filterExpression(DocumentReference user,
            Collection<NotificationFilterPreference> filterPreferences, NotificationFilterType type,
            NotificationFormat format); @Override String getName();  }