|
18 | 18 | import static org.junit.jupiter.api.Assertions.assertTrue; |
19 | 19 |
|
20 | 20 | import java.util.ArrayList; |
| 21 | +import java.util.Arrays; |
21 | 22 | import java.util.Collections; |
22 | 23 | import java.util.List; |
| 24 | +import java.util.stream.Collectors; |
23 | 25 |
|
24 | 26 | import org.junit.jupiter.api.BeforeEach; |
25 | 27 | import org.junit.jupiter.api.Test; |
@@ -56,15 +58,26 @@ public void testSorted() throws Exception { |
56 | 58 | // first, collect all matches |
57 | 59 | Object[] elements= result.getElements(); |
58 | 60 | for (Object element : elements) { |
| 61 | + int sizeBefore= allMatches.size(); |
59 | 62 | Match[] matches = result.getMatches(element); |
60 | 63 | Collections.addAll(allMatches, matches); |
| 64 | + int sizeAfter= allMatches.size(); |
| 65 | + assertEquals(sizeBefore + matches.length, sizeAfter, "Failed to add matches:" + |
| 66 | + Arrays.stream(matches).map(Match::toString).collect(Collectors.joining(System.lineSeparator()))); |
61 | 67 | } |
| 68 | + |
| 69 | + assertEquals(allMatches.size(), originalMatchCount, "Unexpected match count"); |
| 70 | + |
62 | 71 | // now remove them and readd them in reverse order |
63 | 72 | result.removeAll(); |
64 | 73 | assertEquals(0, result.getMatchCount(), "removed all matches"); |
65 | 74 |
|
66 | 75 | for (int i= allMatches.size()-1; i >= 0; i--) { |
67 | | - result.addMatch(allMatches.get(i)); |
| 76 | + Match match= allMatches.get(i); |
| 77 | + int sizeBefore= result.getMatchCount(); |
| 78 | + result.addMatch(match); |
| 79 | + int sizeAfter= result.getMatchCount(); |
| 80 | + assertEquals(sizeBefore + 1, sizeAfter, "Failed to add match:" + match); |
68 | 81 | } |
69 | 82 |
|
70 | 83 | assertEquals(result.getMatchCount(), originalMatchCount, "Test that all matches have been added again"); |
|
0 commit comments