SystemConfig { @Bean public WebMvcConfigurer corsConfigurer() { return new WebMvcConfigurer() { @Override public void addCorsMappings(final CorsRegistry registry) { registry.addMapping(CORS_MAPPING) .allowedOrigins(CORS_ALLOWED_ORIGINS) .allowedMethods(RequestMethod.GET.name(), RequestMethod.POST.name(), RequestMethod.PUT.name()) .allowedHeaders("*") .exposedHeaders(JwtFilter.HEADER_CLAIMS, JwtFilter.HEADER_CLAIMS_SUBJECT); } }; }  @Bean WebMvcConfigurer corsConfigurer();  }
@Test public void testCorsRegistration() { Mockito.when(mockCorsRegistration.allowedOrigins(SystemConfig.CORS_ALLOWED_ORIGINS)) .thenReturn(mockCorsRegistration); Mockito.when(mockCorsRegistry.addMapping(SystemConfig.CORS_MAPPING)).thenReturn(mockCorsRegistration); Mockito .when(mockCorsRegistration .allowedMethods(RequestMethod.GET.name(), RequestMethod.POST.name(), RequestMethod.PUT.name())) .thenReturn(mockCorsRegistration); Mockito.when(mockCorsRegistration.allowedHeaders("*")).thenReturn(mockCorsRegistration); Mockito.when(mockCorsRegistration.exposedHeaders(JwtFilter.HEADER_CLAIMS, JwtFilter.HEADER_CLAIMS_SUBJECT)) .thenReturn(mockCorsRegistration); final WebMvcConfigurer configurer = systemConfig.corsConfigurer(); configurer.addCorsMappings(mockCorsRegistry); Mockito.verify(mockCorsRegistry).addMapping(SystemConfig.CORS_MAPPING); Mockito.verify(mockCorsRegistration).allowedOrigins(SystemConfig.CORS_ALLOWED_ORIGINS); Mockito.verify(mockCorsRegistration) .allowedMethods(RequestMethod.GET.name(), RequestMethod.POST.name(), RequestMethod.PUT.name()); Mockito.verify(mockCorsRegistration).allowedHeaders("*"); Mockito.verify(mockCorsRegistration).exposedHeaders(JwtFilter.HEADER_CLAIMS, JwtFilter.HEADER_CLAIMS_SUBJECT); }