Class TestBeanStore
- All Implemented Interfaces:
AutoCloseable,BeanStore,WritableBeanStore
BasicBeanStore subclass for declaring test-time bean overrides.
A TestBeanStore is an overlay-builder. Tests register replacements for production beans
via override(java.lang.Class<T>, T) and then plug the resulting store into the SUT — typically through a
builder hook such as MockRestClient.Builder.overridingBeanStore(...) (the Mode INJECT wiring
pattern; see JuneauBeanStoreExtension for the full contract). The framework threads the
overlay into the overridingParent slot of the SUT's bean store, putting registered overrides
at tier 1 of the resolution chain (above local resource entries and the Spring bridge).
No JUnit 5 dependency. This class is intentionally a plain BasicBeanStore subclass
so that callers from non-JUnit harnesses (TestNG, raw main(...), Spring Test, etc.) can
use it without dragging in junit-jupiter-api.
Example:
See Also:
BasicBeanStore- The bean store this overlay extends.StackOverlay- The stack-aware composition primitive used for class-scope and Mode OVERLAY layering.JuneauBeanStoreExtension- Mode INJECT vs Mode OVERLAY contracts and the JUnit 5 lifecycle owner.
- Since:
- 10.0.0
-
Field Summary
Fields inherited from class org.apache.juneau.commons.inject.BasicBeanStore
INSTANCE -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescription<T> TestBeanStoreRegisters an unnamed supplier-backed bean as a test-time override.<T> TestBeanStoreRegisters a named supplier-backed bean as a test-time override.<T> TestBeanStoreRegisters an unnamed bean as a test-time override.<T> TestBeanStoreRegisters a named bean as a test-time override.Methods inherited from class org.apache.juneau.commons.inject.BasicBeanStore
add, add, addBean, addBean, addBeanType, addDefaultSupplier, addDefaultSupplier, addSupplier, addSupplier, clear, close, createBeanFromMethod, getBean, getBean, getBeansOfType, getBeanSupplier, getBeanSupplier, getBeanType, getDefaultSupplier, getDefaultSupplier, hasBean, hasBean, hasDefaultSupplier, hasDefaultSupplier, popOverlay, promoteDefaultsToLocalSuppliers, properties, pushOverlay, registerConfiguration, resolve, toStringMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface org.apache.juneau.commons.inject.BeanStore
createBeanFromMethod, getMissingParams, getParams, hasAllParams, instantiate, invokeBeanMethodMethods inherited from interface org.apache.juneau.commons.inject.WritableBeanStore
registerConfigurations
-
Constructor Details
-
TestBeanStore
public TestBeanStore()Constructor. -
TestBeanStore
Parent-chaining constructor.Lookups consult this store's local entries first and then fall through to the supplied parent. Used by
JuneauBeanStoreExtensionto stack a per-method overlay on top of a per-class overlay so method-scope overrides shadow class-scope overrides of the same(type, name)pair.- Parameters:
parent- The parent bean store. Can benull for a standalone overlay.- Since:
- 10.0.0
-
-
Method Details
-
override
Registers an unnamed bean as a test-time override.- Type Parameters:
T- The bean type.- Parameters:
type- The bean type. Must not benull .bean- The override instance. Can benull (stored as an explicitnull binding, distinct from no binding at all).- Returns:
- This object.
-
override
Registers a named bean as a test-time override.- Type Parameters:
T- The bean type.- Parameters:
type- The bean type. Must not benull .bean- The override instance. Can benull (stored as an explicitnull binding, distinct from no binding at all).name- The bean name. Can benull for unnamed beans.- Returns:
- This object.
-
override
Registers an unnamed supplier-backed bean as a test-time override.The supplier is invoked lazily on first lookup, mirroring
BasicBeanStore.addSupplier(java.lang.Class<T>, java.util.function.Supplier<T>).- Type Parameters:
T- The bean type.- Parameters:
type- The bean type. Must not benull .supplier- The override supplier. Must not benull .- Returns:
- This object.
-
override
Registers a named supplier-backed bean as a test-time override.The supplier is invoked lazily on first lookup, mirroring
BasicBeanStore.addSupplier(java.lang.Class<T>, java.util.function.Supplier<T>).- Type Parameters:
T- The bean type.- Parameters:
type- The bean type. Must not benull .supplier- The override supplier. Must not benull .name- The bean name. Can benull for unnamed beans.- Returns:
- This object.
-