Interface AssertFactory<T,ASSERT extends Assert<?,?>>
- Type Parameters:
T
- the type of the given value.ASSERT
- the type of the resultingAssert
.
- All Known Implementing Classes:
InstanceOfAssertFactory
,ObjectAssertFactory
- Functional Interface:
- This is a functional interface and can therefore be used as the assignment target for a lambda expression or method reference.
Assert
instance for a given value of type AssertFactory
.
The createAssert(Object)
factory method typically wraps a call to
Assertions.assertThat(java.util.function.Predicate<T>)
.
More advanced use cases can be achieved via createAssert(ValueProvider)
,
where the provision of the value is externalized and the factory can require
explicit type compatibility for the value to be provided.
- Since:
- 2.5.0 / 3.5.0
- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeInterfaceDescriptionstatic interface
A provider that provides a value compatible with a givenType
. -
Method Summary
Modifier and TypeMethodDescriptiondefault ASSERT
createAssert
(AssertFactory.ValueProvider<? extends T> valueProvider) Creates the customAssert
instance for the value provided by the givenvalueProvider
.createAssert
(T actual) Creates the customAssert
instance for the given value.
-
Method Details
-
createAssert
Creates the customAssert
instance for the given value.Typically, this will just invoke
assertThat(actual)
.- Parameters:
actual
- the input value for theAssert
instance- Returns:
- the custom
Assert
instance for the given value
-
createAssert
Creates the customAssert
instance for the value provided by the givenvalueProvider
.This is typically used by custom assertions that want to leverage existing factories and need to manipulate the value upfront.
The default implementation always requests a value compatible with
Object
.Overriding implementations might provide a more specific
Type
instance to express the desired type of the value returned by the provider. When doing so, the factory is required to be consistent with the type parameterAssertFactory
.- Parameters:
valueProvider
- the value provider for theAssert
instance- Returns:
- the custom
Assert
instance for the value provided by the given value provider - Since:
- 3.26.0
-