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.
@FunctionalInterface public interface AssertFactory<T,ASSERT extends Assert<?,?>>A factory that creates anAssertinstance for a given value of typeAssertFactory.The
createAssert(Object)factory method typically wraps a call toAssertions.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:
InstanceOfAssertFactory
-
-
Nested Class Summary
Nested Classes Modifier and Type Interface Description static interfaceAssertFactory.ValueProvider<T>A provider that provides a value compatible with a givenType.
-
Method Summary
All Methods Instance Methods Abstract Methods Default Methods Modifier and Type Method Description default ASSERTcreateAssert(AssertFactory.ValueProvider<? extends T> valueProvider)Creates the customAssertinstance for the value provided by the givenvalueProvider.ASSERTcreateAssert(T actual)Creates the customAssertinstance for the given value.
-
-
-
Method Detail
-
createAssert
ASSERT createAssert(T actual)
Creates the customAssertinstance for the given value.Typically, this will just invoke
assertThat(actual).- Parameters:
actual- the input value for theAssertinstance- Returns:
- the custom
Assertinstance for the given value
-
createAssert
default ASSERT createAssert(AssertFactory.ValueProvider<? extends T> valueProvider)
Creates the customAssertinstance 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
Typeinstance 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 theAssertinstance- Returns:
- the custom
Assertinstance for the value provided by the given value provider - Since:
- 3.26.0
-
-