Skip to content

Commit

Permalink
Merge pull request #130 from kikuchy/add-contributers-test
Browse files Browse the repository at this point in the history
Add ContributorsRepository Tests
  • Loading branch information
konifar committed Feb 7, 2017
2 parents ae574a1 + 888edf8 commit 917eff6
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 2 deletions.
Expand Up @@ -12,7 +12,7 @@
import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.schedulers.Schedulers;

final class ContributorsLocalDataSource {
public class ContributorsLocalDataSource {

private final OrmaDatabase orma;

Expand All @@ -21,7 +21,7 @@ final class ContributorsLocalDataSource {
this.orma = orma;
}

Single<List<Contributor>> findAll() {
public Single<List<Contributor>> findAll() {
return orma.selectFromContributor()
.executeAsObservable()
.toList()
Expand Down
@@ -0,0 +1,51 @@
package io.github.droidkaigi.confsched2017.repository.contributors

import com.sys1yagi.kmockito.invoked
import com.sys1yagi.kmockito.mock
import com.sys1yagi.kmockito.verify
import io.github.droidkaigi.confsched2017.model.Contributor
import io.reactivex.Single
import org.junit.Test
import org.mockito.Mockito

class ContributorsRepositoryTest {

private val localDataSource = mock<ContributorsLocalDataSource>()
private val remoteDataSource = mock<ContributorsRemoteDataSource>()

private val repository = ContributorsRepository(localDataSource, remoteDataSource)

@Test
@Throws(Exception::class)
fun findAllFromEmptyRepository() {
localDataSource.findAll().invoked.thenReturn(Single.just(listOf()))
remoteDataSource.findAll().invoked.thenReturn(Single.just(listOf()))
repository.findAll().test().assertOf { check ->
check.assertNoErrors()
check.assertValue(listOf())
}
}

@Test
@Throws(Exception::class)
fun updateLocalWhenRemoteReturns() {
val contributors = listOf(
Contributor().apply {
name = "Alice"
},
Contributor().apply {
name = "Bob"
},
Contributor().apply {
name = "Charlie"
}
)
localDataSource.findAll().invoked.thenReturn(Single.just(listOf()))
remoteDataSource.findAll().invoked.thenReturn(Single.just(contributors))
repository.findAll().test().assertOf { check ->
check.assertNoErrors()
localDataSource.verify(Mockito.times(1)).updateAllAsync(contributors)
}
}

}

0 comments on commit 917eff6

Please sign in to comment.