Package de.cuioss.test.valueobjects
Class ValueObjectTest<T>
java.lang.Object
de.cuioss.test.valueobjects.PropertyAwareTest<T>
de.cuioss.test.valueobjects.ValueObjectTest<T>
- Type Parameters:
T
- identifying the type to be tested is usually but not necessarily at leastSerializable
.
- All Implemented Interfaces:
ObjectContractTestSupport
,GeneratorRegistry
Base-class for running tests on value-objects. It runs two type of tests:
- Tests for the canonical
Object
methodsObject.equals(Object)
,Object.hashCode()
andObject.toString()
with each test can be vetoed usingVetoObjectTestContract
at type-level. Seede.cuioss.test.valueobjects.api.object
for details - Individual contract-testing like
VerifyBeanProperty
orVerifyFactoryMethod
, seede.cuioss.test.valueobjects.api.contracts
for details.
Configuration
See PropertyAwareTest
for details on configuring
PropertyMetadata
and TypedGenerator
de.cuioss.test.valueobjects.junit5
- Author:
- Oliver Wolff
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected T
This method can be used in two ways: In case you have at least de.cuioss.test.valueobjects.api.contracts configured this method will implicitly return an arbitraryObject
of the implicitly created underlyingParameterizedInstantiator
In case you have noParameterizedInstantiator
configured you can implement this method for feeding theshouldImplementObjectContracts()
void
Initializes all contractsprotected List<TestContract<T>>
resolveTestContracts
(List<PropertyMetadata> initialMetadata) Resolves the concreteTestContract
s to be tested.void
Base test for ValueObjects verifying the correctness ofObject.equals(Object)
Object.hashCode()
,Object.toString()
andSerializable
implementations.final void
Tests all configuredTestContract
s.Methods inherited from class de.cuioss.test.valueobjects.PropertyAwareTest
initializePropertiesAndGenerators, resolvePropertyMetadata
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface de.cuioss.test.valueobjects.util.GeneratorRegistry
registerAdditionalGenerators
-
Constructor Details
-
ValueObjectTest
public ValueObjectTest()
-
-
Method Details
-
initializeBaseClass
Initializes all contracts -
resolveTestContracts
Resolves the concreteTestContract
s to be tested. They are derived by the corresponding annotations- Parameters:
initialMetadata
-- Returns:
-
shouldImplementObjectContracts
Description copied from interface:ObjectContractTestSupport
Base test for ValueObjects verifying the correctness of
Object.equals(Object)
Object.hashCode()
,Object.toString()
andSerializable
implementations.If you want to disable one of these tests you can annotate the test class with
VetoObjectTestContract
with the valueObjectTestContracts.EQUALS_AND_HASHCODE
,ObjectTestContracts.SERIALIZABLE
orObjectTestContracts.TO_STRING
- Specified by:
shouldImplementObjectContracts
in interfaceObjectContractTestSupport
-
shouldVerifyTestContracts
Tests all configured
TestContract
s. The individual contracts are to be configured using class level annotations or overwriting resolveTestContracts(SortedSet) -
anyValueObject
This method can be used in two ways:- In case you have at least de.cuioss.test.valueobjects.api.contracts
configured this method will implicitly return an arbitrary
Object
of the implicitly created underlyingParameterizedInstantiator
- In case you have no
ParameterizedInstantiator
configured you can implement this method for feeding theshouldImplementObjectContracts()
- Returns:
- a concrete valueObject, or null
- In case you have at least de.cuioss.test.valueobjects.api.contracts
configured this method will implicitly return an arbitrary
-