|
2 | 2 | */ |
3 | 3 | package org.hamcrest.core; |
4 | 4 |
|
5 | | -import org.hamcrest.AbstractMatcherTest; |
6 | | -import org.hamcrest.Matcher; |
7 | | - |
8 | | -import static org.hamcrest.MatcherAssert.assertThat; |
| 5 | +import static org.hamcrest.AbstractMatcherTest.assertDescription; |
| 6 | +import static org.hamcrest.AbstractMatcherTest.assertDoesNotMatch; |
| 7 | +import static org.hamcrest.AbstractMatcherTest.assertMatches; |
| 8 | +import static org.hamcrest.AbstractMatcherTest.assertMismatchDescription; |
| 9 | +import static org.hamcrest.AbstractMatcherTest.assertNullSafe; |
| 10 | +import static org.hamcrest.AbstractMatcherTest.assertUnknownTypeSafe; |
9 | 11 | import static org.hamcrest.core.AllOf.allOf; |
10 | 12 | import static org.hamcrest.core.Is.is; |
11 | 13 | import static org.hamcrest.core.IsEqual.equalTo; |
12 | | -import static org.hamcrest.core.IsNot.not; |
13 | 14 | import static org.hamcrest.core.IsNull.notNullValue; |
| 15 | +import static org.hamcrest.core.StringEndsWith.endsWith; |
14 | 16 | import static org.hamcrest.core.StringStartsWith.startsWith; |
15 | 17 |
|
16 | | -public class AllOfTest extends AbstractMatcherTest { |
| 18 | +import org.hamcrest.Matcher; |
| 19 | +import org.junit.Test; |
| 20 | + |
| 21 | +public final class AllOfTest { |
17 | 22 |
|
18 | | - @Override |
19 | | - @SuppressWarnings("unchecked") |
20 | | - protected Matcher<?> createMatcher() { |
21 | | - return allOf(IsEqual.<Object>equalTo("irrelevant")); |
| 23 | + @Test public void |
| 24 | + copesWithNullsAndUnknownTypes() { |
| 25 | + Matcher<String> matcher = allOf(equalTo("irrelevant"), startsWith("irr")); |
| 26 | + |
| 27 | + assertNullSafe(matcher); |
| 28 | + assertUnknownTypeSafe(matcher); |
22 | 29 | } |
23 | 30 |
|
24 | | - public void testEvaluatesToTheTheLogicalConjunctionOfTwoOtherMatchers() { |
25 | | - assertThat("good", allOf(equalTo("good"), startsWith("good"))); |
26 | | - |
27 | | - assertThat("good", not(allOf(equalTo("bad"), equalTo("good")))); |
28 | | - assertThat("good", not(allOf(equalTo("good"), equalTo("bad")))); |
29 | | - assertThat("good", not(allOf(equalTo("bad"), equalTo("bad")))); |
| 31 | + @Test public void |
| 32 | + evaluatesToTheTheLogicalConjunctionOfTwoOtherMatchers() { |
| 33 | + Matcher<String> matcher = allOf(startsWith("goo"), endsWith("ood")); |
| 34 | + |
| 35 | + assertMatches("didn't pass both sub-matchers", matcher, "good"); |
| 36 | + assertDoesNotMatch("didn't fail first sub-matcher", matcher, "mood"); |
| 37 | + assertDoesNotMatch("didn't fail second sub-matcher", matcher, "goon"); |
| 38 | + assertDoesNotMatch("didn't fail both sub-matchers", matcher, "fred"); |
30 | 39 | } |
31 | 40 |
|
32 | | - public void testEvaluatesToTheTheLogicalConjunctionOfManyOtherMatchers() { |
33 | | - assertThat("good", allOf(equalTo("good"), equalTo("good"), equalTo("good"), equalTo("good"), equalTo("good"))); |
34 | | - assertThat("good", not(allOf(equalTo("good"), equalTo("good"), equalTo("bad"), equalTo("good"), equalTo("good")))); |
| 41 | + @Test public void |
| 42 | + evaluatesToTheTheLogicalConjunctionOfManyOtherMatchers() { |
| 43 | + Matcher<String> matcher = allOf(startsWith("g"), startsWith("go"), endsWith("d"), startsWith("go"), startsWith("goo")); |
| 44 | + |
| 45 | + assertMatches("didn't pass all sub-matchers", matcher, "good"); |
| 46 | + assertDoesNotMatch("didn't fail middle sub-matcher", matcher, "goon"); |
35 | 47 | } |
36 | 48 |
|
37 | | - public void testSupportsMixedTypes() { |
38 | | - final Matcher<SampleSubClass> all = allOf( |
| 49 | + @Test public void |
| 50 | + supportsMixedTypes() { |
| 51 | + final Matcher<SampleSubClass> matcher = allOf( |
39 | 52 | equalTo(new SampleBaseClass("bad")), |
40 | 53 | is(notNullValue()), |
41 | 54 | equalTo(new SampleBaseClass("good")), |
42 | 55 | equalTo(new SampleSubClass("ugly"))); |
43 | | - final Matcher<SampleSubClass> negated = not(all); |
44 | 56 |
|
45 | | - assertThat(new SampleSubClass("good"), negated); |
| 57 | + assertDoesNotMatch("didn't fail last sub-matcher", matcher, new SampleSubClass("good")); |
46 | 58 | } |
47 | 59 |
|
48 | | - public void testHasAReadableDescription() { |
| 60 | + @Test public void |
| 61 | + hasAReadableDescription() { |
49 | 62 | assertDescription("(\"good\" and \"bad\" and \"ugly\")", |
50 | 63 | allOf(equalTo("good"), equalTo("bad"), equalTo("ugly"))); |
51 | 64 | } |
52 | 65 |
|
53 | | - public void testMismatchDescriptionDescribesFirstFailingMatch() { |
| 66 | + @Test public void |
| 67 | + hasAMismatchDescriptionDescribingTheFirstFailingMatch() { |
54 | 68 | assertMismatchDescription("\"good\" was \"bad\"", allOf(equalTo("bad"), equalTo("good")), "bad"); |
55 | 69 | } |
56 | 70 | } |
0 commit comments