1

I'm new to Kotlin and i'm trying to refactor some code in Kotlin.

I have this piece of code that im calling in multiple places which i'd like to call a single function instead

Mockito.`when`(mockedSkillMaxCountRepository.getSkillMaxCount()).thenReturn(
     SkillMaxCount(count = 65),
     SkillMaxCount(count = 65)
)

And I want to do something like this where the number of parameters can be any number

mockSkillMaxCount(SkillMaxCount(count = 65), SkillMaxCount(count = 65),...)

private fun mockSkillMaxCount(SkillMaxCount(count = 65),SkillMaxCount(count = 65),...){       
     Mockito.`when`(mockedSkillMaxCountRepository.getSkillMaxCount()).thenReturn(params)
}

1 Answer 1

1

You can use vararg modifier:

private fun mockSkillMaxCount(vararg skills: SkillMaxCount) {
    Mockito.`when`(mockedSkillMaxCountRepository.getSkillMaxCount()).thenReturn(*skills)
}
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.