@Test public void filterEvent() throws Exception { Collection<NotificationFilterPreference> filterPreferences = mockPreferences(); Event event1 = mock(Event.class); when(event1.getUser()).thenReturn(USER_A); Event event2 = mock(Event.class); when(event2.getUser()).thenReturn(USER_B); Event event3 = mock(Event.class); when(event3.getUser()).thenReturn(USER_C); Event event4 = mock(Event.class); when(event4.getUser()).thenReturn(USER_D); Event event5 = mock(Event.class); when(event5.getUser()).thenReturn(USER_E); assertEquals(NotificationFilter.FilterPolicy.FILTER, mocker.getComponentUnderTest().filterEvent(event1, CURRENT_USER, filterPreferences, NotificationFormat.ALERT)); assertEquals(NotificationFilter.FilterPolicy.FILTER, mocker.getComponentUnderTest().filterEvent(event2, CURRENT_USER, filterPreferences, NotificationFormat.ALERT)); assertEquals(NotificationFilter.FilterPolicy.FILTER, mocker.getComponentUnderTest().filterEvent(event3, CURRENT_USER, filterPreferences, NotificationFormat.ALERT)); assertEquals(NotificationFilter.FilterPolicy.NO_EFFECT, mocker.getComponentUnderTest().filterEvent(event4, CURRENT_USER, filterPreferences, NotificationFormat.ALERT)); assertEquals(NotificationFilter.FilterPolicy.NO_EFFECT, mocker.getComponentUnderTest().filterEvent(event5, CURRENT_USER, filterPreferences, NotificationFormat.ALERT)); }
@Override public FilterPolicy filterEvent(Event event, DocumentReference user, Collection<NotificationFilterPreference> filterPreferences, NotificationFormat format) { final String eventUserId = serializer.serialize(event.getUser()); if (preferencesGetter.isUserExcluded(eventUserId, filterPreferences, format)) { return FilterPolicy.FILTER; } if (preferencesGetter.isUsedFollowed(eventUserId, filterPreferences, format)) { return FilterPolicy.KEEP; } return FilterPolicy.NO_EFFECT; }
EventUserFilter implements NotificationFilter { @Override public FilterPolicy filterEvent(Event event, DocumentReference user, Collection<NotificationFilterPreference> filterPreferences, NotificationFormat format) { final String eventUserId = serializer.serialize(event.getUser()); if (preferencesGetter.isUserExcluded(eventUserId, filterPreferences, format)) { return FilterPolicy.FILTER; } if (preferencesGetter.isUsedFollowed(eventUserId, filterPreferences, format)) { return FilterPolicy.KEEP; } return FilterPolicy.NO_EFFECT; } }
EventUserFilter implements NotificationFilter { @Override public FilterPolicy filterEvent(Event event, DocumentReference user, Collection<NotificationFilterPreference> filterPreferences, NotificationFormat format) { final String eventUserId = serializer.serialize(event.getUser()); if (preferencesGetter.isUserExcluded(eventUserId, filterPreferences, format)) { return FilterPolicy.FILTER; } if (preferencesGetter.isUsedFollowed(eventUserId, filterPreferences, format)) { return FilterPolicy.KEEP; } return FilterPolicy.NO_EFFECT; }  }
EventUserFilter implements NotificationFilter { @Override public FilterPolicy filterEvent(Event event, DocumentReference user, Collection<NotificationFilterPreference> filterPreferences, NotificationFormat format) { final String eventUserId = serializer.serialize(event.getUser()); if (preferencesGetter.isUserExcluded(eventUserId, filterPreferences, format)) { return FilterPolicy.FILTER; } if (preferencesGetter.isUsedFollowed(eventUserId, filterPreferences, format)) { return FilterPolicy.KEEP; } return FilterPolicy.NO_EFFECT; }  @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(); }
EventUserFilter implements NotificationFilter { @Override public FilterPolicy filterEvent(Event event, DocumentReference user, Collection<NotificationFilterPreference> filterPreferences, NotificationFormat format) { final String eventUserId = serializer.serialize(event.getUser()); if (preferencesGetter.isUserExcluded(eventUserId, filterPreferences, format)) { return FilterPolicy.FILTER; } if (preferencesGetter.isUsedFollowed(eventUserId, filterPreferences, format)) { return FilterPolicy.KEEP; } return FilterPolicy.NO_EFFECT; }  @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(); static final String FILTER_NAME; }