Interface AssertFactory<T,ASSERT extends Assert<?,?>>

Type Parameters:
T - the type of the given value.
ASSERT - the type of the resulting Assert.
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 an 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 Classes
    Modifier and Type
    Interface
    Description
    static interface 
    A provider that provides a value compatible with a given Type.
  • Method Summary

    Modifier and Type
    Method
    Description
    default ASSERT
    createAssert(AssertFactory.ValueProvider<? extends T> valueProvider)
    Creates the custom Assert instance for the value provided by the given valueProvider.
    createAssert(T actual)
    Creates the custom Assert instance for the given value.
  • Method Details

    • createAssert

      ASSERT createAssert(T actual)
      Creates the custom Assert instance for the given value.

      Typically, this will just invoke assertThat(actual).

      Parameters:
      actual - the input value for the Assert instance
      Returns:
      the custom Assert instance for the given value
    • createAssert

      default ASSERT createAssert(AssertFactory.ValueProvider<? extends T> valueProvider)
      Creates the custom Assert instance for the value provided by the given valueProvider.

      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 parameter AssertFactory.

      Parameters:
      valueProvider - the value provider for the Assert instance
      Returns:
      the custom Assert instance for the value provided by the given value provider
      Since:
      3.26.0