Skip to content

Commit 96d4b89

Browse files
committed
convert test to JUnit4
1 parent 8d7ecb6 commit 96d4b89

1 file changed

Lines changed: 39 additions & 25 deletions

File tree

‎hamcrest-core/src/test/java/org/hamcrest/core/AllOfTest.java‎

Lines changed: 39 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -2,55 +2,69 @@
22
*/
33
package org.hamcrest.core;
44

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;
911
import static org.hamcrest.core.AllOf.allOf;
1012
import static org.hamcrest.core.Is.is;
1113
import static org.hamcrest.core.IsEqual.equalTo;
12-
import static org.hamcrest.core.IsNot.not;
1314
import static org.hamcrest.core.IsNull.notNullValue;
15+
import static org.hamcrest.core.StringEndsWith.endsWith;
1416
import static org.hamcrest.core.StringStartsWith.startsWith;
1517

16-
public class AllOfTest extends AbstractMatcherTest {
18+
import org.hamcrest.Matcher;
19+
import org.junit.Test;
20+
21+
public final class AllOfTest {
1722

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);
2229
}
2330

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");
3039
}
3140

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");
3547
}
3648

37-
public void testSupportsMixedTypes() {
38-
final Matcher<SampleSubClass> all = allOf(
49+
@Test public void
50+
supportsMixedTypes() {
51+
final Matcher<SampleSubClass> matcher = allOf(
3952
equalTo(new SampleBaseClass("bad")),
4053
is(notNullValue()),
4154
equalTo(new SampleBaseClass("good")),
4255
equalTo(new SampleSubClass("ugly")));
43-
final Matcher<SampleSubClass> negated = not(all);
4456

45-
assertThat(new SampleSubClass("good"), negated);
57+
assertDoesNotMatch("didn't fail last sub-matcher", matcher, new SampleSubClass("good"));
4658
}
4759

48-
public void testHasAReadableDescription() {
60+
@Test public void
61+
hasAReadableDescription() {
4962
assertDescription("(\"good\" and \"bad\" and \"ugly\")",
5063
allOf(equalTo("good"), equalTo("bad"), equalTo("ugly")));
5164
}
5265

53-
public void testMismatchDescriptionDescribesFirstFailingMatch() {
66+
@Test public void
67+
hasAMismatchDescriptionDescribingTheFirstFailingMatch() {
5468
assertMismatchDescription("\"good\" was \"bad\"", allOf(equalTo("bad"), equalTo("good")), "bad");
5569
}
5670
}

0 commit comments

Comments
 (0)