Top Description Inners Methods
org.assertj.core.api

public Interface SoftAssertionsProvider

extends AssertionErrorCollector
Known Direct Subinterfaces
org.assertj.core.api.SoftAssertionsRule, org.assertj.core.api.Java6StandardSoftAssertionsProvider, org.assertj.core.api.AutoCloseableSoftAssertionsProvider, org.assertj.core.api.Java6BDDSoftAssertionsProvider
Known Direct Implementers
org.assertj.core.api.AbstractSoftAssertions
Imports
java.util.function.Consumer, org.opentest4j.MultipleFailuresError

Parent interface for soft assertion implementations.
Author
Fr Jeremy Krieg
See Also
AbstractSoftAssertions, SoftAssertions

Nested and Inner Type Summary

Modifier and TypeClass and Description
public static interface

Method Summary

Modifier and TypeMethod and Description
public void
assertAll()

Verifies that no soft assertions have failed.

public default void
assertAlso(AssertionErrorCollector
the AssertionErrorCollector error source
collector
)

Add all errors of collector argument to current SoftAssertionsProvider instance.

public static <
the concrete type of soft assertions to use.
S extends SoftAssertionsProvider
>
void
assertSoftly(Class<S>
the class object of the concrete type of soft assertions to use.
type
,
Consumer<S>
the Consumer containing the code that will make the soft assertions. Takes one parameter (the SoftAssertion instance used to make the assertions).
softly
)

Use this to avoid having to call assertAll manually.

public default void
check(SoftAssertionsProvider.ThrowingRunnable
an assertion call.
assertion
)

Catch and collect assertion errors coming from standard and custom assertions.

public <
The type of the assertion class
SELF extends Assert<? extends SELF, ? extends ACTUAL>
,
The type of the object-under-test
ACTUAL
>
SELF

Returns:

A proxied assertion class for the given object-under-test.
proxy
(Class<SELF>
Class instance for the assertion type.
assertClass
,
Class<ACTUAL>
Class instance for the type of the object-under-test.
actualClass
,
ACTUAL
The actual object-under-test.
actual
)

Creates a proxied assertion class of the given type.

Inherited from org.assertj.core.api.AssertionErrorCollector:
assertionErrorsCollectedcollectAssertionErrorgetDelegateonAssertionErrorCollectedsetDelegatesucceededwasSuccess

Method Detail

assertAllback to summary
public void assertAll()

Verifies that no soft assertions have failed.

Exceptions
MultipleFailuresError:
if possible or SoftAssertionError if any proxied assertion objects threw an AssertionError
assertAlsoback to summary
public default void assertAlso(AssertionErrorCollector collector)

Add all errors of collector argument to current SoftAssertionsProvider instance.

Parameters
collector:AssertionErrorCollector

the AssertionErrorCollector error source

assertSoftlyback to summary
public static <S extends SoftAssertionsProvider> void assertSoftly(Class<S> type, Consumer<S> softly)

Use this to avoid having to call assertAll manually.

 @Test
public void host_dinner_party_where_nobody_dies() {
  Mansion mansion = new Mansion();
  mansion.hostPotentiallyMurderousDinnerParty();
  SoftAssertion.assertSoftly(SoftAssertions.class, softly -> {
    softly.assertThat(mansion.guests()).as("Living Guests").isEqualTo(7);
    softly.assertThat(mansion.kitchen()).as("Kitchen").isEqualTo("clean");
    softly.assertThat(mansion.library()).as("Library").isEqualTo("clean");
    softly.assertThat(mansion.revolverAmmo()).as("Revolver Ammo").isEqualTo(6);
    softly.assertThat(mansion.candlestick()).as("Candlestick").isEqualTo("pristine");
    softly.assertThat(mansion.colonel()).as("Colonel").isEqualTo("well kempt");
    softly.assertThat(mansion.professor()).as("Professor").isEqualTo("well kempt");
  });
}
Parameters
<S>
the concrete type of soft assertions to use.
type:Class<S>

the class object of the concrete type of soft assertions to use.

softly:Consumer<S>

the Consumer containing the code that will make the soft assertions. Takes one parameter (the SoftAssertion instance used to make the assertions).

Exceptions
MultipleFailuresError:
if possible or SoftAssertionError if any proxied assertion objects threw an AssertionError
Since
3.16.0
checkback to summary
public default void check(SoftAssertionsProvider.ThrowingRunnable assertion)

Catch and collect assertion errors coming from standard and custom assertions.

Example :

 SoftAssertions softly = new SoftAssertions();
softly.check(() -> Assertions.assertThat(…).…);
softly.check(() -> CustomAssertions.assertThat(…).…);
softly.assertAll(); 
Parameters
assertion:SoftAssertionsProvider.ThrowingRunnable

an assertion call.

proxyback to summary
public <SELF extends Assert<? extends SELF, ? extends ACTUAL>, ACTUAL> SELF proxy(Class<SELF> assertClass, Class<ACTUAL> actualClass, ACTUAL actual)

Creates a proxied assertion class of the given type. The returned value is an assertion object compatible with the supplied assertion class, but instead of throwing errors it will collect them and store.

Parameters
<SELF>
The type of the assertion class
<ACTUAL>
The type of the object-under-test
assertClass:Class<SELF>

Class instance for the assertion type.

actualClass:Class<ACTUAL>

Class instance for the type of the object-under-test.

actual:ACTUAL

The actual object-under-test.

Returns:SELF

A proxied assertion class for the given object-under-test.

org.assertj.core.api back to summary

public Interface SoftAssertionsProvider.ThrowingRunnable


Method Summary

Modifier and TypeMethod and Description
public void
run()

Method Detail

runback to summary
public void run() throws Exception