From 1ec5a87de7b9e9c0ded599ffc6bd7f2d9a12acbf Mon Sep 17 00:00:00 2001 From: Andrew Anfanik Date: Sun, 8 Dec 2024 05:00:58 +0200 Subject: [PATCH] Fix ResponseTest: disable default constructor & toString checks for Kotlin Data Classes --- library/build.gradle | 1 + .../test/java/com/pengrad/telegrambot/ResponseTest.java | 8 ++++++++ 2 files changed, 9 insertions(+) diff --git a/library/build.gradle b/library/build.gradle index df95e5a2..4f1d20dc 100644 --- a/library/build.gradle +++ b/library/build.gradle @@ -16,6 +16,7 @@ dependencies { testImplementation 'junit:junit:4.13.1' testImplementation 'nl.jqno.equalsverifier:equalsverifier:3.1.13' testImplementation 'org.reflections:reflections:0.9.12' + testImplementation 'org.jetbrains.kotlin:kotlin-reflect' } jar { diff --git a/library/src/test/java/com/pengrad/telegrambot/ResponseTest.java b/library/src/test/java/com/pengrad/telegrambot/ResponseTest.java index 9813a84a..53069de1 100644 --- a/library/src/test/java/com/pengrad/telegrambot/ResponseTest.java +++ b/library/src/test/java/com/pengrad/telegrambot/ResponseTest.java @@ -1,6 +1,8 @@ package com.pengrad.telegrambot; import com.pengrad.telegrambot.response.BaseResponse; +import kotlin.jvm.JvmClassMappingKt; +import kotlin.reflect.KClass; import org.junit.Before; import org.junit.Test; import org.reflections.Reflections; @@ -33,6 +35,12 @@ public void setClasses() { @Test public void testToString() throws IllegalAccessException, InstantiationException, InvocationTargetException { for (Class c : classes) { + KClass kclass = JvmClassMappingKt.getKotlinClass(c); + + if (kclass.isData()) { + continue; + } + Optional> constructor = Arrays.stream(c.getDeclaredConstructors()).filter(dc -> dc.getParameterCount() == 0).findFirst(); assertTrue("No default constructor in " + c.getSimpleName(), constructor.isPresent()); constructor.get().setAccessible(true);