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 {
79
79
implementation ' com.jakewharton.retrofit:retrofit2-kotlin-coroutines-adapter:0.9.2'
80
80
81
81
testImplementation ' junit:junit:4.12'
82
+ testImplementation " org.jetbrains.kotlin:kotlin-test-junit:$kotlin_version "
82
83
}
83
84
84
85
apply from : ' build.publish.gradle'
Original file line number Diff line number Diff line change @@ -2,22 +2,25 @@ package jp.studyplus.android.sdk
2
2
3
3
import jp.studyplus.android.sdk.internal.api.MockApiClient
4
4
import jp.studyplus.android.sdk.record.StudyRecordBuilder
5
+ import kotlinx.coroutines.runBlocking
5
6
import org.junit.Test
7
+ import kotlin.test.assertEquals
8
+ import kotlin.test.assertNull
6
9
7
10
class ApiUnitTest {
8
11
9
12
@Test
10
13
fun mockApi () {
11
14
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
+ }
22
25
}
23
26
}
Original file line number Diff line number Diff line change 1
1
package jp.studyplus.android.sdk.internal.api
2
2
3
3
import android.content.Context
4
- import io.reactivex.Observable
5
- import jp.studyplus.android.sdk.internal.api.response.PostStudyRecordsResponse
6
4
import jp.studyplus.android.sdk.record.StudyRecord
7
5
import retrofit2.mock.MockRetrofit
8
6
9
- internal class MockApiClient
10
- constructor (retrofit: MockRetrofit ) {
7
+ internal class MockApiClient constructor(retrofit : MockRetrofit ) {
11
8
12
9
companion object {
13
10
val apiClient by lazy { MockApiClient (MockApiManager .retrofit) }
@@ -19,7 +16,6 @@ constructor(retrofit: MockRetrofit) {
19
16
apiService = MockApiService (delegate)
20
17
}
21
18
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)
25
21
}
Original file line number Diff line number Diff line change 1
1
package jp.studyplus.android.sdk.internal.api
2
2
3
- import io.reactivex.Observable
4
3
import jp.studyplus.android.sdk.internal.api.response.PostStudyRecordsResponse
5
4
import jp.studyplus.android.sdk.record.StudyRecord
5
+ import kotlinx.coroutines.Deferred
6
6
import retrofit2.mock.BehaviorDelegate
7
7
8
8
internal 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 > {
10
10
return delegate.returningResponse(PostStudyRecordsResponse (9999 )).postStudyRecords(oauth, studyRecord)
11
11
}
12
12
}
You can’t perform that action at this time.
0 commit comments