public final class AndHowTestUtils extends Object
THIS CLASS CAN DO DANGEROUS THINGS THAT SHOULD NEVER BE DONE NEAR APPLICATION CODE
In production, AndHow is singleton that is only initialized once. Application code depends on that behaviour because it assumes that its basic configuration does not change. If it seems like you need to use the utilities here in production - STOP - you are doing it wrong. See the AndHow documentation and usage examples instead.The methods in this class are generally not needed (directly) for testing. They are used by JUnit extensions that use them in a controlled and predictable way so that your application is configured correctly during testing. Many of methods in this class are used in the testing of the AndHow framework itself, thus, it has no dependency on AndHow and many methods take and return 'Object' types rather than specific AndHow classes.
For examples using JUnit extensions and annotations, see the AndHow Sample Usages module and its many sub-modules, which are stand-alone simulated projects complete with testing.
| Modifier and Type | Method and Description |
|---|---|
static Object |
getAndHow()
The current AndHow singleton instance, without forcing its creation.
|
static Class<?> |
getAndHowClass()
Get the Class> of AndHow - needed since this module has no AndHow dependency.
|
static Class<?> |
getAndHowConfigurationClass()
Get the Class> of AndHowConfiguration - needed since this module has no AndHow dependency.
|
static Object |
getAndHowCore()
The current AndHow singleton's 'Core' object.
|
static Class<?> |
getAndHowCoreClass()
Get the Class> of AndHowCore - needed since this module has no AndHow dependency.
|
static ThreadLocal<Boolean> |
getFindingConfig()
The AndHow 'findingConfig' flag, which indicates that AndHow is search for its configuration
and blocks reentrent loops.
|
static Object |
invokeAndHowInstance()
Invoke AndHow.instance(), returning an AndHow instance and forcing initiation
if AndHow is not already initiated.
|
static void |
killAndHowFully()
Kill AndHow to ground state, as it would be prior to any initialization.
|
static <T> T |
setAndHow(T newAndHow)
Set the AndHow singleton instance and return the previous one.
|
static <T> UnaryOperator<T> |
setAndHowConfigLocator(UnaryOperator<T> newLocator)
Set a locator to find AndHowConfiguration.
|
static <T> T |
setAndHowCore(T newCore)
Set the AndHow 'Core'.
|
static <T> T |
setAndHowInitialization(T newInit)
Force AndHow.Initialization (its debug info about initialization) to a new value.
|
static Boolean |
setAndHowInitializing(Boolean newInitializingStatus)
Force the AndHow 'initializing flag' - If true, AndHow is in the process of initialization.
|
static <T> T |
setAndHowInProcessConfig(T newConfig)
Forces the AndHow inProcessConfig to a new value.
|
public static void killAndHowFully()
public static Object invokeAndHowInstance()
public static Object getAndHow()
public static <T> T setAndHow(T newAndHow)
Since this module has no dependency on AndHow, the return and arg types are 'Object'.
T - implicitly passed type of the instance, which must be type AndHow.newAndHow - An AndHow instance to use as the current singleton instance,
which may be null, but must be of type AndHow.public static Object getAndHowCore()
public static <T> T setAndHowCore(T newCore)
T - implicitly passed type of the core which must be type AndHowCore.newCore - The new core to assign to the AndHow singleton which may be null but must
be of type AndHowCore.public static <T> T setAndHowInitialization(T newInit)
T - implicitly passed type of the newInit which must be type AndHow.Initialization.newInit - The new initialization to assign which may be null, but must be of type
AndHow.Initialization.public static <T> UnaryOperator<T> setAndHowConfigLocator(UnaryOperator<T> newLocator)
AndHowUtil.findConfiguration(c), however, if a locator
is set to nonnull, it will be used instead.
The locator takes a default Configuration to return if a configuration cannot
be found otherwise. See org.yarnandtail.AndHow#findConfig() for details.
Example setting to a custom locator:
setAndHowConfigLocator(c -> return MyConfig);
Example setting back to null:
setAndHowConfigLocator(null);
If this is set to some custom value for testing, it must be set back to null or future initialization will use the custom locator.
T - implicit type of the newLocator, which must be
UnaryOperator<AndHowConfiguration<? extends AndHowConfiguration>>newLocator - The new locator to use, which may be null, but must be of type
UnaryOperator<AndHowConfiguration<? extends AndHowConfiguration>>public static <T> T setAndHowInProcessConfig(T newConfig)
T - The implicit type, which must be of type
AndHowConfiguration<? extends AndHowConfiguration>newConfig - The new configuration to have in-process, which may be null, but
must be of type AndHowConfiguration<? extends AndHowConfiguration>public static Boolean setAndHowInitializing(Boolean newInitializingStatus)
newInitializingStatus - non-null boolean value.public static ThreadLocal<Boolean> getFindingConfig()
public static Class<?> getAndHowClass()
public static Class<?> getAndHowCoreClass()
public static Class<?> getAndHowConfigurationClass()
Copyright © 2022. All rights reserved.