Top Description Inners Methods
org.assertj.core.api

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

Known Direct Implementers
org.assertj.core.api.InstanceOfAssertFactory, org.assertj.core.api.ObjectAssertFactory
Annotations
@FunctionalInterface
Type Parameters
<T>
the type of the given value.
<ASSERT>
the type of the resulting Assert.
Imports
java.lang.reflect.ParameterizedType, .Type, java.util.function.Function

A factory that creates an Assert instance for a given value of type T.

The createAssert(Object) factory method typically wraps a call to Assertions#assertThat.

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 and Inner Type Summary

Modifier and TypeClass and Description
public static interface
AssertFactory.ValueProvider<
the type of provided value.
T
>

A provider that provides a value compatible with a given Type.

Method Summary

Modifier and TypeMethod and Description
public ASSERT

Returns:

the custom Assert instance for the given value
createAssert
(T
the input value for the Assert instance
actual
)

Creates the custom Assert instance for the given value.

public default ASSERT

Returns:

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

Creates the custom Assert instance for the value provided by the given valueProvider.

Method Detail

createAssertback to summary
public ASSERT createAssert(T actual)

Creates the custom Assert instance for the given value.

Typically, this will just invoke assertThat(actual).

Parameters
actual:T

the input value for the Assert instance

Returns:ASSERT

the custom Assert instance for the given value

createAssertback to summary
public 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 T.

Parameters
valueProvider:AssertFactory.ValueProvider<? extends T>

the value provider for the Assert instance

Returns:ASSERT

the custom Assert instance for the value provided by the given value provider

Since
3.26.0
org.assertj.core.api back to summary

public Interface AssertFactory.ValueProvider<T>

extends Function<Type, T>
Annotations
@FunctionalInterface
Type Parameters
<T>
the type of provided value.

A provider that provides a value compatible with a given Type.
Since
3.26.0

Method Summary

Modifier and TypeMethod and Description
public default T

Returns:

the provided value
apply
(Type
the given type
type
)

Implements java.util.function.Function.apply.

Provides a value compatible with the given type.
public T

Returns:

the provided value
provide
(Type
the given type, either a Class or a ParameterizedType instance
type
)

Provides a value compatible with the given type.

Inherited from java.util.function.Function:
andThencomposeidentity

Method Detail

applyback to summary
public default T apply(Type type)

Implements java.util.function.Function.apply.

Provides a value compatible with the given type.

Parameters
type:Type

the given type

Returns:T

the provided value

Exceptions
IllegalArgumentException:
if type is neither a Class nor a ParameterizedType instance
provideback to summary
public T provide(Type type)

Provides a value compatible with the given type.

The compatibility definition depends on the actual type instance:

  • If type is a Class, the provided value must be an instance of it.
  • If type is a ParameterizedType, the provided value must be an instance of its raw type.
All other Type subtypes are unsupported.
Parameters
type:Type

the given type, either a Class or a ParameterizedType instance

Returns:T

the provided value