Package com.codeheadsystems.test.unique
Class UniqueStringExtension
java.lang.Object
com.codeheadsystems.test.unique.UniqueStringExtension
- All Implemented Interfaces:
org.junit.jupiter.api.extension.BeforeAllCallback,org.junit.jupiter.api.extension.BeforeEachCallback,org.junit.jupiter.api.extension.Extension
public class UniqueStringExtension
extends Object
implements org.junit.jupiter.api.extension.BeforeEachCallback, org.junit.jupiter.api.extension.BeforeAllCallback
Provides for a unique string that is valid for the tests.
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidbeforeAll(org.junit.jupiter.api.extension.ExtensionContext context) Handles the beforeAll case.voidbeforeEach(org.junit.jupiter.api.extension.ExtensionContext context) Handles the before each case.protected voidenableSettingTheField(Field field) This allows us to set the field directly.protected voidsetValueForField(String value, Object object, Field field) Sets the value for the field.uniqueFields(Class<?> clazz) Gets all unique annotation fields for this class and its super class.
-
Field Details
-
ATOMIC
The constant ATOMIC.- See Also:
-
namespace
protected final org.junit.jupiter.api.extension.ExtensionContext.Namespace namespaceThe Namespace.
-
-
Constructor Details
-
UniqueStringExtension
public UniqueStringExtension()Default constructor.
-
-
Method Details
-
beforeAll
Handles the beforeAll case. Setting up the context.- Specified by:
beforeAllin interfaceorg.junit.jupiter.api.extension.BeforeAllCallback- Parameters:
context- the current extension context; nevernull- Throws:
Exception- if anything goes wrong.
-
beforeEach
Handles the before each case. Setting the vars in the object.- Specified by:
beforeEachin interfaceorg.junit.jupiter.api.extension.BeforeEachCallback- Parameters:
context- the current extension context; nevernull- Throws:
Exception- if anything goes wrong.
-
uniqueFields
Gets all unique annotation fields for this class and its super class.- Parameters:
clazz- to check.- Returns:
- set of fields.
-
setValueForField
Sets the value for the field. Really this just ignores the exception.- Parameters:
value- to set.object- on this object.field- in this field.
-
enableSettingTheField
This allows us to set the field directly. It will fail if the security manager in play disallows it. We can talk about justifications all we want, but really we know Java is not Smalltalk. Meta programming is limited here. So... we try to do the right thing.- Parameters:
field- to change accessibility for.
-