EventFilter { public boolean shouldFilter(Event event) { boolean enabled = config.getBoolean(ConfigProperties.AUDIT_FILTER_ENABLED); if (!enabled) { return false; } EventTypeAndTarget eventKey = new EventTypeAndTarget(event.getType(), event.getTarget()); if (toNotFilter.contains(eventKey)) { return false; } if (toFilter.contains(eventKey)) { return true; } if (defaultFilterPolicy == FilterPolicy.DO_FILTER) { return true; } else if (defaultFilterPolicy == FilterPolicy.DO_NOT_FILTER) { return false; } else { throw new IllegalArgumentException("Unknown default filtering policy: " + defaultFilterPolicy); } } @Inject  EventFilter(Configuration config); boolean shouldFilter(Event event);  }
@Test public void disabledShouldntFilter() { assertFalse(eventFilterDisabled.shouldFilter(event1)); assertFalse(eventFilterDisabled.shouldFilter(event2)); }
@Test public void filterUnknownEventPolicyDoFilter() { assertTrue(eventFilterEnabled.shouldFilter(event2)); }
@Test public void notFilterIncludes() { assertFalse(eventFilterEnabled.shouldFilter(event1)); }
@Test public void policyDoNotFilterShouldntFilter() { assertFalse(eventFilterDoNotFilter.shouldFilter(event1)); assertFalse(eventFilterDoNotFilter.shouldFilter(event2)); }
@Test public void policyDoNotFilterShouldFilterExcludes() { assertTrue(eventFilterDoNotFilter.shouldFilter(event3)); }