Skip to content
This repository has been archived by the owner on Mar 24, 2021. It is now read-only.

Added Instrumentation Tests For Library #199

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion offix/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ android {
targetSdkVersion 28
versionCode 1
versionName "1.0"

testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}

Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
package org.aerogear.offix

// Imports
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.Mutation
import org.json.JSONObject
import com.apollographql.apollo.api.OperationName

/**
* Instrumented test, which will execute on an Android device.
*
* @see <a href="http://d.android.com/tools/testing">Testing documentation</a>
*/

@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()

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 CheckInsertMutation(){

getDao()?.deleteAllMutations()

// 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)
}

}