@Test public void filterEvent() throws Exception { DocumentReference user = new DocumentReference("xwiki", "XWiki", "User"); when(serializer.serialize(user)).thenReturn("xwiki:XWiki.User"); Event event1 = mock(Event.class); when(event1.getType()).thenReturn("directMessage"); when(event1.getStream()).thenReturn("xwiki:XWiki.User"); Event event2 = mock(Event.class); when(event2.getType()).thenReturn("directMessage"); when(event2.getStream()).thenReturn("xwiki:XWiki.OtherUser"); Event event3 = mock(Event.class); when(event3.getType()).thenReturn("someType"); when(event3.getStream()).thenReturn("xwiki:XWiki.OtherUser"); assertEquals(NotificationFilter.FilterPolicy.NO_EFFECT, mocker.getComponentUnderTest().filterEvent(event1, user, null, null)); assertEquals(NotificationFilter.FilterPolicy.FILTER, mocker.getComponentUnderTest().filterEvent(event2, user, null, null)); assertEquals(NotificationFilter.FilterPolicy.NO_EFFECT, mocker.getComponentUnderTest().filterEvent(event3, user, null, null)); }
@Override public FilterPolicy filterEvent(Event event, DocumentReference user, Collection<NotificationFilterPreference> filterPreferences, NotificationFormat format) { if (!DirectMessageDescriptor.EVENT_TYPE.equals(event.getType())) { return FilterPolicy.NO_EFFECT; } if (user != null) { String userId = serializer.serialize(user); return userId.equals(event.getStream()) ? FilterPolicy.NO_EFFECT : FilterPolicy.FILTER; } else { return FilterPolicy.FILTER; } }
DirectMessageStreamNotificationFilter implements NotificationFilter { @Override public FilterPolicy filterEvent(Event event, DocumentReference user, Collection<NotificationFilterPreference> filterPreferences, NotificationFormat format) { if (!DirectMessageDescriptor.EVENT_TYPE.equals(event.getType())) { return FilterPolicy.NO_EFFECT; } if (user != null) { String userId = serializer.serialize(user); return userId.equals(event.getStream()) ? FilterPolicy.NO_EFFECT : FilterPolicy.FILTER; } else { return FilterPolicy.FILTER; } } }
DirectMessageStreamNotificationFilter implements NotificationFilter { @Override public FilterPolicy filterEvent(Event event, DocumentReference user, Collection<NotificationFilterPreference> filterPreferences, NotificationFormat format) { if (!DirectMessageDescriptor.EVENT_TYPE.equals(event.getType())) { return FilterPolicy.NO_EFFECT; } if (user != null) { String userId = serializer.serialize(user); return userId.equals(event.getStream()) ? FilterPolicy.NO_EFFECT : FilterPolicy.FILTER; } else { return FilterPolicy.FILTER; } }  }
DirectMessageStreamNotificationFilter implements NotificationFilter { @Override public FilterPolicy filterEvent(Event event, DocumentReference user, Collection<NotificationFilterPreference> filterPreferences, NotificationFormat format) { if (!DirectMessageDescriptor.EVENT_TYPE.equals(event.getType())) { return FilterPolicy.NO_EFFECT; } if (user != null) { String userId = serializer.serialize(user); return userId.equals(event.getStream()) ? FilterPolicy.NO_EFFECT : FilterPolicy.FILTER; } else { return 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(); @Override int getPriority(); }
DirectMessageStreamNotificationFilter implements NotificationFilter { @Override public FilterPolicy filterEvent(Event event, DocumentReference user, Collection<NotificationFilterPreference> filterPreferences, NotificationFormat format) { if (!DirectMessageDescriptor.EVENT_TYPE.equals(event.getType())) { return FilterPolicy.NO_EFFECT; } if (user != null) { String userId = serializer.serialize(user); return userId.equals(event.getStream()) ? FilterPolicy.NO_EFFECT : FilterPolicy.FILTER; } else { return 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(); @Override int getPriority();  }