Last active
December 27, 2018 21:56
-
-
Save michalbujalski/d3cd256d651719abd0b366efd97d053d to your computer and use it in GitHub Desktop.
This file contains 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
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(){ | |
} | |
} |
This file contains 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
@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