Skip to content
This repository was archived by the owner on Jun 28, 2019. It is now read-only.

Commit d53d634

Browse files
committed
テストコード更新
1 parent 512e4c6 commit d53d634

File tree

4 files changed

+19
-19
lines changed

4 files changed

+19
-19
lines changed

studyplus-android-sdk2/build.gradle

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff 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

8485
apply from: 'build.publish.gradle'

studyplus-android-sdk2/src/test/java/jp/studyplus/android/sdk/ApiUnitTest.kt

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,22 +2,25 @@ package jp.studyplus.android.sdk
22

33
import jp.studyplus.android.sdk.internal.api.MockApiClient
44
import jp.studyplus.android.sdk.record.StudyRecordBuilder
5+
import kotlinx.coroutines.runBlocking
56
import org.junit.Test
7+
import kotlin.test.assertEquals
8+
import kotlin.test.assertNull
69

710
class 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
}
Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,10 @@
11
package jp.studyplus.android.sdk.internal.api
22

33
import android.content.Context
4-
import io.reactivex.Observable
5-
import jp.studyplus.android.sdk.internal.api.response.PostStudyRecordsResponse
64
import jp.studyplus.android.sdk.record.StudyRecord
75
import 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
}
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
package jp.studyplus.android.sdk.internal.api
22

3-
import io.reactivex.Observable
43
import jp.studyplus.android.sdk.internal.api.response.PostStudyRecordsResponse
54
import jp.studyplus.android.sdk.record.StudyRecord
5+
import kotlinx.coroutines.Deferred
66
import retrofit2.mock.BehaviorDelegate
77

88
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> {
1010
return delegate.returningResponse(PostStudyRecordsResponse(9999)).postStudyRecords(oauth, studyRecord)
1111
}
1212
}

0 commit comments

Comments
 (0)