### Question:
AbstractDispatcherCacheHeaderFilter implements Filter { @Activate @SuppressWarnings("squid:S1149") protected final void activate(ComponentContext context) throws Exception { Dictionary<?, ?> properties = context.getProperties(); doActivate(context); String[] filters = PropertiesUtil.toStringArray(properties.get(PROP_FILTER_PATTERN)); if (filters == null || filters.length == 0) { throw new ConfigurationException(PROP_FILTER_PATTERN, "At least one filter pattern must be specified."); } for (String pattern : filters) { Dictionary<String, String> filterProps = new Hashtable<String, String>(); log.debug("Adding filter ({}) to pattern: {}", this, pattern); filterProps.put(HttpWhiteboardConstants.HTTP_WHITEBOARD_FILTER_REGEX, pattern); filterProps.put(HttpWhiteboardConstants.HTTP_WHITEBOARD_CONTEXT_SELECT, "(" + HttpWhiteboardConstants.HTTP_WHITEBOARD_CONTEXT_NAME + "=*)"); ServiceRegistration filterReg = context.getBundleContext().registerService(Filter.class.getName(), this, filterProps); filterRegistrations.add(filterReg); } }  @Override void init(final FilterConfig filterConfig); @Override final void doFilter(final ServletRequest servletRequest, final ServletResponse servletResponse,
            final FilterChain filterChain); @Override void destroy(); static final String PROP_FILTER_PATTERN; }### Answer:
@Test public void testActivateSuccess() throws Exception { final BaseMatcher<Dictionary<String, Object>> filterPropsMatcher = new BaseMatcher<Dictionary<String, Object>>() { @Override public void describeTo(Description description) { } @Override @SuppressWarnings("unchecked") public boolean matches(Object item) { return StringUtils.equals(pattern, ((Dictionary<String, Object>) item).get(HttpWhiteboardConstants.HTTP_WHITEBOARD_FILTER_REGEX).toString()); } }; filter.activate(componentContext); verify(componentContext).getProperties(); verify(componentContext).getBundleContext(); verify(bundleContext).registerService(eq(Filter.class.getName()), eq(filter), argThat(filterPropsMatcher)); verifyNoMoreInteractions(componentContext, bundleContext, serviceRegistration); }
@Test public void testActivateMultipleFilters() throws Exception { final ServiceRegistration secondRegistration = mock(ServiceRegistration.class); final String secondPattern = "/content/dam/.*"; properties.put(AbstractDispatcherCacheHeaderFilter.PROP_FILTER_PATTERN, new String[] { pattern, secondPattern }); final BaseMatcher<Dictionary<String, Object>> firstPropsMatcher = new BaseMatcher<Dictionary<String, Object>>() { @Override public void describeTo(Description description) { } @Override @SuppressWarnings("unchecked") public boolean matches(Object item) { return StringUtils.equals(pattern, ((Dictionary<String, Object>) item).get(HttpWhiteboardConstants.HTTP_WHITEBOARD_FILTER_REGEX).toString()); } }; final BaseMatcher<Dictionary<String, Object>> secondPropsMatcher = new BaseMatcher<Dictionary<String, Object>>() { @Override public void describeTo(Description description) { } @Override @SuppressWarnings("unchecked") public boolean matches(Object item) { return StringUtils.equals(secondPattern, ((Dictionary<String, Object>) item).get(HttpWhiteboardConstants.HTTP_WHITEBOARD_FILTER_REGEX).toString()); } }; filter.activate(componentContext); verify(componentContext).getProperties(); verify(componentContext, times(2)).getBundleContext(); verify(bundleContext).registerService(eq(Filter.class.getName()), eq(filter), argThat(firstPropsMatcher)); verify(bundleContext).registerService(eq(Filter.class.getName()), eq(filter), argThat(secondPropsMatcher)); verifyNoMoreInteractions(componentContext, bundleContext, serviceRegistration, secondRegistration); }
@Test(expected = ConfigurationException.class) public void testActivateNoFilters() throws Exception { properties.remove(AbstractDispatcherCacheHeaderFilter.PROP_FILTER_PATTERN); when(componentContext.getProperties()).thenReturn(properties); filter.activate(componentContext); }