Skip to content

Commit

Permalink
fix: Configure JVM arguments for test cases to address compatibility (#…
Browse files Browse the repository at this point in the history
…92)

* fix: Configure JVM arguments for test cases to address compatibility issues with JDK 17

* added returnDefaultValues flag for mockito
  • Loading branch information
Mansi-mParticle authored May 16, 2024
1 parent dc5ef91 commit 739f753
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 4 deletions.
4 changes: 4 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,10 @@ android {

testOptions {
unitTests.returnDefaultValues = true
unitTests.all {
jvmArgs += ['--add-opens', 'java.base/java.lang=ALL-UNNAMED']
jvmArgs += ['--add-opens', 'java.base/java.lang.reflect=ALL-UNNAMED']
}
}
}

Expand Down
23 changes: 19 additions & 4 deletions src/test/kotlin/com/mparticle/kits/ButtonKitTests.kt
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ import org.junit.Assert
import org.junit.Before
import org.junit.Test
import org.mockito.Mockito
import org.mockito.Mockito.`when`
import org.mockito.Mockito.mock
import org.mockito.Mockito.`when`
import java.lang.ref.WeakReference
import java.lang.reflect.Field
import java.lang.reflect.Modifier
Expand Down Expand Up @@ -348,10 +348,25 @@ class ButtonKitTests {
@Throws(Exception::class)
private fun setFinalStatic(field: Field, newValue: Int) {
field.isAccessible = true
val modifiersField = Field::class.java.getDeclaredField("modifiers")
modifiersField.isAccessible = true
modifiersField.setInt(field, field.modifiers and Modifier.FINAL.inv())
val getDeclaredFields0 =
Class::class.java.getDeclaredMethod(
"getDeclaredFields0",
Boolean::class.javaPrimitiveType
)
getDeclaredFields0.isAccessible = true
val fields = getDeclaredFields0.invoke(Field::class.java, false) as Array<Field>
var modifiersField: Field? = null
for (each in fields) {
if ("modifiers" == each.name) {
modifiersField = each
break
}
}
modifiersField!!.isAccessible = true
modifiersField!!.setInt(field, field.modifiers and Modifier.FINAL.inv())
field[null] = newValue

}

}
}

0 comments on commit 739f753

Please sign in to comment.