0

i want to stub kotlin's map extension function in my unit test. couldn't find any proper solution on internet to do that.

ctually i have put empty blocks inside curly brackets but it seems like this is not the way that i should do.

here is what i have been trying so far:

whenever(trainWorkoutResult.exerciseSections.map {}).thenReturn(trainSections)

here is the error that i got:

no answer found for: 

    LegacyDataMapper(#4).mappingSectionsToRecordedExerciseDataModels(Mock for List, hashCode: 1199894489)

any idea?

3
  • 1
    Relevant: stackoverflow.com/questions/44382540/… Commented Mar 27, 2023 at 14:38
  • 1
    You cannot and should not. You can stub the function you pass to map, but not map itself, and a good thing too. Commented Mar 27, 2023 at 17:28
  • ty all <3 solved the problem. Commented Mar 28, 2023 at 8:53

1 Answer 1

0

solved it like that:

 with(mockk<List<Section>>()) {
                every {
                    trainWorkoutResult.exerciseSections
                } returns (listOf(Section(12, "123", emptyList())))
            }

inspired by this question.

ps: i am using mockk library

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.