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 Details

    • ATOMIC

      public static final String ATOMIC
      See Also:
    • namespace

      protected final org.junit.jupiter.api.extension.ExtensionContext.Namespace namespace
  • Constructor Details

    • UniqueStringExtension

      public UniqueStringExtension()
      Default constructor.
  • Method Details

    • beforeAll

      public void beforeAll(org.junit.jupiter.api.extension.ExtensionContext context) throws Exception
      Handles the beforeAll case. Setting up the context.
      Specified by:
      beforeAll in interface org.junit.jupiter.api.extension.BeforeAllCallback
      Parameters:
      context - the current extension context; never null
      Throws:
      Exception - if anything goes wrong.
    • beforeEach

      public void beforeEach(org.junit.jupiter.api.extension.ExtensionContext context) throws Exception
      Handles the before each case. Setting the vars in the object.
      Specified by:
      beforeEach in interface org.junit.jupiter.api.extension.BeforeEachCallback
      Parameters:
      context - the current extension context; never null
      Throws:
      Exception - if anything goes wrong.
    • uniqueFields

      public Set<Field> uniqueFields(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(String value, Object object, 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(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.