Skip to content

Commit

Permalink
#3: fixed review findings
Browse files Browse the repository at this point in the history
  • Loading branch information
AnastasiiaSergienko committed May 25, 2020
1 parent 6fea333 commit 75b5191
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 7 deletions.
2 changes: 1 addition & 1 deletion doc/user_guide/user_guide.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ Depending on your personal preferences or the use case for the test, you can pic

## The `ResultSetMatcher`

This matcher allows you to compare two `ResultSet`'s. This can be helpful when you need, for example, to compare each value of two tables.
This matcher allows you to compare two `ResultSet`s. This can be helpful when you need, for example, to compare each value of two tables.

A minimal test would then look as in the example below.

Expand Down
12 changes: 6 additions & 6 deletions src/main/java/com/exasol/matcher/ResultSetMatcher.java
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ private boolean assertEqualResultSets(final ResultSet actualResultSet) throws SQ
expectedNext = this.expectedResultSet.next();
actualNext = actualResultSet.next();
this.rowCounter++;
if (!bothRowsExist(actualResultSet, expectedNext, actualNext))
if (!doBothRowsExist(actualResultSet, expectedNext, actualNext))
return false;
if (expectedNext && !doesRowMatch(actualResultSet, expectedColumnCount)) {
return false;
Expand All @@ -88,17 +88,17 @@ private boolean columnCounterMatches(final int expectedColumnCount, final int ac
}
}

private boolean bothRowsExist(final ResultSet actualResultSet, final boolean expectedNext, final boolean actualNext)
private boolean doBothRowsExist(final ResultSet actualResultSet, final boolean expectedNext, final boolean actualNext)
throws SQLException {
if (expectedNext != actualNext) {
final int expectedRowCounter;
final int actualRowCounter;
if (expectedNext) {
expectedRowCounter = getRowCounter(rowCounter, this.expectedResultSet);
actualRowCounter = rowCounter - 1;
expectedRowCounter = getRowCounter(this.rowCounter, this.expectedResultSet);
actualRowCounter = this.rowCounter - 1;
} else {
expectedRowCounter = rowCounter - 1;
actualRowCounter = getRowCounter(rowCounter, actualResultSet);
expectedRowCounter = this.rowCounter - 1;
actualRowCounter = getRowCounter(this.rowCounter, actualResultSet);
}
this.expectedDescription = "ResultSet with <" + expectedRowCounter + "> row(s)";
this.actualDescription = "ResultSet with <" + actualRowCounter + "> row(s)";
Expand Down
16 changes: 16 additions & 0 deletions src/test/java/com/exasol/matcher/ResultSetMatcherTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,22 @@ void testRowCounterMismatch() throws SQLException {
+ " but: ResultSet with <1> row(s)"));
}

@Test
void testRowCounterMismatch2() throws SQLException {
execute("CREATE TABLE ROW_COUNT_MORE_MISMATCH(COL1 VARCHAR(20), COL2 INTEGER)");
execute("INSERT INTO ROW_COUNT_MORE_MISMATCH VALUES ('foo', 1)");
execute("CREATE TABLE ROW_COUNT_MORE_MISMATCH_2(COL1 VARCHAR(20), COL2 INTEGER)");
execute("INSERT INTO ROW_COUNT_MORE_MISMATCH_2 VALUES ('foo', 1), ('bar', 2)");
final ResultSet expected = query("SELECT * FROM ROW_COUNT_MORE_MISMATCH");
// Derby doesn't support two opened result sets on one statement, so we create one more statement.
final Statement statement2 = this.connection.createStatement();
final ResultSet actual = statement2.executeQuery("SELECT * FROM ROW_COUNT_MORE_MISMATCH_2");
final AssertionError error = assertThrows(AssertionError.class,
() -> assertThat(actual, matchesResultSet(expected)));
assertThat(error.getMessage(), containsString("Expected: ResultSet with <1> row(s)\n" //
+ " but: ResultSet with <2> row(s)"));
}

@Test
void testValueMismatch() throws SQLException {
execute("CREATE TABLE VALUE_MISMATCH(COL1 VARCHAR(20), COL2 INTEGER)");
Expand Down

0 comments on commit 75b5191

Please sign in to comment.