Created
October 1, 2018 06:58
-
-
Save SabagRonen/718bc4c2fdecb900f1818ba6788cb9fe to your computer and use it in GitHub Desktop.
Why Should You Wrap LiveData With Your Own Abstraction - testing
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
@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