Skip to content

Commit 272f360

Browse files
committed
Find default constructor in ResponseTest
1 parent 02b2495 commit 272f360

File tree

2 files changed

+7
-6
lines changed

2 files changed

+7
-6
lines changed

library/src/main/java/com/pengrad/telegrambot/response/UserChatBoostsResponse.kt

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,7 @@ package com.pengrad.telegrambot.response
22

33
import com.pengrad.telegrambot.model.chatboost.ChatBoost
44

5-
data class UserChatBoostsResponse @JvmOverloads constructor(
6-
private val result: ChatBoosts = ChatBoosts(emptyList())
7-
) : BaseResponse() {
5+
data class UserChatBoostsResponse(private val result: ChatBoosts = ChatBoosts(emptyList())) : BaseResponse() {
86
data class ChatBoosts(val boosts: List<ChatBoost>)
97

108
fun boosts(): Array<ChatBoost> {

library/src/test/java/com/pengrad/telegrambot/ResponseTest.java

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
import java.lang.reflect.Field;
1010
import java.lang.reflect.InvocationTargetException;
1111
import java.lang.reflect.Modifier;
12+
import java.util.Arrays;
13+
import java.util.Optional;
1214
import java.util.Set;
1315

1416
import static org.junit.Assert.assertTrue;
@@ -31,9 +33,10 @@ public void setClasses() {
3133
@Test
3234
public void testToString() throws IllegalAccessException, InstantiationException, InvocationTargetException {
3335
for (Class<? extends BaseResponse> c : classes) {
34-
Constructor<?> constructor = c.getDeclaredConstructors()[0];
35-
constructor.setAccessible(true);
36-
String toString = constructor.newInstance().toString();
36+
Optional<Constructor<?>> constructor = Arrays.stream(c.getDeclaredConstructors()).filter(dc -> dc.getParameterCount() == 0).findFirst();
37+
assertTrue("No default constructor in " + c.getSimpleName(), constructor.isPresent());
38+
constructor.get().setAccessible(true);
39+
String toString = constructor.get().newInstance().toString();
3740
for (Field f : c.getDeclaredFields()) {
3841
if (Modifier.isStatic(f.getModifiers())) {
3942
continue;

0 commit comments

Comments
 (0)