Class TestConstructorUtils
java.lang.Object
org.springframework.test.context.support.TestConstructorUtils
Utility methods for working with
@TestConstructor
.
Primarily intended for use within the framework.
- Since:
- 5.2
- Author:
- Sam Brannen, Florian Lehmann
- See Also:
-
Method Summary
Modifier and TypeMethodDescriptionstatic boolean
isAutowirableConstructor
(Constructor<?> constructor, Class<?> testClass) Determine if the supplied constructor for the given test class is autowirable.static boolean
isAutowirableConstructor
(Constructor<?> constructor, Class<?> testClass, PropertyProvider fallbackPropertyProvider) Determine if the supplied constructor for the given test class is autowirable.static boolean
isAutowirableConstructor
(Executable executable, Class<?> testClass) Determine if the supplied executable for the given test class is an autowirable constructor.static boolean
isAutowirableConstructor
(Executable executable, Class<?> testClass, PropertyProvider fallbackPropertyProvider) Determine if the supplied executable for the given test class is an autowirable constructor.
-
Method Details
-
isAutowirableConstructor
Determine if the supplied executable for the given test class is an autowirable constructor.This method delegates to
isAutowirableConstructor(Executable, Class, PropertyProvider)
will a value ofnull
for the fallbackPropertyProvider
.- Parameters:
executable
- an executable for the test classtestClass
- the test class- Returns:
true
if the executable is an autowirable constructor- See Also:
-
isAutowirableConstructor
Determine if the supplied constructor for the given test class is autowirable.This method delegates to
isAutowirableConstructor(Constructor, Class, PropertyProvider)
will a value ofnull
for the fallbackPropertyProvider
.- Parameters:
constructor
- a constructor for the test classtestClass
- the test class- Returns:
true
if the constructor is autowirable- See Also:
-
isAutowirableConstructor
public static boolean isAutowirableConstructor(Executable executable, Class<?> testClass, @Nullable PropertyProvider fallbackPropertyProvider) Determine if the supplied executable for the given test class is an autowirable constructor.This method delegates to
isAutowirableConstructor(Constructor, Class, PropertyProvider)
if the supplied executable is a constructor and otherwise returnsfalse
.- Parameters:
executable
- an executable for the test classtestClass
- the test classfallbackPropertyProvider
- fallback property provider used to look up the value forTestConstructor.TEST_CONSTRUCTOR_AUTOWIRE_MODE_PROPERTY_NAME
if no such value is found inSpringProperties
- Returns:
true
if the executable is an autowirable constructor- Since:
- 5.3
- See Also:
-
isAutowirableConstructor
public static boolean isAutowirableConstructor(Constructor<?> constructor, Class<?> testClass, @Nullable PropertyProvider fallbackPropertyProvider) Determine if the supplied constructor for the given test class is autowirable.A constructor is considered to be autowirable if one of the following conditions is
true
.- The constructor is annotated with
@Autowired
,@jakarta.inject.Inject
, or@javax.inject.Inject
. @TestConstructor
is present or meta-present on the test class withautowireMode
set toALL
.- The default test constructor autowire mode has been set to
ALL
inSpringProperties
or in the supplied fallbackPropertyProvider
(seeTestConstructor.TEST_CONSTRUCTOR_AUTOWIRE_MODE_PROPERTY_NAME
).
- Parameters:
constructor
- a constructor for the test classtestClass
- the test classfallbackPropertyProvider
- fallback property provider used to look up the value for the default test constructor autowire mode if no such value is found inSpringProperties
- Returns:
true
if the constructor is autowirable- Since:
- 5.3
- The constructor is annotated with
-