This repository was archived by the owner on Jun 28, 2019. It is now read-only.
File tree Expand file tree Collapse file tree 4 files changed +19
-19
lines changed
src/test/java/jp/studyplus/android/sdk Expand file tree Collapse file tree 4 files changed +19
-19
lines changed Original file line number Diff line number Diff line change @@ -79,6 +79,7 @@ dependencies {
7979 implementation ' com.jakewharton.retrofit:retrofit2-kotlin-coroutines-adapter:0.9.2'
8080
8181 testImplementation ' junit:junit:4.12'
82+ testImplementation " org.jetbrains.kotlin:kotlin-test-junit:$kotlin_version "
8283}
8384
8485apply from : ' build.publish.gradle'
Original file line number Diff line number Diff line change @@ -2,22 +2,25 @@ package jp.studyplus.android.sdk
22
33import jp.studyplus.android.sdk.internal.api.MockApiClient
44import jp.studyplus.android.sdk.record.StudyRecordBuilder
5+ import kotlinx.coroutines.runBlocking
56import org.junit.Test
7+ import kotlin.test.assertEquals
8+ import kotlin.test.assertNull
69
710class ApiUnitTest {
811
912 @Test
1013 fun mockApi () {
1114 val record = StudyRecordBuilder ().build()
12- MockApiClient .apiClient.postStudyRecords( null , record)
13- .test()
14- .assertNoErrors( )
15- .assertValue {
16- it.recordId?. let {
17- it == 9999L
18- } ? : run {
19- false
20- }
21- }
15+ runBlocking {
16+ try {
17+ val deferred = MockApiClient .apiClient.postStudyRecords( null , record )
18+ val result = deferred.await()
19+
20+ assertEquals(result.recordId, 9999L )
21+ } catch (t : Throwable ) {
22+ assertNull(t)
23+ }
24+ }
2225 }
2326}
Original file line number Diff line number Diff line change 11package jp.studyplus.android.sdk.internal.api
22
33import android.content.Context
4- import io.reactivex.Observable
5- import jp.studyplus.android.sdk.internal.api.response.PostStudyRecordsResponse
64import jp.studyplus.android.sdk.record.StudyRecord
75import retrofit2.mock.MockRetrofit
86
9- internal class MockApiClient
10- constructor (retrofit: MockRetrofit ) {
7+ internal class MockApiClient constructor(retrofit : MockRetrofit ) {
118
129 companion object {
1310 val apiClient by lazy { MockApiClient (MockApiManager .retrofit) }
@@ -19,7 +16,6 @@ constructor(retrofit: MockRetrofit) {
1916 apiService = MockApiService (delegate)
2017 }
2118
22- fun postStudyRecords (context : Context ? , studyRecord : StudyRecord ): Observable <PostStudyRecordsResponse > {
23- return apiService.postStudyRecords(" " , studyRecord)
24- }
19+ fun postStudyRecords (context : Context ? , studyRecord : StudyRecord ) =
20+ apiService.postStudyRecords(" " , studyRecord)
2521}
Original file line number Diff line number Diff line change 11package jp.studyplus.android.sdk.internal.api
22
3- import io.reactivex.Observable
43import jp.studyplus.android.sdk.internal.api.response.PostStudyRecordsResponse
54import jp.studyplus.android.sdk.record.StudyRecord
5+ import kotlinx.coroutines.Deferred
66import retrofit2.mock.BehaviorDelegate
77
88internal class MockApiService (private val delegate : BehaviorDelegate <ApiService >) : ApiService {
9- override fun postStudyRecords (oauth : String , studyRecord : StudyRecord ): Observable <PostStudyRecordsResponse > {
9+ override fun postStudyRecords (oauth : String , studyRecord : StudyRecord ): Deferred <PostStudyRecordsResponse > {
1010 return delegate.returningResponse(PostStudyRecordsResponse (9999 )).postStudyRecords(oauth, studyRecord)
1111 }
1212}
You can’t perform that action at this time.
0 commit comments