Skip to content

Commit

Permalink
Fixed the tests to make them work with java 17
Browse files Browse the repository at this point in the history
  • Loading branch information
B3nedikt committed Sep 26, 2023
1 parent 66168f6 commit a75d120
Showing 1 changed file with 6 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@ import org.junit.runner.RunWith
import org.mockito.kotlin.doReturn
import org.mockito.kotlin.mock
import org.robolectric.RobolectricTestRunner
import java.lang.reflect.Field
import java.lang.reflect.Modifier
import java.util.*

@RunWith(RobolectricTestRunner::class)
Expand Down Expand Up @@ -47,23 +45,18 @@ class AppLocaleInitialStateTest {
@Before
fun resetAppLocale() {
setAppLocaleField("isInitial", true)

setAppLocaleField("appLocaleRepository", null)

setAppLocaleField("supportedLocales", listOf<Locale>())
setAppLocaleField("currentLocale", Locale.ROOT)
setAppLocaleField("desiredLocale", Locale.ROOT)
}

private fun setAppLocaleField(name: String, newValue: Any?) {
AppLocale.javaClass.getDeclaredField(name).setFinalStatic(newValue)
}

private fun Field.setFinalStatic(newValue: Any?) {
isAccessible = true
val modifiersField: Field = Field::class.java.getDeclaredField("modifiers")
modifiersField.isAccessible = true
modifiersField.setInt(this, modifiers and Modifier.FINAL.inv())
set(null, newValue)
AppLocale::class.java.getDeclaredField(name).apply {
isAccessible = true
set(AppLocale, newValue)
}
}
}

0 comments on commit a75d120

Please sign in to comment.