From 64c3ad363425da934c012db4cfdc7d20a8f5a9cb Mon Sep 17 00:00:00 2001 From: Sam Brannen Date: Sat, 30 Jul 2022 11:09:07 +0300 Subject: [PATCH] Make BootstrapUtils.resolveTestContextBootstrapper() public Closes gh-28891 --- .../test/context/BootstrapUtils.java | 25 ++++++++++++++++++- .../test/context/TestContextManager.java | 4 +-- 2 files changed, 26 insertions(+), 3 deletions(-) diff --git a/spring-test/src/main/java/org/springframework/test/context/BootstrapUtils.java b/spring-test/src/main/java/org/springframework/test/context/BootstrapUtils.java index 0336e4d513c..6d0b5aabe70 100644 --- a/spring-test/src/main/java/org/springframework/test/context/BootstrapUtils.java +++ b/spring-test/src/main/java/org/springframework/test/context/BootstrapUtils.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2021 the original author or authors. + * Copyright 2002-2022 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -35,6 +35,8 @@ import org.springframework.util.StringUtils; * {@code BootstrapUtils} is a collection of utility methods to assist with * bootstrapping the Spring TestContext Framework. * + *

Only intended for internal use. + * * @author Sam Brannen * @author Phillip Webb * @since 4.1 @@ -114,6 +116,27 @@ abstract class BootstrapUtils { } } + /** + * Resolve the {@link TestContextBootstrapper} type for the supplied test class + * using the default {@link BootstrapContext}, instantiate the bootstrapper, + * and provide it a reference to the {@code BootstrapContext}. + *

If the {@link BootstrapWith @BootstrapWith} annotation is present on + * the test class, either directly or as a meta-annotation, then its + * {@link BootstrapWith#value value} will be used as the bootstrapper type. + * Otherwise, either the + * {@link org.springframework.test.context.support.DefaultTestContextBootstrapper + * DefaultTestContextBootstrapper} or the + * {@link org.springframework.test.context.web.WebTestContextBootstrapper + * WebTestContextBootstrapper} will be used, depending on the presence of + * {@link org.springframework.test.context.web.WebAppConfiguration @WebAppConfiguration}. + * @param testClass the test class for which the bootstrapper should be created + * @return a fully configured {@code TestContextBootstrapper} + * @since 6.0 + */ + public static TestContextBootstrapper resolveTestContextBootstrapper(Class testClass) { + return resolveTestContextBootstrapper(createBootstrapContext(testClass)); + } + /** * Resolve the {@link TestContextBootstrapper} type for the test class in the * supplied {@link BootstrapContext}, instantiate it, and provide it a reference diff --git a/spring-test/src/main/java/org/springframework/test/context/TestContextManager.java b/spring-test/src/main/java/org/springframework/test/context/TestContextManager.java index d93b78d88d5..8eb384abdbe 100644 --- a/spring-test/src/main/java/org/springframework/test/context/TestContextManager.java +++ b/spring-test/src/main/java/org/springframework/test/context/TestContextManager.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2021 the original author or authors. + * Copyright 2002-2022 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -119,7 +119,7 @@ public class TestContextManager { * @see #TestContextManager(TestContextBootstrapper) */ public TestContextManager(Class testClass) { - this(BootstrapUtils.resolveTestContextBootstrapper(BootstrapUtils.createBootstrapContext(testClass))); + this(BootstrapUtils.resolveTestContextBootstrapper(testClass)); } /**