Skip to content

Instantly share code, notes, and snippets.

@gilgoldzweig
Last active February 12, 2019 17:28
Show Gist options
  • Save gilgoldzweig/47d62f867d06029f33870ca143975bd2 to your computer and use it in GitHub Desktop.
Save gilgoldzweig/47d62f867d06029f33870ca143975bd2 to your computer and use it in GitHub Desktop.
@RunWith(MockitoJUnitRunner::class)
class ExamplePresenterTest {
@Mock
private lateinit var view: ExampleContract.View
@Spy
private var presenter: ExamplePresenter = ExamplePresenter()
@Before
fun setUp() {
presenter.attach(view)
}
@Test
fun `test_fetchProfileName_calles_onProfileNameReceived_on_positive_response`() {
Mockito.`when`(presenter.fetchProfileNameFromRepository()))
.thenReturn("Gil Goldzweig")
presenter.fetchProfileName()
Mockito.verify(view, times(1))
.onProfileNameReceived("Gil Goldzweig")
}
@Test
fun `test_fetchProfileName_calles_onProfileRequestFailed_on_exception`() {
val fakeException = Mockito.mock(IOException::class.java)
Mockito.`when`(presenter.fetchProfileNameFromRepository()))
.thenThrow(fakeException)
presenter.fetchProfileName()
Mockito.verify(view, times(1))
.onProfileNameRequestFailed(fakeException)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment