### Question:
EbayCorsFilterRegistration implements CorsFilterRegistration { @Override public void register(ServletContext context, CorsConfiguration config) { FilterRegistration.Dynamic filter = context.addFilter("cors", CORSFilter.class); addUrlPatterns(filter, config); addInitParameters(filter, config); }  @Override void register(ServletContext context, CorsConfiguration config);  }### Answer:
@Test public void shouldActuallyAddTheFilter() { CorsConfiguration config = new CorsConfiguration.Builder().build(); registration.register(mockContext, config); verify(mockContext).addFilter("cors", CORSFilter.class); }
@Test public void shouldSetCorrectInitParametersForConfiguration() { CorsConfiguration config = new CorsConfiguration.Builder() .allowedOrigins("origin1", "origin2") .allowedMethods("method1", "method2") .allowedHeaders("header1", "header2") .exposedHeaders("header3", "header4", "header5") .preflightMaxAge(100) .allowCredentials(false) .enableLogging(true) .build(); registration.register(mockContext, config); verify(mockFilterReg).setInitParameter("cors.allowed.origins", "origin1,origin2"); verify(mockFilterReg).setInitParameter("cors.allowed.methods", "method1,method2"); verify(mockFilterReg).setInitParameter("cors.allowed.headers", "header1,header2"); verify(mockFilterReg).setInitParameter("cors.exposed.headers", "header3,header4,header5"); verify(mockFilterReg).setInitParameter("cors.preflight.maxage", "100"); verify(mockFilterReg).setInitParameter("cors.support.credentials", "false"); verify(mockFilterReg).setInitParameter("cors.logging.enabled", "true"); verify(mockFilterReg).setInitParameter("cors.request.decorate", "false"); }
@Test public void shouldSetCorrectUrlPatternForConfiguration() { CorsConfiguration config = new CorsConfiguration.Builder() .urlPatterns("/test", "/data") .build(); registration.register(mockContext, config); verify(mockFilterReg).addMappingForUrlPatterns(null, false, "/test", "/data"); }