aboutsummaryrefslogtreecommitdiff
path: root/src/test/java/at
diff options
context:
space:
mode:
authorLinnea Gräf <nea@nea.moe>2024-10-18 14:19:55 +0200
committerLinnea Gräf <nea@nea.moe>2024-10-18 14:19:55 +0200
commit34a3477488e2e15a5a0e7cd2cd358faf8f926f71 (patch)
tree8a54c6f418448ce91696d03e1aeb4e94ffe8375d /src/test/java/at
parentf4fa81ebd56882bf25261427f3ca6672e2782e0b (diff)
downloadskyhanni-34a3477488e2e15a5a0e7cd2cd358faf8f926f71.tar.gz
skyhanni-34a3477488e2e15a5a0e7cd2cd358faf8f926f71.tar.bz2
skyhanni-34a3477488e2e15a5a0e7cd2cd358faf8f926f71.zip
Support permuting type arguments of GenericSkyhanniEventgeneric-permutable-resolution
Diffstat (limited to 'src/test/java/at')
-rw-r--r--src/test/java/at/hannibal2/skyhanni/test/utils/ReflectUtilsTest.kt39
1 files changed, 39 insertions, 0 deletions
diff --git a/src/test/java/at/hannibal2/skyhanni/test/utils/ReflectUtilsTest.kt b/src/test/java/at/hannibal2/skyhanni/test/utils/ReflectUtilsTest.kt
new file mode 100644
index 000000000..106f3aeb0
--- /dev/null
+++ b/src/test/java/at/hannibal2/skyhanni/test/utils/ReflectUtilsTest.kt
@@ -0,0 +1,39 @@
+package at.hannibal2.skyhanni.test.utils
+
+import at.hannibal2.skyhanni.utils.ReflectionUtils
+import org.junit.jupiter.api.Assertions
+import org.junit.jupiter.api.Test
+import java.lang.reflect.ParameterizedType
+import java.lang.reflect.TypeVariable
+
+class ReflectUtilsTest {
+ class SomeClass
+ open class Parent<A, B>
+ open class Child<A, B> : Parent<B, A>()
+ open class GrandChild<T> : Child<String, T>()
+
+ abstract class Holder<X>
+
+ inline fun <reified T> resolve(typeParam: TypeVariable<*>): Class<*>? {
+ return ReflectionUtils.resolveUpperBoundSuperClassGenericParameter(
+ (object : Holder<T>() {}
+ .javaClass.genericSuperclass as ParameterizedType)
+ .actualTypeArguments[0],
+ typeParam,
+ )
+ }
+
+ @Test
+ fun testResolveUpperBoundSuperClassGenericParameter() {
+ val firstParent = Parent::class.java.typeParameters[0]
+ val secondParent = Parent::class.java.typeParameters[1]
+ Assertions.assertEquals(String::class.java, resolve<Parent<String, Int>>(firstParent))
+ Assertions.assertEquals(Integer::class.java, resolve<Parent<String, Int>>(secondParent))
+ Assertions.assertEquals(Integer::class.java, resolve<Child<String, Int>>(firstParent))
+ Assertions.assertEquals(String::class.java, resolve<Child<String, Int>>(secondParent))
+ Assertions.assertEquals(SomeClass::class.java, resolve<GrandChild<SomeClass>>(firstParent))
+ Assertions.assertEquals(String::class.java, resolve<GrandChild<SomeClass>>(secondParent))
+ Assertions.assertEquals(SomeClass::class.java, resolve<GrandChild<out SomeClass>>(firstParent))
+ Assertions.assertEquals(Any::class.java, resolve<GrandChild<*>>(firstParent))
+ }
+}