Skip to content

Commit

Permalink
Refactor unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
cuongpm committed Feb 17, 2019
1 parent 3c6de5b commit 46d49c4
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@ package com.youtubedl.data.repository
import com.youtubedl.data.local.room.entity.ProgressInfo
import com.youtubedl.di.qualifier.LocalData
import io.reactivex.Flowable
import io.reactivex.Single
import io.reactivex.schedulers.Schedulers
import javax.inject.Inject
import javax.inject.Singleton

Expand All @@ -31,14 +29,10 @@ class ProgressRepositoryImpl @Inject constructor(
}

override fun saveProgressInfo(progressInfo: ProgressInfo) {
Single.just(progressInfo)
.subscribeOn(Schedulers.io())
.subscribe { it -> localDataSource.saveProgressInfo(it) }
localDataSource.saveProgressInfo(progressInfo)
}

override fun deleteProgressInfo(progressInfo: ProgressInfo) {
Single.just(progressInfo)
.subscribeOn(Schedulers.io())
.subscribe { it -> localDataSource.deleteProgressInfo(it) }
localDataSource.deleteProgressInfo(progressInfo)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
package com.youtubedl.data.local

import com.nhaarman.mockito_kotlin.doReturn
import com.nhaarman.mockito_kotlin.mock
import com.nhaarman.mockito_kotlin.verify
import com.youtubedl.data.local.room.dao.ConfigDao
import com.youtubedl.data.local.room.entity.SupportedPage
import io.reactivex.Maybe
import org.junit.Before
import org.junit.Test

/**
* Created by cuongpm on 2/17/19.
*/
class ConfigLocalDataSourceTest {

private lateinit var configDao: ConfigDao

private lateinit var configLocalDataSource: ConfigLocalDataSource

private lateinit var supportedPages: List<SupportedPage>

@Before
fun setup() {
configDao = mock()
configLocalDataSource = ConfigLocalDataSource(configDao)
supportedPages = listOf(SupportedPage(id = "id1", name = "name1"), SupportedPage(id = "id2", name = "name2"))
}

@Test
fun `test get supported pages`() {
doReturn(Maybe.just(supportedPages)).`when`(configDao).getSupportedPages()

configLocalDataSource.getSupportedPages()
.test()
.assertNoErrors()
.assertValue { it == supportedPages }
}

@Test
fun `test save supported pages`() {
configLocalDataSource.saveSupportedPages(supportedPages)
verify(configDao).insertSupportedPage(supportedPages[0])
verify(configDao).insertSupportedPage(supportedPages[1])
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import com.youtubedl.data.local.room.entity.ProgressInfo
import com.youtubedl.data.local.room.entity.VideoInfo
import io.reactivex.Flowable
import org.junit.Before
import org.junit.Ignore
import org.junit.Test

/**
Expand Down Expand Up @@ -41,14 +40,12 @@ class ProgressLocalDataSourceTest {
}

@Test
@Ignore
fun `test get save downloading video`() {
progressLocalDataSource.saveProgressInfo(progressInfo)
verify(progressDao).insertProgressInfo(progressInfo)
}

@Test
@Ignore
fun `test delete downloading video`() {
progressLocalDataSource.deleteProgressInfo(progressInfo)
verify(progressDao).deleteProgressInfo(progressInfo)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import com.youtubedl.data.local.room.entity.ProgressInfo
import com.youtubedl.data.local.room.entity.VideoInfo
import io.reactivex.Flowable
import org.junit.Before
import org.junit.Ignore
import org.junit.Test

/**
Expand Down Expand Up @@ -41,14 +40,12 @@ class ProgressRepositoryImplTest {
}

@Test
@Ignore
fun `test save downloading video`() {
progressRepository.saveProgressInfo(progressInfo)
verify(progressLocalDataSource).saveProgressInfo(progressInfo)
}

@Test
@Ignore
fun `test delete downloading video`() {
progressRepository.deleteProgressInfo(progressInfo)
verify(progressLocalDataSource).deleteProgressInfo(progressInfo)
Expand Down

0 comments on commit 46d49c4

Please sign in to comment.