-
Notifications
You must be signed in to change notification settings - Fork 2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
#44: Improved assertion message when more columns expected than present. #47
Merged
redcatbear
merged 6 commits into
main
from
bugfix/44_assertion-fails-with-arrayindexoutofboundsexception-when-too-many-columns-are-expected
Oct 27, 2023
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
92a1ff4
#44: Improved reporting of situation where more columns are expected …
redcatbear 7020688
#44: Fixed broken test name.
redcatbear 51e0379
#44: Fixed indexing. Added test for in-order matching.
redcatbear d3f3553
Fixed lambda code smells.
redcatbear 437b478
Added missing `final`.
redcatbear 443c6dd
#44: Extracted query.
redcatbear File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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:")); | ||
|
||
} | ||
} | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.