Skip to content

Commit

Permalink
#44: Fixed indexing. Added test for in-order matching.
Browse files Browse the repository at this point in the history
  • Loading branch information
redcatbear committed Oct 27, 2023
1 parent 7020688 commit 51e0379
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ private boolean matchRowsInOrder(final ResultSet resultSet) {
boolean ok = true;
try {
int rowIndex = 0;
int matcherRowIndex = 1;
int matcherRowIndex = 0;
for (final List<Matcher<?>> cellMatcherRow : this.cellMatcherTable) {
++matcherRowIndex;
if (resultSet.next()) {
Expand All @@ -164,7 +164,7 @@ private boolean matchRowsInAnyOrder(final ResultSet resultSet) {
final int numberOfRowMatchers = this.cellMatcherTable.size();
int[] matchesForRowMatcher = new int[numberOfRowMatchers];
int rowIndex = 0;
int matcherRowIndex = 1;
int matcherRowIndex = 0;
while (resultSet.next()) {
++rowIndex;
boolean anyMatchForThisResultRow = false;
Expand Down
20 changes: 18 additions & 2 deletions src/test/java/com/exasol/matcher/RowMatcherIT.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ void afterEach() {

// This is a regression test for https://github.com/exasol/hamcrest-resultset-matcher/issues/44
@Test
void testExpectingThreeColumnsThrowsAssertionErrorWhenResultSetHasOnlyTwoColumns() {
void testMatchingInAnyOrderAndExpectingThreeColumnsThrowsAssertionErrorWhenResultSetHasOnlyTwoColumns() {
execute("CREATE TABLE T(I INTEGER, V VARCHAR(20))");
execute("INSERT INTO T VALUES (1, 'a'), (2, 'b')");
AssertionError error = assertThrows(AssertionError.class, () -> ResultSetStructureMatcher //
Expand All @@ -38,7 +38,23 @@ void testExpectingThreeColumnsThrowsAssertionErrorWhenResultSetHasOnlyTwoColumns
.row(greaterThan(0), "b", 3) //
.matchesInAnyOrder() //
.matches(query("SELECT * FROM T")));
assertThat(error.getMessage(), startsWith("Row expectation definition 2 tries to validate the value of row 1, "
assertThat(error.getMessage(), startsWith("Row expectation definition 1 tries to validate the value of row 1, "
+ "column 3 but that value can't be read from the result set. "
+ "This usually means the column does not exist. \nCaused by SQL error:"));
}

// This is a regression test for https://github.com/exasol/hamcrest-resultset-matcher/issues/44
@Test
void testMatchingInStrictOrderAndExpectingThreeColumnsThrowsAssertionErrorWhenResultSetHasOnlyTwoColumns() {
execute("CREATE TABLE T(I INTEGER, V VARCHAR(20))");
execute("INSERT INTO T VALUES (1, 'A'), (2, 'B')");
AssertionError error = assertThrows(AssertionError.class, () -> ResultSetStructureMatcher //
.table()//
.row(1, "A", 1) //
.row(greaterThan(0), "B", 3) //
.matches() //
.matches(query("SELECT * FROM T")));
assertThat(error.getMessage(), startsWith("Row expectation definition 1 tries to validate the value of row 1, "
+ "column 3 but that value can't be read from the result set. "
+ "This usually means the column does not exist. \nCaused by SQL error:"));
}
Expand Down

0 comments on commit 51e0379

Please sign in to comment.