Skip to content

Commit dad718f

Browse files
committed
fix @Config with RobolectricExtension
In a previous commit I assumed all 4 copies of RobolectricExtension.kt were the same, however there was a difference in their getConfig implementation. This fixes a number of failing tests, such as the location tests.
1 parent ab7dcab commit dad718f

File tree

1 file changed

+14
-3
lines changed

1 file changed

+14
-3
lines changed

OneSignalSDK/onesignal/testhelpers/src/main/java/com/onesignal/testhelpers/extensions/RobolectricExtension.kt

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,15 +33,26 @@ class RobolectricExtension : ConstructorExtension, TestCaseExtension {
3333
}
3434

3535
private fun KClass<*>.getConfig(): Config {
36-
val annotations =
36+
val configAnnotations =
37+
listOf(this.java).plus(this.java.getParentClass())
38+
.mapNotNull { it.kotlin.findAnnotation<Config>() }
39+
.asSequence()
40+
41+
val configAnnotation = configAnnotations.firstOrNull()
42+
43+
if (configAnnotation != null) {
44+
return Config.Builder(configAnnotation).build()
45+
}
46+
47+
val robolectricTestAnnotations =
3748
listOf(this.java).plus(this.java.getParentClass())
3849
.mapNotNull { it.kotlin.findAnnotation<RobolectricTest>() }
3950
.asSequence()
4051

4152
val application: KClass<out Application>? =
42-
annotations
53+
robolectricTestAnnotations
4354
.firstOrNull { it.application != KotestDefaultApplication::class }?.application
44-
val sdk: Int? = annotations.firstOrNull { it.sdk != -1 }?.takeUnless { it.sdk == -1 }?.sdk
55+
val sdk: Int? = robolectricTestAnnotations.firstOrNull { it.sdk != -1 }?.takeUnless { it.sdk == -1 }?.sdk
4556

4657
return Config.Builder()
4758
.also { builder ->

0 commit comments

Comments
 (0)