mock(PersonDao::class.java) val client = mock(PersonClient::class.java) val repository = PersonRepository(dao, client) val expected = Array(5, Int::toString) .map { Person(it, it) }.toList() `when`(client.fetch()).thenReturn(Single.just(expected)) repository.getPersons().test().assertValue(expected) verify(dao).insert(expected) } } Test PersonRepository#getPersons “when” is reserved word of Kotlin
mock<PersonDao>() val client = mock<PersonClient>() val repository = PersonRepository(dao, client) val expected = Array(5, Int::toString) .map { Person(it, it) }.toList() client.fetch().invoked.thenReturn(Single.just(expected)) repository.getPersons().test().assertValue(expected) dao.verify().insert(expected) } } How does it work?
mock<PersonDao>() val client = mock<PersonClient>() val repository = PersonRepository(dao, client) val expected = Array(5, Int::toString) .map { Person(it, it) }.toList() client.fetch().invoked.thenReturn(Single.just(expected)) repository.getPersons().test().assertValue(expected) dao.verify().insert(expected) } } How does it work? Inline function, reified type parameter
mock<PersonDao>() val client = mock<PersonClient>() val repository = PersonRepository(dao, client) val expected = Array(5, Int::toString) .map { Person(it, it) }.toList() client.fetch().invoked.thenReturn(Single.just(expected)) repository.getPersons().test().assertValue(expected) dao.verify().insert(expected) } } How does it work? Extension function