Skip to content

Commit cd0b713

Browse files
committed
Fiddling with tests and failure messages
1 parent c4bddd2 commit cd0b713

3 files changed

Lines changed: 27 additions & 37 deletions

File tree

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,7 @@ public final class BaseDescriptionTest {
5959
assertEquals("[\"2\", \"3\"]", result.toString());
6060
}
6161

62-
@Test
63-
public void
62+
@Test public void
6463
describesAppendedIterableValue() {
6564
baseDescription.appendValue(new Iterable<String>() {
6665
@Override

‎hamcrest-library/src/main/java/org/hamcrest/collection/HasSubsequence.java‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,15 +42,15 @@ public boolean matchesSafely(Iterable<? extends T> subsequenceToMatch,
4242
}
4343

4444
mismatchDescription
45-
.appendText("could not find subsequence inside collection ")
45+
.appendText("could not find subsequence in ")
4646
.appendValueList("[", ", ", "]", subsequenceToMatch);
4747
return false;
4848
}
4949

5050
@Override
5151
public void describeTo(Description description) {
5252
description
53-
.appendText("collection contains subsequence matching ")
53+
.appendText("iterable contains subsequence matching ")
5454
.appendList("[", ", ", "]", matchers);
5555
}
5656
}

‎hamcrest-library/src/test/java/org/hamcrest/collection/HasSubsequenceTest.java‎

Lines changed: 24 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
import org.hamcrest.Matcher;
66

77
import java.util.ArrayList;
8-
import java.util.List;
98

109
import static java.util.Arrays.asList;
1110
import static org.hamcrest.collection.MatchIterables.hasSubsequence;
@@ -19,58 +18,50 @@ protected Matcher<?> createMatcher() {
1918
return hasSubsequence(1, 2);
2019
}
2120

22-
public void testMatchingSingleItemCollection() throws Exception {
23-
assertMatches("Single item iterable",
24-
hasSubsequence(1), asList(1));
25-
}
26-
27-
public void testMatchingMultipleItemCollection() throws Exception {
28-
assertMatches("Multiple item iterable",
21+
public void testMatchesIterableWithSameValues() throws Exception {
22+
assertMatches("Actual with single item",
23+
hasSubsequence(1), asList(1));
24+
assertMatches("Actual with multiple items",
2925
hasSubsequence(1, 2, 3), asList(1, 2, 3));
3026
}
3127

32-
public void testMatchesWithMoreElementsThanExpectedAtBeginning() throws Exception {
28+
public void testMatchesIterableWithExcessElements() throws Exception {
3329
assertMatches("More elements at beginning",
3430
hasSubsequence(2, 3, 4), asList(1, 2, 3, 4));
35-
}
36-
37-
public void testMatchesWithMoreElementsThanExpectedAtEnd() throws Exception {
31+
assertMatches("Sub section of actual", hasSubsequence(2, 3), asList(1, 2, 3, 4));
3832
assertMatches("More elements at end",
39-
hasSubsequence(1, 2, 3), asList(1, 2, 3, 4));
33+
hasSubsequence(1, 2, 3), asList(1, 2, 3, 4));
4034
}
4135

42-
public void testDoesNotMatchWithMoreElementsThanExpectedInBetween() throws Exception {
43-
assertMismatchDescription("could not find subsequence inside collection [<1>, <2>, <3>]",
44-
hasSubsequence(1, 3), asList(1, 2, 3));
36+
public void testMismatchesIfItemsMissing() throws Exception {
37+
assertMismatchDescription(
38+
"could not find subsequence in [<WithValue 3>]",
39+
hasSubsequence(value(4)), asList(withValue(3)));
40+
assertMismatchDescription(
41+
"could not find subsequence in [<WithValue 1>, <WithValue 2>, <WithValue 4>]",
42+
contains123, asList(withValue(1), withValue(2), withValue(4)));
4543
}
4644

47-
public void testMatchesSubSection() throws Exception {
48-
assertMatches("Sub section of iterable", hasSubsequence(2, 3), asList(1, 2, 3, 4));
49-
}
5045

51-
public void testDoesNotMatchWithFewerElementsThanExpected() throws Exception {
52-
List<WithValue> valueList = asList(make(1), make(2));
53-
assertMismatchDescription("could not find subsequence inside collection [<WithValue 1>, <WithValue 2>]",
54-
contains123, valueList);
46+
public void testMismatchesForAdditionalIntermediateItems() throws Exception {
47+
assertMismatchDescription("could not find subsequence in [<1>, <2>, <3>]",
48+
hasSubsequence(1, 3), asList(1, 2, 3));
5549
}
5650

57-
public void testDoesNotMatchIfSingleItemNotFound() throws Exception {
58-
assertMismatchDescription("could not find subsequence inside collection [<WithValue 3>]",
59-
hasSubsequence(value(4)), asList(make(3)));
60-
}
6151

62-
public void testDoesNotMatchIfOneOfMultipleItemsNotFound() throws Exception {
63-
assertMismatchDescription("could not find subsequence inside collection [<WithValue 1>, <WithValue 2>, <WithValue 4>]",
64-
contains123, asList(make(1), make(2), make(4)));
52+
public void testMismatchesWhenTooFewItems() throws Exception {
53+
assertMismatchDescription(
54+
"could not find subsequence in [<WithValue 1>, <WithValue 2>]",
55+
contains123, asList(withValue(1), withValue(2)));
6556
}
6657

6758
public void testDoesNotMatchEmptyCollection() throws Exception {
68-
assertMismatchDescription("could not find subsequence inside collection []",
59+
assertMismatchDescription("could not find subsequence in []",
6960
hasSubsequence(value(4)), new ArrayList<WithValue>());
7061
}
7162

7263
public void testHasAReadableDescription() {
73-
assertDescription("collection contains subsequence matching [<1>, <2>]", hasSubsequence(1, 2));
64+
assertDescription("iterable contains subsequence matching [<1>, <2>]", hasSubsequence(1, 2));
7465
}
7566

7667
public static class WithValue {
@@ -90,7 +81,7 @@ public String toString() {
9081
}
9182
}
9283

93-
public static WithValue make(int value) {
84+
public static WithValue withValue(int value) {
9485
return new WithValue(value);
9586
}
9687

0 commit comments

Comments
 (0)