-
Notifications
You must be signed in to change notification settings - Fork 1.8k
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
Test for exceptions on wrong parameter types in Query, and column out of bounds #104
Merged
Merged
Changes from 2 commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
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
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 |
---|---|---|
|
@@ -3,6 +3,8 @@ | |
import static org.testng.AssertJUnit.*; | ||
import org.testng.annotations.Test; | ||
|
||
import java.util.Date; | ||
|
||
public class JNIQueryTest { | ||
|
||
Table table; | ||
|
@@ -45,4 +47,156 @@ public void shouldQuery() { | |
|
||
// TODO: Add tests with all parameters | ||
} | ||
|
||
@Test | ||
public void queryWithWrongDataType() { | ||
|
||
Table table = new Table(); | ||
|
||
table.addColumn(ColumnType.ColumnTypeBinary, "binary"); // 0 | ||
table.addColumn(ColumnType.ColumnTypeBool, "boolean"); // 1 | ||
table.addColumn(ColumnType.ColumnTypeDate, "date"); // 2 | ||
table.addColumn(ColumnType.ColumnTypeDouble, "double"); // 3 | ||
table.addColumn(ColumnType.ColumnTypeFloat, "float"); // 4 | ||
table.addColumn(ColumnType.ColumnTypeInt, "long"); // 5 | ||
table.addColumn(ColumnType.ColumnTypeMixed, "mixed"); // 6 | ||
table.addColumn(ColumnType.ColumnTypeString, "string"); // 7 | ||
table.addColumn(ColumnType.ColumnTypeTable, "table"); // 8 | ||
|
||
// Query the table | ||
TableQuery query = table.where(); | ||
|
||
// Compare strings in non string columns | ||
for(int i = 0; i <= 8; i++) { | ||
if(i != 7) { | ||
try { query.equal(i, "string"); assert(false); } catch(IllegalArgumentException e) {} | ||
try { query.notEqual(i, "string"); assert(false); } catch(IllegalArgumentException e) {} | ||
try { query.beginsWith(i, "string"); assert(false); } catch(IllegalArgumentException e) {} | ||
try { query.endsWith(i, "string"); assert(false); } catch(IllegalArgumentException e) {} | ||
try { query.contains(i, "string"); assert(false); } catch(IllegalArgumentException e) {} | ||
} | ||
} | ||
|
||
// Compare integer in non integer columns | ||
for(int i = 0; i <= 8; i++) { | ||
if(i != 5) { | ||
try { query.equal(i, 123); assert(false); } catch(IllegalArgumentException e) {} | ||
try { query.notEqual(i, 123); assert(false); } catch(IllegalArgumentException e) {} | ||
try { query.lessThan(i, 123); assert(false); } catch(IllegalArgumentException e) {} | ||
try { query.lessThanOrEqual(i, 123); assert(false); } catch(IllegalArgumentException e) {} | ||
try { query.greaterThan(i, 123); assert(false); } catch(IllegalArgumentException e) {} | ||
try { query.greaterThanOrEqual(i, 123); assert(false); } catch(IllegalArgumentException e) {} | ||
try { query.between(i, 123, 321); assert(false); } catch(IllegalArgumentException e) {} | ||
} | ||
} | ||
|
||
// Compare float in non float columns | ||
for(int i = 0; i <= 8; i++) { | ||
if(i != 4) { | ||
try { query.equal(i, 123F); assert(false); } catch(IllegalArgumentException e) {} | ||
try { query.notEqual(i, 123F); assert(false); } catch(IllegalArgumentException e) {} | ||
try { query.lessThan(i, 123F); assert(false); } catch(IllegalArgumentException e) {} | ||
try { query.lessThanOrEqual(i, 123F); assert(false); } catch(IllegalArgumentException e) {} | ||
try { query.greaterThan(i, 123F); assert(false); } catch(IllegalArgumentException e) {} | ||
try { query.greaterThanOrEqual(i, 123F); assert(false); } catch(IllegalArgumentException e) {} | ||
try { query.between(i, 123F, 321F); assert(false); } catch(IllegalArgumentException e) {} | ||
} | ||
} | ||
|
||
// Compare double in non double columns | ||
for(int i = 0; i <= 8; i++) { | ||
if(i != 3) { | ||
try { query.equal(i, 123D); assert(false); } catch(IllegalArgumentException e) {} | ||
try { query.notEqual(i, 123D); assert(false); } catch(IllegalArgumentException e) {} | ||
try { query.lessThan(i, 123D); assert(false); } catch(IllegalArgumentException e) {} | ||
try { query.lessThanOrEqual(i, 123D); assert(false); } catch(IllegalArgumentException e) {} | ||
try { query.greaterThan(i, 123D); assert(false); } catch(IllegalArgumentException e) {} | ||
try { query.greaterThanOrEqual(i, 123D); assert(false); } catch(IllegalArgumentException e) {} | ||
try { query.between(i, 123D, 321D); assert(false); } catch(IllegalArgumentException e) {} | ||
} | ||
} | ||
|
||
// Compare boolean in non boolean columns | ||
for(int i = 0; i <= 8; i++) { | ||
if(i != 1) { | ||
try { query.equal(i, true); assert(false); } catch(IllegalArgumentException e) {} | ||
} | ||
} | ||
|
||
// Compare date | ||
/* | ||
for(int i = 0; i <= 8; i++) { | ||
if(i != 2) { | ||
try { query.equal(i, new Date()); assert(false); } catch(IllegalArgumentException e) {} | ||
try { query.lessThan(i, new Date()); assert(false); } catch(IllegalArgumentException e) {} | ||
try { query.lessThanOrEqual(i, new Date()); assert(false); } catch(IllegalArgumentException e) {} | ||
try { query.greaterThan(i, new Date()); assert(false); } catch(IllegalArgumentException e) {} | ||
try { query.greaterThanOrEqual(i, new Date()); assert(false); } catch(IllegalArgumentException e) {} | ||
try { query.between(i, new Date(), new Date()); assert(false); } catch(IllegalArgumentException e) {} | ||
} | ||
} | ||
*/ | ||
} | ||
|
||
@Test | ||
public void columnIndexOutOfBounds() { | ||
Table table = new Table(); | ||
|
||
table.addColumn(ColumnType.ColumnTypeBinary, "binary"); // 0 | ||
table.addColumn(ColumnType.ColumnTypeBool, "boolean"); // 1 | ||
table.addColumn(ColumnType.ColumnTypeDate, "date"); // 2 | ||
table.addColumn(ColumnType.ColumnTypeDouble, "double"); // 3 | ||
table.addColumn(ColumnType.ColumnTypeFloat, "float"); // 4 | ||
table.addColumn(ColumnType.ColumnTypeInt, "long"); // 5 | ||
table.addColumn(ColumnType.ColumnTypeMixed, "mixed"); // 6 | ||
table.addColumn(ColumnType.ColumnTypeString, "string"); // 7 | ||
table.addColumn(ColumnType.ColumnTypeTable, "table"); // 8 | ||
|
||
// Query the table | ||
TableQuery query = table.where(); | ||
|
||
// Compare strings in non string columns | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Comments are wrong all the way down (copy/paste :-)?) |
||
try { query.equal(9, "string"); assert(false); } catch(ArrayIndexOutOfBoundsException e) {} | ||
try { query.notEqual(9, "string"); assert(false); } catch(ArrayIndexOutOfBoundsException e) {} | ||
try { query.beginsWith(9, "string"); assert(false); } catch(ArrayIndexOutOfBoundsException e) {} | ||
try { query.endsWith(9, "string"); assert(false); } catch(ArrayIndexOutOfBoundsException e) {} | ||
try { query.contains(9, "string"); assert(false); } catch(ArrayIndexOutOfBoundsException e) {} | ||
|
||
|
||
// Compare integer in non integer columns | ||
try { query.equal(9, 123); assert(false); } catch(ArrayIndexOutOfBoundsException e) {} | ||
try { query.notEqual(9, 123); assert(false); } catch(ArrayIndexOutOfBoundsException e) {} | ||
try { query.lessThan(9, 123); assert(false); } catch(ArrayIndexOutOfBoundsException e) {} | ||
try { query.lessThanOrEqual(9, 123); assert(false); } catch(ArrayIndexOutOfBoundsException e) {} | ||
try { query.greaterThan(9, 123); assert(false); } catch(ArrayIndexOutOfBoundsException e) {} | ||
try { query.greaterThanOrEqual(9, 123); assert(false); } catch(ArrayIndexOutOfBoundsException e) {} | ||
try { query.between(9, 123, 321); assert(false); } catch(ArrayIndexOutOfBoundsException e) {} | ||
|
||
|
||
// Compare float in non float columns | ||
try { query.equal(9, 123F); assert(false); } catch(ArrayIndexOutOfBoundsException e) {} | ||
try { query.notEqual(9, 123F); assert(false); } catch(ArrayIndexOutOfBoundsException e) {} | ||
try { query.lessThan(9, 123F); assert(false); } catch(ArrayIndexOutOfBoundsException e) {} | ||
try { query.lessThanOrEqual(9, 123F); assert(false); } catch(ArrayIndexOutOfBoundsException e) {} | ||
try { query.greaterThan(9, 123F); assert(false); } catch(ArrayIndexOutOfBoundsException e) {} | ||
try { query.greaterThanOrEqual(9, 123F); assert(false); } catch(ArrayIndexOutOfBoundsException e) {} | ||
try { query.between(9, 123F, 321F); assert(false); } catch(ArrayIndexOutOfBoundsException e) {} | ||
|
||
|
||
// Compare double in non double columns | ||
|
||
try { query.equal(9, 123D); assert(false); } catch(ArrayIndexOutOfBoundsException e) {} | ||
try { query.notEqual(9, 123D); assert(false); } catch(ArrayIndexOutOfBoundsException e) {} | ||
try { query.lessThan(9, 123D); assert(false); } catch(ArrayIndexOutOfBoundsException e) {} | ||
try { query.lessThanOrEqual(9, 123D); assert(false); } catch(ArrayIndexOutOfBoundsException e) {} | ||
try { query.greaterThan(9, 123D); assert(false); } catch(ArrayIndexOutOfBoundsException e) {} | ||
try { query.greaterThanOrEqual(9, 123D); assert(false); } catch(ArrayIndexOutOfBoundsException e) {} | ||
try { query.between(9, 123D, 321D); assert(false); } catch(ArrayIndexOutOfBoundsException e) {} | ||
|
||
|
||
// Compare boolean in non boolean columns | ||
try { query.equal(9, true); assert(false); } catch(ArrayIndexOutOfBoundsException e) {} | ||
|
||
} | ||
|
||
} |
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.
In TestHelper there is a static method getTableWithAllColumnTypes, that returns excactly this
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.
Yes, but TestHelper is not in develop, it is in Breaking-updates
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.
Good point :)