@@ -0,0 +1,1988 @@
+/*%0A * Copyright 2002-2017 the original author or authors.%0A *%0A * Licensed under the Apache License, Version 2.0 (the %22License%22);%0A * you may not use this file except in compliance with the License.%0A * You may obtain a copy of the License at%0A *%0A *      https://www.apache.org/licenses/LICENSE-2.0%0A *%0A * Unless required by applicable law or agreed to in writing, software%0A * distributed under the License is distributed on an %22AS IS%22 BASIS,%0A * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.%0A * See the License for the specific language governing permissions and%0A * limitations under the License.%0A */%0A%0Apackage org.springframework.security.config.test;%0A%0Aimport java.lang.reflect.Field;%0Aimport java.util.ArrayList;%0Aimport java.util.List;%0A%0Aimport org.junit.jupiter.api.extension.AfterEachCallback;%0Aimport org.junit.jupiter.api.extension.BeforeEachCallback;%0Aimport org.junit.jupiter.api.extension.ExtensionContext;%0A%0Aimport org.springframework.security.test.context.TestSecurityContextHolder;%0A%0Apublic class SpringTestContextExtension implements BeforeEachCallback, AfterEachCallback %7B%0A%0A%09@Override%0A%09public void afterEach(ExtensionContext context) throws Exception %7B%0A%09%09TestSecurityContextHolder.clearContext();%0A%09%09getContexts(context.getRequiredTestInstance()).forEach((springTestContext) -%3E springTestContext.close());%0A%09%7D%0A%0A%09@Override%0A%09public void beforeEach(ExtensionContext context) throws Exception %7B%0A%09%09Object testInstance = context.getRequiredTestInstance();%0A%09%09getContexts(testInstance).forEach((springTestContext) -%3E springTestContext.setTest(testInstance));%0A%09%7D%0A%0A%09private static List%3CSpringTestContext%3E getContexts(Object test) throws IllegalAccessException %7B%0A%09%09Field%5B%5D declaredFields = test.getClass().getDeclaredFields();%0A%09%09List%3CSpringTestContext%3E result = new ArrayList%3C%3E();%0A%09%09for (Field field : declaredFields) %7B%0A%09%09%09if (SpringTestContext.class.isAssignableFrom(field.getType())) %7B%0A%09%09%09%09result.add((SpringTestContext) field.get(test));%0A%09%09%09%7D%0A%09%09%7D%0A%09%09return result;%0A%09%7D%0A%0A%7D%0A

Add SpringTestContextExtension