@Test void getScopeFilterPreferencesCriteriaOnlyGivenType() { NotificationFormat requestedFormat = null; String requestedEventType = "mentions"; boolean onlyGivenType = true; NotificationFilterPreference pref1 = mock(NotificationFilterPreference.class); NotificationFilterPreference pref2 = mock(NotificationFilterPreference.class); NotificationFilterPreference pref3 = mock(NotificationFilterPreference.class); NotificationFilterPreference pref4 = mock(NotificationFilterPreference.class); NotificationFilterPreference pref5 = mock(NotificationFilterPreference.class); NotificationFilterPreference pref6 = mock(NotificationFilterPreference.class); when(pref1.isEnabled()).thenReturn(false); when(pref2.isEnabled()).thenReturn(true); when(pref3.isEnabled()).thenReturn(true); when(pref4.isEnabled()).thenReturn(true); when(pref5.isEnabled()).thenReturn(true); when(pref6.isEnabled()).thenReturn(true); when(pref2.getFilterName()).thenReturn("Something"); when(pref3.getFilterName()).thenReturn(ScopeNotificationFilter.FILTER_NAME); when(pref4.getFilterName()).thenReturn(ScopeNotificationFilter.FILTER_NAME); when(pref5.getFilterName()).thenReturn(ScopeNotificationFilter.FILTER_NAME); when(pref6.getFilterName()).thenReturn(ScopeNotificationFilter.FILTER_NAME); when(pref3.getNotificationFormats()).thenReturn(Collections.singleton(NotificationFormat.EMAIL)); when(pref4.getNotificationFormats()) .thenReturn(new HashSet<>(Arrays.asList(NotificationFormat.ALERT, NotificationFormat.EMAIL))); when(pref5.getNotificationFormats()).thenReturn(Collections.singleton(NotificationFormat.ALERT)); when(pref6.getNotificationFormats()).thenReturn(null); when(pref3.getEventTypes()).thenReturn(Collections.singleton("mentions")); when(pref4.getEventTypes()).thenReturn(Collections.singleton("otherEventType")); when(pref5.getEventTypes()).thenReturn(Collections.emptySet()); when(pref6.getEventTypes()).thenReturn(new HashSet<>(Arrays.asList("like", "mentions", "comment"))); ScopeNotificationFilterPreferencesHierarchy expected = new ScopeNotificationFilterPreferencesHierarchy( Arrays.asList( new ScopeNotificationFilterPreference(pref3, this.entityReferenceResolver), new ScopeNotificationFilterPreference(pref6, this.entityReferenceResolver) )); assertEquals(expected, this.getter.getScopeFilterPreferences(Arrays.asList( pref1, pref2, pref3, pref4, pref5, pref6 ), requestedEventType, requestedFormat, onlyGivenType)); }
public ScopeNotificationFilterPreferencesHierarchy getScopeFilterPreferences( Collection<NotificationFilterPreference> filterPreferences, String eventType, NotificationFormat format, boolean onlyGivenType) { List<ScopeNotificationFilterPreference> results = new ArrayList<>(); Stream<NotificationFilterPreference> filterPreferenceStream = filterPreferences.stream().filter( pref -> matchAllCriteria(pref, eventType, format, onlyGivenType) ); Iterator<NotificationFilterPreference> iterator = filterPreferenceStream.iterator(); while (iterator.hasNext()) { results.add(new ScopeNotificationFilterPreference(iterator.next(), entityReferenceResolver)); } return new ScopeNotificationFilterPreferencesHierarchy(results); }
ScopeNotificationFilterPreferencesGetter { public ScopeNotificationFilterPreferencesHierarchy getScopeFilterPreferences( Collection<NotificationFilterPreference> filterPreferences, String eventType, NotificationFormat format, boolean onlyGivenType) { List<ScopeNotificationFilterPreference> results = new ArrayList<>(); Stream<NotificationFilterPreference> filterPreferenceStream = filterPreferences.stream().filter( pref -> matchAllCriteria(pref, eventType, format, onlyGivenType) ); Iterator<NotificationFilterPreference> iterator = filterPreferenceStream.iterator(); while (iterator.hasNext()) { results.add(new ScopeNotificationFilterPreference(iterator.next(), entityReferenceResolver)); } return new ScopeNotificationFilterPreferencesHierarchy(results); } }
ScopeNotificationFilterPreferencesGetter { public ScopeNotificationFilterPreferencesHierarchy getScopeFilterPreferences( Collection<NotificationFilterPreference> filterPreferences, String eventType, NotificationFormat format, boolean onlyGivenType) { List<ScopeNotificationFilterPreference> results = new ArrayList<>(); Stream<NotificationFilterPreference> filterPreferenceStream = filterPreferences.stream().filter( pref -> matchAllCriteria(pref, eventType, format, onlyGivenType) ); Iterator<NotificationFilterPreference> iterator = filterPreferenceStream.iterator(); while (iterator.hasNext()) { results.add(new ScopeNotificationFilterPreference(iterator.next(), entityReferenceResolver)); } return new ScopeNotificationFilterPreferencesHierarchy(results); }  }
ScopeNotificationFilterPreferencesGetter { public ScopeNotificationFilterPreferencesHierarchy getScopeFilterPreferences( Collection<NotificationFilterPreference> filterPreferences, String eventType, NotificationFormat format, boolean onlyGivenType) { List<ScopeNotificationFilterPreference> results = new ArrayList<>(); Stream<NotificationFilterPreference> filterPreferenceStream = filterPreferences.stream().filter( pref -> matchAllCriteria(pref, eventType, format, onlyGivenType) ); Iterator<NotificationFilterPreference> iterator = filterPreferenceStream.iterator(); while (iterator.hasNext()) { results.add(new ScopeNotificationFilterPreference(iterator.next(), entityReferenceResolver)); } return new ScopeNotificationFilterPreferencesHierarchy(results); }  ScopeNotificationFilterPreferencesHierarchy getScopeFilterPreferences(
        Collection<NotificationFilterPreference> filterPreferences, String eventType, NotificationFormat format,
        boolean onlyGivenType); }
ScopeNotificationFilterPreferencesGetter { public ScopeNotificationFilterPreferencesHierarchy getScopeFilterPreferences( Collection<NotificationFilterPreference> filterPreferences, String eventType, NotificationFormat format, boolean onlyGivenType) { List<ScopeNotificationFilterPreference> results = new ArrayList<>(); Stream<NotificationFilterPreference> filterPreferenceStream = filterPreferences.stream().filter( pref -> matchAllCriteria(pref, eventType, format, onlyGivenType) ); Iterator<NotificationFilterPreference> iterator = filterPreferenceStream.iterator(); while (iterator.hasNext()) { results.add(new ScopeNotificationFilterPreference(iterator.next(), entityReferenceResolver)); } return new ScopeNotificationFilterPreferencesHierarchy(results); }  ScopeNotificationFilterPreferencesHierarchy getScopeFilterPreferences(
        Collection<NotificationFilterPreference> filterPreferences, String eventType, NotificationFormat format,
        boolean onlyGivenType);  }