Created
February 26, 2018 10:53
-
-
Save wickedev/7a4764c3ac12cc3c50546c2ac5f3ea17 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@file:Suppress("IllegalIdentifier") | |
package com.novonetworks.mojito.common.db.dao | |
import android.arch.persistence.room.Room | |
import com.novonetworks.mojito.BuildConfig | |
import com.novonetworks.mojito.base.TestApp | |
import com.novonetworks.mojito.common.db.AppDatabase | |
import com.novonetworks.mojito.common.vo.Owner | |
import com.winterbe.expekt.should | |
import io.reactivex.subscribers.TestSubscriber | |
import org.junit.Test | |
import org.junit.runner.RunWith | |
import org.robolectric.RobolectricTestRunner | |
import org.robolectric.RuntimeEnvironment | |
import org.robolectric.annotation.Config | |
@RunWith(RobolectricTestRunner::class) | |
@Config(constants = BuildConfig::class, application = TestApp::class) | |
class OwnerDaoTest { | |
@Test | |
fun `owner should be correct result after save`() { | |
val context = RuntimeEnvironment.application | |
val appDatabase = Room.inMemoryDatabaseBuilder(context, AppDatabase::class.java) | |
.allowMainThreadQueries() | |
.build() | |
val ownerDao = appDatabase.ownerDao() | |
val observer = TestSubscriber<Owner>() | |
val owner = Owner(userId = 1, | |
email = "[email protected]", | |
name = "owner", | |
statusMessage = "status message", | |
blockToFind = true, | |
blockToUnknownMessage = true, | |
dailyEngPush = true, | |
isDailyEngUpdated = true, | |
isWebtoonUpdated = true, | |
isKorean = true, | |
contentId = "content_id", | |
wallpaperContentId = "wallpaper_content_id") | |
owner.userId.should.be.equal(1) | |
owner.email.should.be.equal("[email protected]") | |
ownerDao.save(owner) | |
ownerDao.find().subscribe(observer) | |
observer.awaitCount(1) | |
val result = observer.values()[0] | |
result.should.be.equal(owner) | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.novonetworks.mojito.common.network.api | |
import com.novonetworks.mojito.base.BaseSpek | |
import com.novonetworks.mojito.base.extentions.apiUtil | |
import com.winterbe.expekt.should | |
import org.jetbrains.spek.api.dsl.it | |
class UserApiTest : BaseSpek({ | |
it("owner api should be success") { | |
val userApi = apiUtil.mockApi(UserApi::class) | |
apiUtil.enqueueResponseJson(""" | |
{ | |
"userID": 47, | |
"email": "[email protected]", | |
"name": "orange", | |
"stateMsg": "good!?", | |
"blockToFind": false, | |
"blockToUnknownMsg": false, | |
"silPush": false, | |
"isSilUpdated": true, | |
"isWtUpdated": true, | |
"isKorean": false, | |
"userContentID": "fd115b3a-c740-480f-bbf2-6da9303827ae", | |
"wallPaperContentID": "499bbadb-f976-4cbd-b3d5-9bccc7be9d06" | |
} | |
""".trimIndent()) | |
val response = userApi.getUser().blockingGet() | |
val owner = response.body | |
response.isSuccessful.should.be.`true` | |
owner.should.not.`null` | |
owner?.userId.should.be.equal(47) | |
} | |
}) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@file:Suppress("IllegalIdentifier") | |
package com.novonetworks.mojito.common.repository | |
import com.novonetworks.mojito.base.BaseRobolectricTest | |
import com.novonetworks.mojito.base.extentions.apiUtil | |
import com.novonetworks.mojito.base.extentions.appDatabase | |
import com.novonetworks.mojito.base.extentions.appExecutor | |
import com.novonetworks.mojito.common.network.api.UserApi | |
import com.novonetworks.mojito.common.repository.strategy.FetchingStrategy | |
import com.novonetworks.mojito.common.vo.Owner | |
import com.novonetworks.mojito.common.vo.resouce.Resource | |
import com.winterbe.expekt.should | |
import io.reactivex.subscribers.TestSubscriber | |
import org.junit.Test | |
import timber.log.Timber | |
import java.util.concurrent.TimeUnit | |
class OwnerRepositoryTest : BaseRobolectricTest() { | |
@Test(timeout = 30000) | |
fun `owner repository should be success`() { | |
val userApi = apiUtil.mockApi(UserApi::class) | |
val ownerDao = appDatabase.ownerDao() | |
val observer = TestSubscriber<Resource<Owner>>() | |
apiUtil.enqueueResponseJson(""" | |
{ | |
"userID": 47, | |
"email": "[email protected]", | |
"name": "orange", | |
"stateMsg": "good!?", | |
"blockToFind": false, | |
"blockToUnknownMsg": false, | |
"silPush": false, | |
"isSilUpdated": true, | |
"isWtUpdated": true, | |
"isKorean": false, | |
"userContentID": "fd115b3a-c740-480f-bbf2-6da9303827ae", | |
"wallPaperContentID": "499bbadb-f976-4cbd-b3d5-9bccc7be9d06" | |
} | |
""".trimIndent()) | |
val repository = OwnerRepository(userApi = userApi, | |
ownerDao = ownerDao, | |
appExecutors = appExecutor) | |
repository.getOwner() | |
.toFlowable() | |
.takeUntil { it.isSuccess() } | |
.subscribe(observer) | |
observer.await() | |
observer.values()[0].isLoading().should.be.`true` | |
val resource = observer.values()[1] | |
resource.isSuccess().should.be.`true` | |
val owner = resource.data | |
owner.should.not.`null` | |
owner?.userId.should.be.equal(47) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment