From c07bb49567337c73e4bf55120e6dbee3c3d67ea1 Mon Sep 17 00:00:00 2001 From: Jayahari Vavachan Date: Wed, 6 Feb 2019 14:45:15 -0800 Subject: [PATCH] test: add empty args exception check (#1859) * checking empty args in unit tests --- .../java/com/couchbase/lite/DatabaseTest.java | 14 +++++++++++ .../java/com/couchbase/lite/QueryTest.java | 23 +++++++++++++++++++ 2 files changed, 37 insertions(+) diff --git a/android/CouchbaseLite/src/androidTest/java/com/couchbase/lite/DatabaseTest.java b/android/CouchbaseLite/src/androidTest/java/com/couchbase/lite/DatabaseTest.java index 2966acf47..e09c34aea 100644 --- a/android/CouchbaseLite/src/androidTest/java/com/couchbase/lite/DatabaseTest.java +++ b/android/CouchbaseLite/src/androidTest/java/com/couchbase/lite/DatabaseTest.java @@ -23,7 +23,9 @@ import org.junit.After; import org.junit.Before; +import org.junit.Rule; import org.junit.Test; +import org.junit.rules.ExpectedException; import java.io.File; import java.util.ArrayList; @@ -43,6 +45,9 @@ public class DatabaseTest extends BaseTest { final static String kDatabaseTestBlob = "i'm blob"; + @Rule + public ExpectedException thrown = ExpectedException.none(); + //--------------------------------------------- // Helper methods //--------------------------------------------- @@ -1390,6 +1395,15 @@ public void testCreateIndex() throws CouchbaseLiteException { Log.i(TAG, "db.getIndexes() -> " + db.getIndexes()); } + @Test + public void testIndexBuilderEmptyArgs() { + thrown.expect(IllegalArgumentException.class); + IndexBuilder.fullTextIndex(null); + + thrown.expect(IllegalArgumentException.class); + IndexBuilder.valueIndex(null); + } + @Test public void testCreateSameIndexTwice() throws CouchbaseLiteException { // Create index with first name: diff --git a/android/CouchbaseLite/src/androidTest/java/com/couchbase/lite/QueryTest.java b/android/CouchbaseLite/src/androidTest/java/com/couchbase/lite/QueryTest.java index ef3576b86..2589a3d2f 100644 --- a/android/CouchbaseLite/src/androidTest/java/com/couchbase/lite/QueryTest.java +++ b/android/CouchbaseLite/src/androidTest/java/com/couchbase/lite/QueryTest.java @@ -1637,6 +1637,29 @@ public void testJoinWithArrayContains() throws Exception { Log.e(TAG, "RESULT: " + r.toMap()); } + @Test + public void testJoinWithEmptyArgs() { + DataSource mainDS = DataSource.database(this.db).as("main"); + + thrown.expect(IllegalArgumentException.class); + QueryBuilder.select(SelectResult.all()).from(mainDS).join(null); + + thrown.expect(IllegalArgumentException.class); + QueryBuilder.select(SelectResult.all()).from(mainDS).where(null); + + thrown.expect(IllegalArgumentException.class); + QueryBuilder.select(SelectResult.all()).from(mainDS).groupBy(null); + + thrown.expect(IllegalArgumentException.class); + QueryBuilder.select(SelectResult.all()).from(mainDS).orderBy(null); + + thrown.expect(IllegalArgumentException.class); + QueryBuilder.select(SelectResult.all()).from(mainDS).limit(null); + + thrown.expect(IllegalArgumentException.class); + QueryBuilder.select(SelectResult.all()).from(mainDS).limit(null, null); + } + //https://github.com/couchbase/couchbase-lite-android/issues/1785 @Test public void testResultToMapWithBoolean() throws Exception {