Class InstanceOfAssertFactory<T,​ASSERT extends AbstractAssert<?,​?>>

  • Type Parameters:
    T - the type to use for the cast.
    ASSERT - the type of the resulting Assert.
    All Implemented Interfaces:
    AssertFactory<java.lang.Object,​ASSERT>

    public class InstanceOfAssertFactory<T,​ASSERT extends AbstractAssert<?,​?>>
    extends java.lang.Object
    implements AssertFactory<java.lang.Object,​ASSERT>
    AssertFactory decorator that casts the input value to the given type before invoking the decorated factory.
    Since:
    3.13.0
    • Field Detail

      • type

        private final java.lang.reflect.Type type
      • rawClass

        private final java.lang.Class<T> rawClass
    • Constructor Detail

      • InstanceOfAssertFactory

        public InstanceOfAssertFactory​(java.lang.Class<T> type,
                                       AssertFactory<T,​ASSERT> delegate)
        Instantiates a new InstanceOfAssertFactory for a given type.
        Parameters:
        type - the Class instance of the given type.
        delegate - the AssertFactory to decorate.
      • InstanceOfAssertFactory

        public InstanceOfAssertFactory​(java.lang.Class<T> rawClass,
                                       java.lang.reflect.Type[] typeArguments,
                                       AssertFactory<T,​ASSERT> delegate)
        Instantiates a new InstanceOfAssertFactory for a given type with type arguments.
        Parameters:
        rawClass - the raw Class instance of the given type.
        typeArguments - the Type arguments of the given type.
        delegate - the AssertFactory to decorate.
        Since:
        3.26.0
      • InstanceOfAssertFactory

        private InstanceOfAssertFactory​(java.lang.reflect.Type type,
                                        java.lang.Class<T> rawClass,
                                        AssertFactory<T,​ASSERT> delegate)
    • Method Detail

      • getRawClass

        java.lang.Class<T> getRawClass()
      • createAssert

        public ASSERT createAssert​(java.lang.Object actual)
        Creates the custom Assert instance for the given value.

        Before invoking the delegate, the factory casts the value to the raw Class defined during instantiation.

        Specified by:
        createAssert in interface AssertFactory<T,​ASSERT extends AbstractAssert<?,​?>>
        Parameters:
        actual - the input value for the Assert instance
        Returns:
        the custom Assert instance for the given value
      • createAssert

        public ASSERT createAssert​(AssertFactory.ValueProvider<?> 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.

        This implementation requests a value compatible with the Type defined during instantiation and casts the provided value to the corresponding raw Class before invoking the delegate.

        Specified by:
        createAssert in interface AssertFactory<T,​ASSERT extends AbstractAssert<?,​?>>
        Parameters:
        valueProvider - the value provider for the Assert instance
        Returns:
        the custom Assert instance for the provided value
        Since:
        3.26.0
      • toString

        public java.lang.String toString()
        Overrides:
        toString in class java.lang.Object