CspPolicyEnforcer implements PolicyEnforcer { @Override public void applyPolicy(ServletContext cx) { cspEnforcementFilter = new CspEnforcementFilter(policy, policyConfig); FilterRegistration.Dynamic filterRegistration = cx.addFilter("cspEnforcementFilter", cspEnforcementFilter); filterRegistration.addMappingForUrlPatterns(null, false, "/*"); }  @Override void init(PieConfig pieConfig); @Override Policy getPolicy(); @Override PolicyConfig getPolicyConfig(); @Override void applyPolicy(ServletContext cx); @Override void shutdown();  }
@Test public void testApplyPolicy() { CspPolicyEnforcer cspPolicyEnforcer = new CspPolicyEnforcer(); cspPolicyEnforcer.init(new PieConfig()); FilterRegistration.Dynamic filterRegistration = createStrictMock(FilterRegistration.Dynamic.class); ServletContext servletContext = createStrictMock(ServletContext.class); expect(servletContext.addFilter(anyObject(String.class), anyObject(CspEnforcementFilter.class))) .andReturn(filterRegistration); filterRegistration.addMappingForUrlPatterns(null, false, "/*"); expectLastCall(); replay(servletContext, filterRegistration); cspPolicyEnforcer.applyPolicy(servletContext); verify(servletContext, filterRegistration); }