Skip to content

Commit

Permalink
Added additional tests for where-chaining.
Browse files Browse the repository at this point in the history
  • Loading branch information
mpfeiffermway committed Apr 17, 2014
1 parent a980772 commit 25ea077
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 0 deletions.
61 changes: 61 additions & 0 deletions tests/src/com/activeandroid/test/query/FromTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,67 @@ public void testWhereWithArguments() {
query);
}

public void testWhereChaining() {

From expected = from()
.where("a = ? AND b = ?", 1, 2);

From actual = from()
.where("a = ?", 1, 2)
.where("b = ?", 1, 2);

assertSqlEquals(expected, actual);
}

public void testWhereAndChaining() {

From expected = from()
.where("a = ? AND b = ?", 1, 2);

From actual = from()
.where("a = ?", 1)
.and("b = ?", 2);

assertSqlEquals(expected, actual);
}

public void testWhereOrChaining() {

From expected = from()
.where("a = ? OR b = ?", 1, 2);

From actual = from()
.where("a = ?", 1)
.or("b = ?", 2);

assertSqlEquals(expected, actual);
}

public void testWhereAndOrChaining() {

From expected = from()
.where("a = ? OR (b = ? AND c = ?)", 1, 2, 3);

From actual = from()
.where("a = ?", 1)
.or("(b = ? AND c = ?)", 2, 3);

assertSqlEquals(expected, actual);
}

public void testWhereAlternateAndOrChaining() {

From expected = from()
.where("a = ? OR (b = ? AND c = ?)", 1, 2, 3);

From actual = from()
.where("a = ?", 1)
.or("(b = ?", 2)
.and("c = ?)", 3);

assertSqlEquals(expected, actual);
}

// Test with 'no arguments' and 'with arguments' chained together.
public void testWhereWithNoArgumentsAndWithArguments() {
From query = from().where("Id = 5");
Expand Down
4 changes: 4 additions & 0 deletions tests/src/com/activeandroid/test/query/SqlableTestCase.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,8 @@ public abstract class SqlableTestCase extends ActiveAndroidTestCase {
public static void assertSqlEquals(String expected, Sqlable actual) {
assertEquals(expected, actual.toSql());
}

public static void assertSqlEquals(Sqlable expected, Sqlable actual) {
assertEquals(expected.toSql(), actual.toSql());
}
}

0 comments on commit 25ea077

Please sign in to comment.