Class PropertySupport
java.lang.Object
de.cuioss.test.valueobjects.property.PropertySupport
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 Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoid
Writes the property, previously initialized withgenerateTestValue()
to the given target, using the configuredPropertyAccessStrategy
void
assertDefaultValue
(Object target) Asserts that the given object provides a default value.void
assertValueSet
(Object target) Asserts that the value previously set byapply(Object)
is accessible by the corresponding read-method, e.g getPropertyvoid
assertValueSet
(Object target, Object expected) Asserts that the expected value is accessible by the corresponding read-method, e.g getPropertycreateCopy
(boolean withGeneratedValue) Creates a copy of this instanceCreates a copy of this instance.Generates a value from the contained generator and sets it to#setGeneratedValue(Object)
.getName()
boolean
boolean
boolean
boolean
readProperty
(Object target) Reads and returns the read property from the given targetvoid
reset()
Resets the generated valuewriteProperty
(Object target, Object propertyValue) Writes the given property the given target
-
Constructor Details
-
PropertySupport
public PropertySupport()
-
-
Method Details
-
isReadable
- Returns:
- boolean indicating whether the current property is readable
-
isDefaultValue
- Returns:
- boolean indicating whether the current property is defaultValued
-
isRequired
- Returns:
- boolean indicating whether the current property is required
-
getName
- Returns:
- the name of the property
-
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
Resets the generated value -
apply
Writes the property, previously initialized withgenerateTestValue()
to the given target, using the configuredPropertyAccessStrategy
- Parameters:
target
- must not be null
-
assertValueSet
Asserts that the value previously set byapply(Object)
is accessible by the corresponding read-method, e.g getProperty- Parameters:
target
- must not be null
-
assertValueSet
Asserts that the expected value is accessible by the corresponding read-method, e.g getProperty- Parameters:
target
- must not be nullexpected
- the expected content of the attribute
-
readProperty
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
Writes the given property the given target- Parameters:
target
- to be written to, must not be nullpropertyValue
- to be written- Returns:
- he read Property, may be
null
-
assertDefaultValue
Asserts that the given object provides a default value.- Parameters:
target
- must not be null
-
createCopy
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 anAssertionError
- Returns:
- the created copy
-