Class TrackerFieldsSupport
- java.lang.Object
-
- ru.vyarus.dropwizard.guice.test.jupiter.env.field.AnnotatedTestFieldSetup<TrackBean,Tracker>
-
- ru.vyarus.dropwizard.guice.test.jupiter.ext.track.TrackerFieldsSupport
-
- All Implemented Interfaces:
TestExecutionListener,TestEnvironmentSetup
public class TrackerFieldsSupport extends AnnotatedTestFieldSetup<TrackBean,Tracker>
TrackBeantest fields support implementation.Annotated fields resolved in time of guicey extension initialization (beforeAll or beforeEach). Register aop interceptor around target service to intercept all calls.
In beforeAll injects static values, in beforeEach inject both (in case if beforeAll wasn't called). Calls tracker reset after each test.
- Since:
- 11.02.2025
-
-
Field Summary
-
Fields inherited from class ru.vyarus.dropwizard.guice.test.jupiter.env.field.AnnotatedTestFieldSetup
appPerClass, FIELD_INJECTED, FIELD_MANUAL, fields, regTestClass, setupContext, setupContextName
-
-
Constructor Summary
Constructors Constructor Description TrackerFieldsSupport()Create support.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidafterEach(EventContext context)Called after each test method execution.protected voidafterTest(EventContext context, AnnotatedField<TrackBean,Tracker> field, Tracker value)Called after each test to post-process field value (if required).protected voidbeforeTest(EventContext context, AnnotatedField<TrackBean,Tracker> field, Tracker value)Called before each test to pre-process field value (if required).protected voidbeforeValueInjection(EventContext context, AnnotatedField<TrackBean,Tracker> field)Called after application startup and before field value injection.protected voidfieldDetected(org.junit.jupiter.api.extension.ExtensionContext context, AnnotatedField<TrackBean,Tracker> field)Validate resolved field, if required.protected <K> voidinitializeField(AnnotatedField<TrackBean,Tracker> field, Tracker userValue)Configure application for a field (user value might be provided).protected TrackerinjectFieldValue(EventContext context, AnnotatedField<TrackBean,Tracker> field)Get test field value (would be immediately injected into the test field).protected voidregisterHooks(TestExtension extension)Called to register additional guicey hooks, if required.protected voidreport(EventContext context, java.util.List<AnnotatedField<TrackBean,Tracker>> annotatedFields)Called when debug is enabled on guicey extension to report registered fields.-
Methods inherited from class ru.vyarus.dropwizard.guice.test.jupiter.env.field.AnnotatedTestFieldSetup
beforeAll, beforeEach, failIfInstanceFieldInitialized, getClassContext, getDeclarationErrorPrefix, getOwnFields, getParentFields, getStore, injectValues, isInstanceBinding, lookupFields, setup, started, starting, stopped, validateUnreachableFieldsInNestedTest, valueLifecycle
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface ru.vyarus.dropwizard.guice.test.jupiter.env.listen.TestExecutionListener
afterAll, stopping
-
-
-
-
Method Detail
-
fieldDetected
protected void fieldDetected(org.junit.jupiter.api.extension.ExtensionContext context, AnnotatedField<TrackBean,Tracker> field)Description copied from class:AnnotatedTestFieldSetupValidate resolved field, if required. Note that some validations are performed automatically like checking field type with provided required type or unreachable annotated fields reporting. This method should be used for validations, which are not possible to perform automatically (e.g., there is a class, declared in annotation that must comply with a field type (base class know nothing about annotation and can't check that).Called only for current test class own fields: in case of nested test, root test fields would already be validated. Also, if guice context started per each test method, validation would be called only for the first test method because fields would be searched just once - no need to validate each time.
- Specified by:
fieldDetectedin classAnnotatedTestFieldSetup<TrackBean,Tracker>- Parameters:
context- junit contextfield- annotated fields
-
registerHooks
protected void registerHooks(TestExtension extension)
Description copied from class:AnnotatedTestFieldSetupCalled to register additional guicey hooks, if required. Called only when at least one annotated field is detected.- Specified by:
registerHooksin classAnnotatedTestFieldSetup<TrackBean,Tracker>- Parameters:
extension- extension configuration object
-
initializeField
protected <K> void initializeField(AnnotatedField<TrackBean,Tracker> field, Tracker userValue)
Description copied from class:AnnotatedTestFieldSetupConfigure application for a field (user value might be provided). There might be field object instance creation (e.g. mocks initialization), guice overrides registration, etc. The main initialization point.NOTE: If user-provided values are not allowed, throw an exception here
- Specified by:
initializeFieldin classAnnotatedTestFieldSetup<TrackBean,Tracker>- Type Parameters:
K- type for aligning a binding key with value types (cheating on guice type checks)- Parameters:
field- annotated fielduserValue- user-provided field value (pre-initialized)
-
beforeValueInjection
protected void beforeValueInjection(EventContext context, AnnotatedField<TrackBean,Tracker> field)
Description copied from class:AnnotatedTestFieldSetupCalled after application startup and before field value injection. Useful for additional validations, which can't be performed before, like binding correctness validation (requiring the created injector): for example, to detect instance bindings when extension relies on AOP and so would not work. Such validation is impossible to do before (in time of binding overrides).Called before
AnnotatedTestFieldSetup.injectFieldValue(ru.vyarus.dropwizard.guice.test.jupiter.env.listen.EventContext, AnnotatedField). At this point, non-static fields could be resolved (test instance present).Important: method called for all fields, even initialized by user! Inject value method might not be called after it!
- Specified by:
beforeValueInjectionin classAnnotatedTestFieldSetup<TrackBean,Tracker>- Parameters:
context- event contextfield- annotated field
-
injectFieldValue
protected Tracker injectFieldValue(EventContext context, AnnotatedField<TrackBean,Tracker> field)
Description copied from class:AnnotatedTestFieldSetupGet test field value (would be immediately injected into the test field). Called only if field was not initialized by user (not a manual value). For example, implementation might simply get bean instance from guice context (if guice was re-configured with module overrides).Warning: not called for manually initialized fields (because value already set)! To validate binding use
AnnotatedTestFieldSetup.beforeValueInjection(ru.vyarus.dropwizard.guice.test.jupiter.env.listen.EventContext, AnnotatedField)method instead (which is called for all fields).Application already completely started and test extension initialized at this moment (beforeEach test phase).
- Specified by:
injectFieldValuein classAnnotatedTestFieldSetup<TrackBean,Tracker>- Parameters:
context- event contextfield- annotated field- Returns:
- created field value
-
report
protected void report(EventContext context, java.util.List<AnnotatedField<TrackBean,Tracker>> annotatedFields)
Description copied from class:AnnotatedTestFieldSetupCalled when debug is enabled on guicey extension to report registered fields. Note: there might be fields from multiple test classes in case of nested tests.Report called after application startup because at this point all fields were processed (in configure guice method) and so all required fields data collected. Called only if at least one field is detected.
Special custom data markers used in field objects (
AnnotatedField.getCustomData(String)):AnnotatedTestFieldSetup.FIELD_MANUALfield value was initialized by user, otherwise automaticAnnotatedTestFieldSetup.FIELD_INJECTEDfield injection instance (test instance)
- Specified by:
reportin classAnnotatedTestFieldSetup<TrackBean,Tracker>- Parameters:
context- event context, IMPORTANT - this would be setup context and not currentannotatedFields- fields to report
-
beforeTest
protected void beforeTest(EventContext context, AnnotatedField<TrackBean,Tracker> field, Tracker value)
Description copied from class:AnnotatedTestFieldSetupCalled before each test to pre-process field value (if required).- Specified by:
beforeTestin classAnnotatedTestFieldSetup<TrackBean,Tracker>- Parameters:
context- event contextfield- filed descriptorvalue- value instance
-
afterTest
protected void afterTest(EventContext context, AnnotatedField<TrackBean,Tracker> field, Tracker value)
Description copied from class:AnnotatedTestFieldSetupCalled after each test to post-process field value (if required).- Specified by:
afterTestin classAnnotatedTestFieldSetup<TrackBean,Tracker>- Parameters:
context- event contextfield- filed descriptorvalue- value instance
-
afterEach
public void afterEach(EventContext context)
Description copied from interface:TestExecutionListenerCalled after each test method execution. Even if an application is closed on afterEach, this method would be called before it.- Specified by:
afterEachin interfaceTestExecutionListener- Overrides:
afterEachin classAnnotatedTestFieldSetup<TrackBean,Tracker>- Parameters:
context- context object providing access to all required objects (junit context, injector, test support, etc.)
-
-