Last active
December 3, 2016 22:44
-
-
Save eddarmitage/98f1bd0496768243230a859b0e46969b to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import org.junit.Test; | |
import java.util.Arrays; | |
import java.util.List; | |
import static org.assertj.core.api.Assertions.assertThat; | |
import static org.assertj.core.api.SoftAssertions.assertSoftly; | |
public class AllSoftlyMatchTest { | |
@Test | |
public void shouldFailTwice() { | |
String story = "Bob, Jim and Carol went to the shops"; | |
List<String> characters = Arrays.asList("Jim", "John", "Jeremy"); | |
assertThat(characters).allSoftlyMatch(story::contains, "character is in story"); | |
// Output of allMatch(): | |
/* | |
* Expecting all elements of: | |
* <["Jim", "John", "Jeremy"]> | |
* to match 'character is in story' predicate but this element did not: | |
* <"John"> | |
*/ | |
} | |
@Test | |
public void currentAlternative() { | |
String story = "Bob, Jim and Carol went to the shops"; | |
List<String> characters = Arrays.asList("Jim", "John", "Jeremy"); | |
assertSoftly(softly -> { | |
characters.forEach(character -> softly.assertThat(story).contains(character)); | |
}); | |
// Output: | |
/* | |
* The following 2 assertions failed: | |
* 1) | |
* Expecting: | |
* <"Bob, Jim and Carol went to the shops"> | |
* to contain: | |
* <"John"> | |
* at JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:68) | |
* 2) | |
* Expecting: | |
* <"Bob, Jim and Carol went to the shops"> | |
* to contain: | |
* <"Jeremy"> | |
* at JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:68) | |
*/ | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This should be more an improvement of
allMatch
than a new assertions, said otherwiseallMatch
should report all the elements not matching the predicate. assertj/assertj#816