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
// given | |
// api returns contacs list | |
// when | |
// fetch contacts is initiated | |
// then | |
// assert progress was shown | |
// assert set contacts list was called | |
// assert progress was hidden |
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
view.hideProgress() | |
when(it){ | |
is NoConnectionException -> view.showNoConnectionError() | |
is ApiException -> view.showError(it.msg) | |
} |
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>) |
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
//given | |
// api returns error | |
//when | |
// fetching contacts list | |
//then | |
// show error message | |
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>) |
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>) |
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
whenever(repository.fetchContacts()).thenReturn(emptyList()) //simulate interface response | |
verify(view).setData(any()) //verify `setData` method was called | |
verify(view, never()).setData(any()) //verify `setData` was never called | |
verify(view, times(2)).setData(any()) //verify `setData` was called exactly two times | |
... | |
//verify that `showProgress` and `getCurrentUser` were called in that exact order | |
val inOrder = inOrder(view,repository) | |
inOrder.verify(view).showProgress() | |
inOrder.verify(repository).getCurrentUser() |
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
@Test | |
fun `fetch contacts, api error`(){ | |
//given | |
val errorMessage = "Bad request" | |
whenver(api.fetchContacts()).thenReturn{Single.error(IllegalArgumentException(errorMessage)} | |
//when | |
presenter.fetchContacts() | |
//then | |
val inOrder = inOrder(view, api) | |
inOrder.verify(view).showProgress() |
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>) |
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
interface MyLocationProvider{ | |
fun obtainCurrentLocation():LatLng | |
} | |
class SomePresenter(val locationProvider: MyLoacationProvider){ | |
... | |
} |
NewerOlder