Skip to content

Commit 097afbd

Browse files
committed
Add model/request classes in ModelTest
1 parent 49056d5 commit 097afbd

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

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

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
import com.pengrad.telegrambot.model.CallbackQuery;
55
import com.pengrad.telegrambot.model.Message;
66
import com.pengrad.telegrambot.model.Update;
7+
import com.pengrad.telegrambot.model.request.InlineKeyboardButton;
8+
import com.pengrad.telegrambot.model.request.InlineKeyboardMarkup;
79
import com.pengrad.telegrambot.passport.Credentials;
810
import nl.jqno.equalsverifier.EqualsVerifier;
911
import nl.jqno.equalsverifier.Warning;
@@ -15,8 +17,10 @@
1517
import java.lang.reflect.Field;
1618
import java.lang.reflect.Modifier;
1719
import java.util.Arrays;
20+
import java.util.HashMap;
1821
import java.util.List;
1922
import java.util.Set;
23+
import java.util.function.Supplier;
2024
import java.util.stream.Collectors;
2125

2226
import static org.junit.Assert.assertTrue;
@@ -28,6 +32,7 @@
2832
public class ModelTest {
2933

3034
private Set<Class> classes;
35+
private HashMap<Class, Supplier<Object>> customInstance = new HashMap<>();
3136

3237
@Before
3338
public void setClasses() {
@@ -42,6 +47,12 @@ public void setClasses() {
4247
&& !clazz.getSimpleName().startsWith("PassportElementError")
4348
&& !Modifier.isAbstract(clazz.getModifiers())
4449
).collect(Collectors.toSet());
50+
51+
// classes from model/request available in responses
52+
classes.add(InlineKeyboardMarkup.class);
53+
classes.add(InlineKeyboardButton.class);
54+
customInstance.put(InlineKeyboardMarkup.class, InlineKeyboardMarkup::new);
55+
customInstance.put(InlineKeyboardButton.class, () -> new InlineKeyboardButton(""));
4556
}
4657

4758
@Test
@@ -76,7 +87,8 @@ public void testEquals() throws IllegalAccessException, InstantiationException,
7687
@Test
7788
public void testToString() throws IllegalAccessException, InstantiationException {
7889
for (Class c : classes) {
79-
String toString = c.newInstance().toString();
90+
Object instance = customInstance.containsKey(c) ? customInstance.get(c).get() : c.newInstance();
91+
String toString = instance.toString();
8092
for (Field f : c.getDeclaredFields()) {
8193
if (Modifier.isStatic(f.getModifiers())) {
8294
continue;

0 commit comments

Comments
 (0)