Skip to content

Instantly share code, notes, and snippets.

@SabagRonen
Created October 1, 2018 06:58
Show Gist options
  • Save SabagRonen/718bc4c2fdecb900f1818ba6788cb9fe to your computer and use it in GitHub Desktop.
Save SabagRonen/718bc4c2fdecb900f1818ba6788cb9fe to your computer and use it in GitHub Desktop.
Why Should You Wrap LiveData With Your Own Abstraction - testing
@RunWith(AndroidJUnit4::class)
class ScreenViewTests {
@get:Rule val testRule = createTestRuleWithFakeScreenViewInjector {
presenter = mockPresenter
}
private val mockPresenter = mock(IScreenPresenter::class.java)
@Test
fun someTest() {
val captor = lambdaArgumentCaptor<(String) -> Unit>()
verify(mockPresenter.observeTitle(anyNonNull(), captor.capture()))
val titleObserver = captor.value
titleObserver("tests are fun")
onView(withId(R.id.title)).check(matches(withText("tests are fun")))
}
}
fun <T> anyNonNull(): T = Mockito.any<T>() as T
inline fun <reified T> lambdaArgumentCaptor() : ArgumentCaptor<T> = ArgumentCaptor.forClass(T::class.java)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment