Class 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.BeforeAllCallback
    Provides for a unique string that is valid for the tests.
    • Field Summary

      Fields 
      Modifier and Type Field Description
      static java.lang.String ATOMIC
      The constant ATOMIC.
      protected org.junit.jupiter.api.extension.ExtensionContext.Namespace namespace
      The Namespace.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void beforeAll​(org.junit.jupiter.api.extension.ExtensionContext context)
      Handles the beforeAll case.
      void beforeEach​(org.junit.jupiter.api.extension.ExtensionContext context)
      Handles the before each case.
      protected void enableSettingTheField​(java.lang.reflect.Field field)
      This allows us to set the field directly.
      protected void setValueForField​(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.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • 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.
    • Constructor Detail

      • UniqueStringExtension

        public UniqueStringExtension()
        Default constructor.
    • Method Detail

      • beforeAll

        public void beforeAll​(org.junit.jupiter.api.extension.ExtensionContext context)
                       throws java.lang.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:
        java.lang.Exception - if anything goes wrong.
      • beforeEach

        public void beforeEach​(org.junit.jupiter.api.extension.ExtensionContext context)
                        throws java.lang.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:
        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.