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 java.lang.Object implements org.junit.jupiter.api.extension.BeforeEachCallback, org.junit.jupiter.api.extension.BeforeAllCallbackProvides for a unique string that is valid for the tests.
-
-
Constructor Summary
Constructors Constructor Description UniqueStringExtension()Default constructor.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidbeforeAll(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(java.lang.reflect.Field field)This allows us to set the field directly.protected voidsetValueForField(java.lang.String value, java.lang.Object object, java.lang.reflect.Field field)Sets the value for the field.java.util.Set<java.lang.reflect.Field>uniqueFields(java.lang.Class<?> clazz)Gets all unique annotation fields for this class and its super class.
-
-
-
Field Detail
-
ATOMIC
public static final java.lang.String ATOMIC
The constant ATOMIC.- See Also:
- Constant Field Values
-
namespace
protected final org.junit.jupiter.api.extension.ExtensionContext.Namespace namespace
The Namespace.
-
-
Method Detail
-
beforeAll
public void beforeAll(org.junit.jupiter.api.extension.ExtensionContext context) throws java.lang.ExceptionHandles the beforeAll case. Setting up the context.- Specified by:
beforeAllin interfaceorg.junit.jupiter.api.extension.BeforeAllCallback- Parameters:
context- the current extension context; nevernull- Throws:
java.lang.Exception- if anything goes wrong.
-
beforeEach
public void beforeEach(org.junit.jupiter.api.extension.ExtensionContext context) throws java.lang.ExceptionHandles 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:
java.lang.Exception- if anything goes wrong.
-
uniqueFields
public java.util.Set<java.lang.reflect.Field> uniqueFields(java.lang.Class<?> clazz)
Gets all unique annotation fields for this class and its super class.- Parameters:
clazz- to check.- Returns:
- set of fields.
-
setValueForField
protected void setValueForField(java.lang.String value, java.lang.Object object, java.lang.reflect.Field field)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
protected void enableSettingTheField(java.lang.reflect.Field field)
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.
-
-