Class PropertySupport

java.lang.Object
de.cuioss.test.valueobjects.property.PropertySupport

public class PropertySupport extends Object
Stateful wrapper around instances of PropertyMetadata that provides methods for reading / asserting properties according to the configured PropertyAccessStrategy, see apply(Object), assertValueSet(Object) and assertDefaultValue(Object) . In addition it can create / store an instant specific generatedValue, see generateTestValue()
Author:
Oliver Wolff
  • Constructor Details

  • Method Details

    • isReadable

      public boolean isReadable()
      Returns:
      boolean indicating whether the current property is readable
    • isDefaultValue

      public boolean isDefaultValue()
      Returns:
      boolean indicating whether the current property is defaultValued
    • isRequired

      public boolean isRequired()
      Returns:
      boolean indicating whether the current property is required
    • getName

      public String getName()
      Returns:
      the name of the property
    • isPrimitive

      public boolean isPrimitive()
      Returns:
      boolean indicating whether the current property is a primitive
    • generateTestValue

      Generates a value from the contained generator and sets it to #setGeneratedValue(Object).
      Returns:
      the generated test value
    • reset

      public void reset()
      Resets the generated value
    • apply

      public void apply(Object target)
      Writes the property, previously initialized with generateTestValue() to the given target, using the configured PropertyAccessStrategy
      Parameters:
      target - must not be null
    • assertValueSet

      public void assertValueSet(Object target)
      Asserts that the value previously set by apply(Object) is accessible by the corresponding read-method, e.g getProperty
      Parameters:
      target - must not be null
    • assertValueSet

      public void assertValueSet(Object target, Object expected)
      Asserts that the expected value is accessible by the corresponding read-method, e.g getProperty
      Parameters:
      target - must not be null
      expected - the expected content of the attribute
    • readProperty

      public Object readProperty(Object target)
      Reads and returns the read property from the given target
      Parameters:
      target - to be read from, must not be null
      Returns:
      he read Property, may be null
    • writeProperty

      public Object writeProperty(Object target, Object propertyValue)
      Writes the given property the given target
      Parameters:
      target - to be written to, must not be null
      propertyValue - to be written
      Returns:
      he read Property, may be null
    • assertDefaultValue

      public void assertDefaultValue(Object target)
      Asserts that the given object provides a default value.
      Parameters:
      target - must not be null
    • createCopy

      public PropertySupport createCopy(boolean withGeneratedValue)
      Creates a copy of this instance
      Parameters:
      withGeneratedValue - indicating whether to copy the currently #getGeneratedValue()
      Returns:
      the created copy
    • createCopyWithNonEqualValue

      Creates a copy of this instance. In addition it tries to create a generatedValue that is not equal to the contained one. It will try this 50 times and will then throw an AssertionError
      Returns:
      the created copy