Skip to content

Instantly share code, notes, and snippets.

@michalbujalski
Last active December 27, 2018 21:56
Show Gist options
  • Save michalbujalski/d3cd256d651719abd0b366efd97d053d to your computer and use it in GitHub Desktop.
Save michalbujalski/d3cd256d651719abd0b366efd97d053d to your computer and use it in GitHub Desktop.
data class Contact(val name:String, val phoneNum:String)
interface ContactsListsApi{
fetchContacts(): Single<List<Contact>>
}
interface ContactsListsContract{
interface View{
fun showProgress()
fun hideProgress()
fun setData(contacts: List<Contact>)
fun showError(errorMessage:String)
}
interface Presenter{
fun fetchContacts()
}
}
class ContactsListPresenter(val view: ContactsListsContract.View, val api:ContactsListsApi): ContactsListsContract.Presenter {
override fun fetchContacts(){
}
}
@Mock lateinit var view: ContactsListsContract.View
@Mock lateinit var api: ContactsListsApi
lateinit var presenter: ContactsListPresenter
@Before
fun setUp(){
MockitoAnnotations.init(this)
presenter = ContactsListPresenter(view, api)
}
@Test
fun `fetch contacts, success`(){
//given
whenver(api.fetchContacts()).thenReturn{Single.just(emptyList())}
//when
presenter.fetchContacts()
//then
val inOrder = inOrder(view, api)
inOrder.verify(view).showProgress()
inOrder.verify(api).fetchContacts()
inOrder.verify(view).hideProgress()
inOrder.verify(view).setData(anyList)
inOrder.verifyNoMoreInteractions()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment