Interface AssertionErrorCollector
-
- All Superinterfaces:
AfterAssertionErrorCollected
- All Known Subinterfaces:
AutoCloseableSoftAssertionsProvider
,BDDSoftAssertionsProvider
,Java6BDDSoftAssertionsProvider
,Java6StandardSoftAssertionsProvider
,SoftAssertionsProvider
,SoftAssertionsRule
,StandardSoftAssertionsProvider
- All Known Implementing Classes:
AbstractSoftAssertions
,AutoCloseableBDDSoftAssertions
,AutoCloseableSoftAssertions
,BDDSoftAssertions
,Java6BDDSoftAssertions
,Java6JUnitBDDSoftAssertions
,Java6JUnitSoftAssertions
,Java6SoftAssertions
,JUnitBDDSoftAssertions
,JUnitJupiterBDDSoftAssertions
,JUnitJupiterSoftAssertions
,JUnitSoftAssertions
,SoftAssertions
public interface AssertionErrorCollector extends AfterAssertionErrorCollected
-
-
Method Summary
All Methods Instance Methods Abstract Methods Default Methods Modifier and Type Method Description List<AssertionError>
assertionErrorsCollected()
void
collectAssertionError(AssertionError error)
This method can be used to collect soft assertion errors.default void
onAssertionErrorCollected(AssertionError assertionError)
This method is called after eachAssertionError
is collected by soft assertions (you can't prevent the error to be collected).
-
-
-
Method Detail
-
collectAssertionError
void collectAssertionError(AssertionError error)
This method can be used to collect soft assertion errors.Warning: this is not the method used internally by AssertJ to collect all of them, overriding it to react to each collected assertion error will not work.
To be able to react after an assertion error is collected, use @
onAssertionErrorCollected(AssertionError)
instead.- Parameters:
error
- theAssertionError
to collect.
-
assertionErrorsCollected
List<AssertionError> assertionErrorsCollected()
-
onAssertionErrorCollected
default void onAssertionErrorCollected(AssertionError assertionError)
Description copied from interface:AfterAssertionErrorCollected
This method is called after eachAssertionError
is collected by soft assertions (you can't prevent the error to be collected).SoftAssertionsProvider
provides a do-nothing implementation which you can override in your own custom soft assertions class.
Note that your custom soft assertions class must extendAbstractSoftAssertions
as this is where the actual soft assertion errors collection is implemented.If you just use the standard soft assertions classes provided by AssertJ, you can register your callback with
AbstractSoftAssertions.setAfterAssertionErrorCollected(AfterAssertionErrorCollected)
.Example with custom soft assertions:
class TolkienSoftAssertions extends SoftAssertions { public TolkienHeroesAssert assertThat(TolkienHero actual) { return proxy(TolkienHeroesAssert.class, TolkienHero.class, actual); } @Override public void onAssertionErrorCollected(AssertionError assertionError) { System.out.println(assertionError); } } TolkienSoftAssertions softly = new TolkienSoftAssertions(); TolkienCharacter frodo = TolkienCharacter.of("Frodo", 33, HOBBIT); // the AssertionError corresponding to this failing assertion is printed to the console. softly.assertThat(frodo).hasName("Bilbo");
Example with standard soft assertions:
SoftAssertions softly = new SoftAssertions(); // register our callback softly.setAfterAssertionErrorCollected(error -> System.out.println(error)); // the AssertionError corresponding to this failing assertion is printed to the console. softly.assertThat("The Beatles").isEqualTo("The Rolling Stones");
- Specified by:
onAssertionErrorCollected
in interfaceAfterAssertionErrorCollected
- Parameters:
assertionError
- the collectedAssertionError
.
-
-