Interface SoftAssertionsProvider

    • Method Detail

      • proxy

        <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.
        Type Parameters:
        SELF - The type of the assertion class
        ACTUAL - The type of the object-under-test
        Parameters:
        assertClass - Class instance for the assertion type.
        actualClass - Class instance for the type of the object-under-test.
        actual - The actual object-under-test.
        Returns:
        A proxied assertion class for the given object-under-test.
      • assertAll

        void assertAll()
        Verifies that no soft assertions have failed.
        Throws:
        org.opentest4j.MultipleFailuresError - if possible or SoftAssertionError if any proxied assertion objects threw an AssertionError
      • check

        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 - an assertion call.
      • assertSoftly

        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");
           });
         }
        Type Parameters:
        S - the concrete type of soft assertions to use.
        Parameters:
        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).
        Throws:
        org.opentest4j.MultipleFailuresError - if possible or SoftAssertionError if any proxied assertion objects threw an AssertionError
        Since:
        3.16.0