diff options
Diffstat (limited to 'src/test')
-rw-r--r-- | src/test/java/de/xenoworld/ormpaloompa/TableTest.java | 43 | ||||
-rw-r--r-- | src/test/java/de/xenoworld/ormpaloompa/testutils/DBRule.java | 5 |
2 files changed, 34 insertions, 14 deletions
diff --git a/src/test/java/de/xenoworld/ormpaloompa/TableTest.java b/src/test/java/de/xenoworld/ormpaloompa/TableTest.java index 79b3a0c..d73b45f 100644 --- a/src/test/java/de/xenoworld/ormpaloompa/TableTest.java +++ b/src/test/java/de/xenoworld/ormpaloompa/TableTest.java @@ -1,6 +1,6 @@ package de.xenoworld.ormpaloompa; -import de.xenoworld.ormpaloompa.annotations.Field; +import de.xenoworld.ormpaloompa.annotations.Column; import de.xenoworld.ormpaloompa.annotations.TableInfo; import de.xenoworld.ormpaloompa.testutils.DBRule; import org.junit.Ignore; @@ -18,27 +18,27 @@ import static org.hamcrest.Matchers.hasSize; import static org.hamcrest.Matchers.is; /** - * Test object with explicit identity + * Test object with explicit identity, and an alternative name for a field. */ class Bird { - @Field(identity = true) + @Column(identity = true) public Integer id; - @Field + @Column public String name; - @Field + @Column(name = "descr") public String description; } /** - * Test object with no explicit identity + * Test object with no explicit identity. */ class Rabbit { - @Field + @Column public Integer id; - @Field + @Column public String name; } @@ -48,10 +48,10 @@ class Rabbit { */ @TableInfo(tableName = "foxes") class Fox { - @Field(identity = true) + @Column(identity = true) public String name; - @Field(identity = true) + @Column(identity = true) public Integer id; } @@ -60,13 +60,13 @@ class Fox { */ @TableInfo class Monkey { - @Field + @Column public String name; } public class TableTest { static String[] FIXTURES = { - "CREATE TABLE birds (id INTEGER PRIMARY KEY, name TEXT, description TEXT);", + "CREATE TABLE birds (id INTEGER PRIMARY KEY, name TEXT, descr TEXT);", "INSERT INTO birds " + "(id, name) " + "VALUES " + @@ -100,7 +100,7 @@ public class TableTest { public DBRule dbRule = new DBRule(FIXTURES); /** - * The field `id` should be annotated as `@Field`, but it should not have + * The field `id` should be annotated as `@Column`, but it should not have * property `identity` set to `true`. The field should be recognised as * identity by virtue of being named `id`. */ @@ -239,4 +239,21 @@ public class TableTest { assertThat("Table size did not change", table.count(), is(4)); assertThat("No new entries were added", insertId.isPresent(), is(false)); } + + @Test + public void testFind_brokenQuery() throws Exception { + long count; + Table<Bird> table = new Table<>(Bird.class, dbRule.getConnection()); + + Bird newBird = new Bird(); + newBird.name = "A new bird"; + + table.insert(newBird); + + count = table.find(where("id = 1")).count(); + assertThat("Table has one entry", count, is(1L)); + + count = table.find(where("broken = 1234")).count(); + assertThat("Query returns turns up empty", count, is(0L)); + } }
\ No newline at end of file diff --git a/src/test/java/de/xenoworld/ormpaloompa/testutils/DBRule.java b/src/test/java/de/xenoworld/ormpaloompa/testutils/DBRule.java index 0bb12f7..39da3d8 100644 --- a/src/test/java/de/xenoworld/ormpaloompa/testutils/DBRule.java +++ b/src/test/java/de/xenoworld/ormpaloompa/testutils/DBRule.java @@ -2,7 +2,10 @@ package de.xenoworld.ormpaloompa.testutils; import org.junit.rules.ExternalResource; -import java.sql.*; +import java.sql.Connection; +import java.sql.DriverManager; +import java.sql.SQLException; +import java.sql.Statement; import java.util.stream.Stream; public class DBRule extends ExternalResource { |