Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to mock lambda call #463

Open
cjacky475 opened this issue Sep 27, 2022 · 1 comment
Open

How to mock lambda call #463

cjacky475 opened this issue Sep 27, 2022 · 1 comment

Comments

@cjacky475
Copy link

Hello, I have this function:

override fun loadSensors(userId: String, param: (Result<MutableList<UserSensor>>) -> Unit) {
        // Blank
}
    @get:Rule
    var hiltRule = HiltAndroidRule(this)

    @Rule @JvmField
    var mockitoRule = MockitoJUnit.rule()

    @Inject
    lateinit var repository: MockRepositoryImpl

    @Before
    fun before() {
        hiltRule.inject()

        MockitoAnnotations.openMocks(this)

        `when`(repository.loadSensors(anyString(), any())).thenAnswer {
            Result.Success("", mutableListOf(UserSensor(0), UserSensor(1)))
        }

        ActivityScenario.launch(MainActivity::class.java)
    }

How to mock that thenAnswer would actually call my param argument?

@wesalvaro
Copy link
Contributor

Are you asking about InvocationOnMock?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants