From db427675ccb1adaddabccc5813cfe12b9c6cbf6b Mon Sep 17 00:00:00 2001 From: sayam Date: Sun, 19 Jan 2020 15:09:21 +0530 Subject: [PATCH 1/2] Setup instrumentation tests --- .../offix/ExampleInstrumentedTest.java | 26 ------------ .../aerogear/offix/ExampleInstrumentedTest.kt | 41 +++++++++++++++++++ 2 files changed, 41 insertions(+), 26 deletions(-) delete mode 100644 offix/src/androidTest/java/org/aerogear/offix/ExampleInstrumentedTest.java create mode 100644 offix/src/androidTest/java/org/aerogear/offix/ExampleInstrumentedTest.kt diff --git a/offix/src/androidTest/java/org/aerogear/offix/ExampleInstrumentedTest.java b/offix/src/androidTest/java/org/aerogear/offix/ExampleInstrumentedTest.java deleted file mode 100644 index 3e85363..0000000 --- a/offix/src/androidTest/java/org/aerogear/offix/ExampleInstrumentedTest.java +++ /dev/null @@ -1,26 +0,0 @@ -package org.aerogear.offix; - -import android.content.Context; -import android.support.test.InstrumentationRegistry; -import android.support.test.runner.AndroidJUnit4; - -import org.junit.Test; -import org.junit.runner.RunWith; - -import static org.junit.Assert.*; - -/** - * Instrumented test, which will execute on an Android device. - * - * @see Testing documentation - */ -@RunWith(AndroidJUnit4.class) -public class ExampleInstrumentedTest { - @Test - public void useAppContext() { - // Context of the app under test. - Context appContext = InstrumentationRegistry.getTargetContext(); - - assertEquals("org.aerogear.offixsdk.test", appContext.getPackageName()); - } -} diff --git a/offix/src/androidTest/java/org/aerogear/offix/ExampleInstrumentedTest.kt b/offix/src/androidTest/java/org/aerogear/offix/ExampleInstrumentedTest.kt new file mode 100644 index 0000000..2c1bf91 --- /dev/null +++ b/offix/src/androidTest/java/org/aerogear/offix/ExampleInstrumentedTest.kt @@ -0,0 +1,41 @@ +package org.aerogear.offix + +import android.content.Context +import android.support.test.InstrumentationRegistry +import android.support.test.runner.AndroidJUnit4 + +import org.junit.Test; +import org.junit.runner.RunWith; + +import org.junit.Assert.* + +import org.aerogear.offix.persistence.MutationDao +import org.aerogear.offix.getDao +import org.aerogear.offix.persistence.Mutation + +/** + * Instrumented test, which will execute on an Android device. + * + * @see Testing documentation + */ + +@RunWith(AndroidJUnit4::class) +class ExampleInstrumentedTest { + + @Test + fun useAppContext() { + // Context of the app under test. + val appContext = InstrumentationRegistry.getTargetContext(); + + assertEquals("org.aerogear.offixsdk.test", appContext.getPackageName()); + } + + @Test + fun AddMutation(){ + + getDao()?.deleteAllMutations() + val size = getDao()?.getAllMutations()?.size + + + } +} From 9cbb70b6f3ad8d54f81444645ceb4a5abfad82ba Mon Sep 17 00:00:00 2001 From: sayam Date: Mon, 20 Jan 2020 06:48:35 +0530 Subject: [PATCH 2/2] Added Instrumentation Tests For Library --- offix/build.gradle | 1 - .../aerogear/offix/ExampleInstrumentedTest.kt | 71 ++++++++++++++++--- 2 files changed, 61 insertions(+), 11 deletions(-) diff --git a/offix/build.gradle b/offix/build.gradle index 57776c0..09debd1 100644 --- a/offix/build.gradle +++ b/offix/build.gradle @@ -26,7 +26,6 @@ android { targetSdkVersion 28 versionCode 1 versionName "1.0" - testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" } diff --git a/offix/src/androidTest/java/org/aerogear/offix/ExampleInstrumentedTest.kt b/offix/src/androidTest/java/org/aerogear/offix/ExampleInstrumentedTest.kt index 2c1bf91..4b522c2 100644 --- a/offix/src/androidTest/java/org/aerogear/offix/ExampleInstrumentedTest.kt +++ b/offix/src/androidTest/java/org/aerogear/offix/ExampleInstrumentedTest.kt @@ -1,17 +1,18 @@ package org.aerogear.offix -import android.content.Context +// Imports import android.support.test.InstrumentationRegistry import android.support.test.runner.AndroidJUnit4 -import org.junit.Test; -import org.junit.runner.RunWith; + +import org.junit.Test +import org.junit.runner.RunWith import org.junit.Assert.* -import org.aerogear.offix.persistence.MutationDao -import org.aerogear.offix.getDao import org.aerogear.offix.persistence.Mutation +import org.json.JSONObject +import com.apollographql.apollo.api.OperationName /** * Instrumented test, which will execute on an Android device. @@ -22,20 +23,70 @@ import org.aerogear.offix.persistence.Mutation @RunWith(AndroidJUnit4::class) class ExampleInstrumentedTest { + // Test Mutation + private val testOperation = OperationName { "testOperation" } + private val testJson = JSONObject("{'value':'test'}") + + private val testMutation = Mutation(operationId = "1",queryDoc = "test",operationName = testOperation, + valueMap = testJson,responseClassName = "testClass") + @Test fun useAppContext() { // Context of the app under test. - val appContext = InstrumentationRegistry.getTargetContext(); + val appContext = InstrumentationRegistry.getTargetContext() - assertEquals("org.aerogear.offixsdk.test", appContext.getPackageName()); + assertEquals("org.aerogear.offix.test", appContext.getPackageName()) + } + + // Check Delete All Mutations + @Test + fun CheckDeleteAllMutation(){ + getDao()?.deleteAllMutations() + assertEquals(0,getDao()?.getAllMutations()?.size) } + // Check Mutation Insert and Get A Mutation Method @Test - fun AddMutation(){ + fun CheckInsertMutation(){ getDao()?.deleteAllMutations() - val size = getDao()?.getAllMutations()?.size - + // Insert the mutation and get the snNo And Convert it into Non-nullable Int + val snNo = getDao()?.insertMutation(testMutation)?.toInt()!! + val testMutation = getDao()?.getAMutation(snNo) + + assertEquals("1",testMutation?.operationId) } + + + // Check Delete Mutation by snNo + @Test + fun CheckDeleteCurrentMutation(){ + + getDao()?.deleteAllMutations() + val snNo = getDao()?.insertMutation(testMutation)?.toInt()!! + + assertEquals(1,getDao()?.getAllMutations()?.size) + + getDao()?.deleteCurrentMutation(snNo) + + assertEquals(0,getDao()?.getAllMutations()?.size) + } + + // Check Delete Mutation + @Test + fun CheckDeleteMutation(){ + + getDao()?.deleteAllMutations() + + val snNo = getDao()?.insertMutation(testMutation)?.toInt()!! + + assertEquals(1,getDao()?.getAllMutations()?.size) + + val testMutation = getDao()?.getAMutation(snNo)!! + getDao()?.deleteMutation(testMutation) + + assertEquals(0,getDao()?.getAllMutations()?.size) + } + }