### Question:
PreferenceDateNotificationFilter { public boolean shouldFilter(Event event, Collection<NotificationPreference> preferences) { for (NotificationPreference preference : preferences) { Object preferenceEventType = preference.getProperties().get(NotificationPreferenceProperty.EVENT_TYPE); if (preferenceEventType != null && event.getType().equals(preferenceEventType) && preference.getStartDate().after(event.getDate())) { return true; } } return false; }  boolean shouldFilter(Event event, Collection<NotificationPreference> preferences);  }### Answer:
@Test void shouldFilterDefault() { assertFalse(this.notificationFilter.shouldFilter(mock(Event.class), Collections.emptyList())); }
@Test void shouldFilterEvent() { Event event = mock(Event.class); NotificationPreference pref1 = mock(NotificationPreference.class); NotificationPreference pref2 = mock(NotificationPreference.class); String eventType = "myEventType"; when(event.getType()).thenReturn(eventType); when(pref1.getProperties()).thenReturn(Collections.emptyMap()); when(pref2.getProperties()) .thenReturn(Collections.singletonMap(NotificationPreferenceProperty.EVENT_TYPE, eventType)); when(event.getDate()).thenReturn(new Date(41)); when(pref2.getStartDate()).thenReturn(new Date(42)); assertTrue(this.notificationFilter.shouldFilter(event, Arrays.asList(pref1, pref2))); }
@Test void shouldNotFilterWrongType() { Event event = mock(Event.class); NotificationPreference pref1 = mock(NotificationPreference.class); NotificationPreference pref2 = mock(NotificationPreference.class); String eventType = "myEventType"; when(event.getType()).thenReturn(eventType); when(pref1.getProperties()).thenReturn(Collections.emptyMap()); when(pref2.getProperties()) .thenReturn(Collections.singletonMap(NotificationPreferenceProperty.EVENT_TYPE, "anotherType")); assertFalse(this.notificationFilter.shouldFilter(event, Arrays.asList(pref1, pref2))); }
@Test void shouldNotFilterWrongDate() { Event event = mock(Event.class); NotificationPreference pref1 = mock(NotificationPreference.class); NotificationPreference pref2 = mock(NotificationPreference.class); String eventType = "myEventType"; when(event.getType()).thenReturn(eventType); when(pref2.getProperties()) .thenReturn(Collections.singletonMap(NotificationPreferenceProperty.EVENT_TYPE, eventType)); when(pref2.getProperties()) .thenReturn(Collections.singletonMap(NotificationPreferenceProperty.EVENT_TYPE, eventType)); when(event.getDate()).thenReturn(new Date(40)); when(pref2.getStartDate()).thenReturn(new Date(0)); when(pref2.getStartDate()).thenReturn(new Date(39)); assertFalse(this.notificationFilter.shouldFilter(event, Arrays.asList(pref1, pref2))); }
@Test void shouldFilterEventSameDate() { Event event = mock(Event.class); NotificationPreference pref1 = mock(NotificationPreference.class); NotificationPreference pref2 = mock(NotificationPreference.class); String eventType = "myEventType"; when(event.getType()).thenReturn(eventType); when(pref1.getProperties()).thenReturn(Collections.emptyMap()); when(pref2.getProperties()) .thenReturn(Collections.singletonMap(NotificationPreferenceProperty.EVENT_TYPE, eventType)); when(event.getDate()).thenReturn(new Date(42)); when(pref2.getStartDate()).thenReturn(new Date(42)); assertFalse(this.notificationFilter.shouldFilter(event, Arrays.asList(pref1, pref2))); }