-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
#44: Improved assertion message when more columns expected than prese…
- Loading branch information
1 parent
33eff40
commit 07e75bc
Showing
7 changed files
with
159 additions
and
53 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
# Matcher for SQL Result Sets 1.6.2, released 2023-10-27 | ||
|
||
Code name: Fix expectation with too many columns | ||
|
||
## Summary | ||
|
||
We fixed an issue where expecting more columns than are actually in the result set would throw an `ArrayIndexOutOfBoundsException`. | ||
|
||
## Features | ||
|
||
* #44: Fixed `ArrayIndexOutOfBoundsException` when expecting more columns than are in the result set. | ||
|
||
## Dependency Updates | ||
|
||
### Test Dependency Updates | ||
|
||
* Updated `org.testcontainers:jdbc:1.19.0` to `1.19.1` | ||
* Updated `org.testcontainers:junit-jupiter:1.19.0` to `1.19.1` | ||
|
||
### Plugin Dependency Updates | ||
|
||
* Updated `com.exasol:error-code-crawler-maven-plugin:1.3.0` to `1.3.1` | ||
* Updated `com.exasol:project-keeper-maven-plugin:2.9.12` to `2.9.14` | ||
* Updated `org.apache.maven.plugins:maven-enforcer-plugin:3.4.0` to `3.4.1` | ||
* Updated `org.apache.maven.plugins:maven-javadoc-plugin:3.5.0` to `3.6.0` | ||
* Updated `org.codehaus.mojo:versions-maven-plugin:2.16.0` to `2.16.1` | ||
* Updated `org.jacoco:jacoco-maven-plugin:0.8.10` to `0.8.11` | ||
* Updated `org.sonarsource.scanner.maven:sonar-maven-plugin:3.9.1.2184` to `3.10.0.2594` |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
package com.exasol.matcher; | ||
|
||
import org.hamcrest.Matcher; | ||
import org.junit.jupiter.api.AfterEach; | ||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import java.sql.Connection; | ||
import java.sql.DriverManager; | ||
import java.sql.ResultSet; | ||
import java.sql.SQLException; | ||
|
||
import static org.hamcrest.MatcherAssert.assertThat; | ||
import static org.hamcrest.Matchers.*; | ||
import static org.junit.jupiter.api.Assertions.*; | ||
|
||
/** | ||
* This integration test runs row matching tests against the Apache Derby database. | ||
*/ | ||
class RowMatcherIT extends AbstractResultSetMatcherTest { | ||
@BeforeEach | ||
void beforeEach() throws SQLException { | ||
final Connection connection = DriverManager.getConnection("jdbc:derby:memory:test;create=true"); | ||
this.statement = connection.createStatement(); | ||
} | ||
|
||
@AfterEach | ||
void afterEach() { | ||
execute("DROP TABLE T"); | ||
} | ||
|
||
// This is a regression test for https://github.com/exasol/hamcrest-resultset-matcher/issues/44 | ||
@Test | ||
void testMatchingInAnyOrderAndExpectingThreeColumnsThrowsAssertionErrorWhenResultSetHasOnlyTwoColumns() | ||
throws SQLException { | ||
execute("CREATE TABLE T(I INTEGER, V VARCHAR(20))"); | ||
execute("INSERT INTO T VALUES (1, 'a'), (2, 'b')"); | ||
final Matcher<ResultSet> anyOrderMatcher = ResultSetStructureMatcher // | ||
.table()// | ||
.row(1, "a", 1) // | ||
.row(greaterThan(0), "b", 3) // | ||
.matchesInAnyOrder(); | ||
try(final ResultSet result = query("SELECT * FROM T")) { | ||
final AssertionError error = assertThrows(AssertionError.class, | ||
() -> anyOrderMatcher.matches(result)); | ||
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() | ||
throws SQLException { | ||
execute("CREATE TABLE T(I INTEGER, V VARCHAR(20))"); | ||
execute("INSERT INTO T VALUES (1, 'A'), (2, 'B')"); | ||
final Matcher<ResultSet> orderedMatcher = ResultSetStructureMatcher // | ||
.table()// | ||
.row(1, "A", 1) // | ||
.row(greaterThan(0), "B", 3) // | ||
.matches(); | ||
try (final ResultSet result = query("SELECT * FROM T")) { | ||
final AssertionError error = assertThrows(AssertionError.class, () -> orderedMatcher.matches(result)); | ||
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:")); | ||
|
||
} | ||
} | ||
} |