This repository was archived by the owner on Jun 28, 2019. It is now read-only.
File tree Expand file tree Collapse file tree
src/test/java/jp/studyplus/android/sdk Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -60,6 +60,12 @@ android {
6060 }
6161 }
6262 }
63+
64+ testOptions {
65+ unitTests {
66+ includeAndroidResources = true
67+ }
68+ }
6369}
6470
6571dependencies {
@@ -74,6 +80,7 @@ dependencies {
7480 implementation " com.squareup.okhttp3:okhttp:$okhttp "
7581
7682 testImplementation ' junit:junit:4.12'
83+ testImplementation ' org.robolectric:robolectric:4.0.2'
7784 testImplementation " org.jetbrains.kotlin:kotlin-test-junit:$kotlin_version "
7885 testImplementation " com.squareup.okhttp3:mockwebserver:$okhttp "
7986}
Original file line number Diff line number Diff line change @@ -4,9 +4,12 @@ import jp.studyplus.android.sdk.internal.api.MockApiClient
44import jp.studyplus.android.sdk.record.StudyRecordBuilder
55import kotlinx.coroutines.runBlocking
66import org.junit.Test
7+ import org.junit.runner.RunWith
8+ import org.robolectric.RobolectricTestRunner
79import kotlin.test.assertEquals
810import kotlin.test.assertNull
911
12+ @RunWith(RobolectricTestRunner ::class )
1013class ApiUnitTest {
1114
1215 @Test
Original file line number Diff line number Diff line change @@ -5,12 +5,13 @@ import okhttp3.OkHttpClient
55import okhttp3.Request
66import okhttp3.mockwebserver.MockResponse
77import okhttp3.mockwebserver.MockWebServer
8+ import org.json.JSONObject
89
910internal class MockApiService (private val client : OkHttpClient ) {
1011
1112 fun post (json : String ): Deferred <Long ?> {
1213 val server = MockWebServer ()
13- server.enqueue(MockResponse ().setBody(""" "{ "record_id": 9999L} """ ))
14+ server.enqueue(MockResponse ().setBody(JSONObject (). apply { put( " record_id" , 9999L ) }.toString() ))
1415 server.start()
1516
1617 val body = createPostBody(json)
You can’t perform that action at this time.
0 commit comments