Last active
July 13, 2025 04:26
-
-
Save voghDev/8d874f71d2481a66d3c9155df2e21250 to your computer and use it in GitHub Desktop.
Quick workaround to mock a context.getResources().getStringArray(...), in Kotlin
This file contains hidden or 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
@Mock | |
lateinit var mockContext: Context | |
@Mock | |
lateinit var mockResources: Resources | |
@Before | |
fun setUp() { | |
MockitoAnnotations.initMocks(this) | |
} | |
protected fun givenThatAllStringsAreMocked() { | |
whenever(mockContext.getString(anyInt())).thenReturn("-") | |
whenever(mockContext.resources).thenReturn(mockResources) | |
whenever(mockResources.getStringArray(anyInt())).thenReturn(arrayOf( | |
"-", "-", "-", "-", "-", "-", "-", "-" | |
)) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Cleaner way to avoid mocking
Context
, orResources