public interface SoftAssertionsProvider extends AssertionErrorCollector
AbstractSoftAssertions,
SoftAssertions| Modifier and Type | Interface and Description |
|---|---|
static interface |
SoftAssertionsProvider.ThrowingRunnable |
| Modifier and Type | Method and Description |
|---|---|
void |
assertAll()
Verifies that no soft assertions have failed.
|
default void |
assertAlso(AssertionErrorCollector collector)
Add all errors of
collector argument to current instance. |
static <S extends SoftAssertionsProvider> |
assertSoftly(Class<S> type,
Consumer<S> softly)
Use this to avoid having to call assertAll manually.
|
default void |
check(SoftAssertionsProvider.ThrowingRunnable assertion)
Catch and collect assertion errors coming from standard and custom assertions.
|
<SELF extends Assert<? extends SELF,? extends ACTUAL>,ACTUAL> |
proxy(Class<SELF> assertClass,
Class<ACTUAL> actualClass,
ACTUAL actual)
Creates a proxied assertion class of the given type.
|
assertionErrorsCollected, collectAssertionError, getDelegate, onAssertionErrorCollected, setDelegate, succeeded, wasSuccess<SELF extends Assert<? extends SELF,? extends ACTUAL>,ACTUAL> SELF proxy(Class<SELF> assertClass, Class<ACTUAL> actualClass, ACTUAL actual)
SELF - The type of the assertion classACTUAL - The type of the object-under-testassertClass - Class instance for the assertion type.actualClass - Class instance for the type of the object-under-test.actual - The actual object-under-test.void assertAll()
org.opentest4j.MultipleFailuresError - if possible or SoftAssertionError if any proxied assertion objects threw an AssertionErrordefault void assertAlso(AssertionErrorCollector collector)
collector argument to current SoftAssertionsProvider instance.collector - the AssertionErrorCollector error sourcedefault void check(SoftAssertionsProvider.ThrowingRunnable assertion)
Example :
SoftAssertions softly = new SoftAssertions();
softly.check(() -> Assertions.assertThat(…).…);
softly.check(() -> CustomAssertions.assertThat(…).…);
softly.assertAll(); assertion - an assertion call.static <S extends SoftAssertionsProvider> void assertSoftly(Class<S> type, Consumer<S> softly)
@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");
});
}S - the concrete type of soft assertions to use.type - the class object of the concrete type of soft assertions to use.softly - the Consumer containing the code that will make the soft assertions.
Takes one parameter (the SoftAssertion instance used to make the assertions).org.opentest4j.MultipleFailuresError - if possible or SoftAssertionError if any proxied assertion objects threw an AssertionErrorCopyright © 2025. All rights reserved.