Skip to content

Commit

Permalink
Fix ResponseTest: disable default constructor & toString checks for K…
Browse files Browse the repository at this point in the history
…otlin Data Classes
  • Loading branch information
anfanik committed Dec 8, 2024
1 parent d1d11eb commit 1ec5a87
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
1 change: 1 addition & 0 deletions library/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -33,6 +35,12 @@ public void setClasses() {
@Test
public void testToString() throws IllegalAccessException, InstantiationException, InvocationTargetException {
for (Class<? extends BaseResponse> c : classes) {
KClass<? extends BaseResponse> kclass = JvmClassMappingKt.getKotlinClass(c);

if (kclass.isData()) {
continue;
}

Optional<Constructor<?>> constructor = Arrays.stream(c.getDeclaredConstructors()).filter(dc -> dc.getParameterCount() == 0).findFirst();
assertTrue("No default constructor in " + c.getSimpleName(), constructor.isPresent());
constructor.get().setAccessible(true);
Expand Down

0 comments on commit 1ec5a87

Please sign in to comment.