55import org .hamcrest .Matcher ;
66
77import java .util .ArrayList ;
8- import java .util .List ;
98
109import static java .util .Arrays .asList ;
1110import 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