Skip to content

Commit bc1c052

Browse files
committed
Fix ModelTest
1 parent b7bcb08 commit bc1c052

File tree

2 files changed

+14
-5
lines changed

2 files changed

+14
-5
lines changed

library/src/main/java/com/pengrad/telegrambot/model/BotCommand.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ public BotCommand(String command, String description) {
1414
this.description = description;
1515
}
1616

17-
private BotCommand() {}
17+
BotCommand() {}
1818

1919
private String command;
2020
private String description;

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

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,13 @@
77
import com.pengrad.telegrambot.model.request.InlineKeyboardButton;
88
import com.pengrad.telegrambot.model.request.InlineKeyboardMarkup;
99
import com.pengrad.telegrambot.passport.Credentials;
10-
import nl.jqno.equalsverifier.EqualsVerifier;
11-
import nl.jqno.equalsverifier.Warning;
10+
1211
import org.junit.Before;
1312
import org.junit.Test;
1413
import org.reflections.Reflections;
1514
import org.reflections.scanners.SubTypesScanner;
1615

16+
import java.lang.reflect.Constructor;
1717
import java.lang.reflect.Field;
1818
import java.lang.reflect.Modifier;
1919
import java.util.Arrays;
@@ -23,6 +23,9 @@
2323
import java.util.function.Supplier;
2424
import java.util.stream.Collectors;
2525

26+
import nl.jqno.equalsverifier.EqualsVerifier;
27+
import nl.jqno.equalsverifier.Warning;
28+
2629
import static org.junit.Assert.assertTrue;
2730

2831
/**
@@ -85,9 +88,9 @@ public void testEquals() throws IllegalAccessException, InstantiationException,
8588
}
8689

8790
@Test
88-
public void testToString() throws IllegalAccessException, InstantiationException {
91+
public void testToString() throws Exception {
8992
for (Class c : classes) {
90-
Object instance = customInstance.containsKey(c) ? customInstance.get(c).get() : c.newInstance();
93+
Object instance = customInstance.containsKey(c) ? customInstance.get(c).get() : defaultInstance(c);
9194
String toString = instance.toString();
9295
for (Field f : c.getDeclaredFields()) {
9396
if (Modifier.isStatic(f.getModifiers())) {
@@ -97,4 +100,10 @@ public void testToString() throws IllegalAccessException, InstantiationException
97100
}
98101
}
99102
}
103+
104+
private Object defaultInstance(Class c) throws Exception {
105+
Constructor constructor = c.getDeclaredConstructor();
106+
constructor.setAccessible(true);
107+
return constructor.newInstance();
108+
}
100109
}

0 commit comments

Comments
 (0)