|
1 | 1 | package org.hamcrest.core; |
2 | 2 |
|
3 | | -import org.hamcrest.StringDescription; |
4 | | -import org.junit.Test; |
| 3 | +import static java.util.Arrays.asList; |
| 4 | +import static org.hamcrest.AbstractMatcherTest.assertDescription; |
| 5 | +import static org.hamcrest.AbstractMatcherTest.assertDoesNotMatch; |
| 6 | +import static org.hamcrest.AbstractMatcherTest.assertMatches; |
| 7 | +import static org.hamcrest.AbstractMatcherTest.assertMismatchDescription; |
| 8 | +import static org.hamcrest.AbstractMatcherTest.assertNullSafe; |
| 9 | +import static org.hamcrest.AbstractMatcherTest.assertUnknownTypeSafe; |
| 10 | +import static org.hamcrest.core.StringContains.containsString; |
5 | 11 |
|
6 | 12 | import java.util.ArrayList; |
7 | 13 |
|
8 | | -import static java.util.Arrays.asList; |
9 | | -import static org.hamcrest.MatcherAssert.assertThat; |
10 | | -import static org.hamcrest.core.IsNot.not; |
11 | | -import static org.hamcrest.core.StringContains.containsString; |
12 | | -import static org.junit.Assert.assertEquals; |
| 14 | +import org.hamcrest.Matcher; |
| 15 | +import org.junit.Test; |
| 16 | + |
| 17 | +public final class EveryTest { |
13 | 18 |
|
14 | | -public class EveryTest { |
15 | | - @Test public void isTrueWhenEveryValueMatches() { |
16 | | - assertThat(asList("AaA", "BaB", "CaC"), Every.everyItem(containsString("a"))); |
17 | | - assertThat(asList("AbA", "BbB", "CbC"), not(Every.everyItem(containsString("a")))); |
| 19 | + private final Matcher<Iterable<String>> matcher = Every.everyItem(containsString("a")); |
| 20 | + |
| 21 | + @Test public void |
| 22 | + copesWithNullsAndUnknownTypes() { |
| 23 | + assertNullSafe(matcher); |
| 24 | + assertUnknownTypeSafe(matcher); |
| 25 | + } |
| 26 | + |
| 27 | + @Test public void |
| 28 | + matchesOnlyWhenEveryItemMatches() { |
| 29 | + assertMatches("didn't match", matcher, asList("AaA", "BaB", "CaC")); |
| 30 | + assertDoesNotMatch("matched unexpectedly", matcher, asList("AaA", "BXB", "CaC")); |
18 | 31 | } |
19 | 32 |
|
20 | | - @Test public void isAlwaysTrueForEmptyLists() { |
21 | | - assertThat(new ArrayList<String>(), Every.everyItem(containsString("a"))); |
| 33 | + @Test public void |
| 34 | + matchesEmptyLists() { |
| 35 | + assertMatches("didn't match empty list", matcher, new ArrayList<String>()); |
22 | 36 | } |
23 | 37 |
|
24 | | - @Test public void describesItself() { |
25 | | - final Every<String> each= new Every<String>(containsString("a")); |
26 | | - assertEquals("every item is a string containing \"a\"", each.toString()); |
27 | | - |
28 | | - StringDescription description = new StringDescription(); |
29 | | - each.matchesSafely(asList("BbB"), description); |
30 | | - assertEquals("an item was \"BbB\"", description.toString()); |
| 38 | + @Test public void |
| 39 | + describesItself() { |
| 40 | + assertDescription("every item is a string containing \"a\"", matcher); |
| 41 | + } |
| 42 | + |
| 43 | + @Test public void |
| 44 | + describesAMismatch() { |
| 45 | + assertMismatchDescription("an item was \"BXB\"", matcher, asList("BXB")); |
31 | 46 | } |
32 | 47 | } |
| 48 | + |
0 commit comments