From 097afbdfb710b9877aa15c9c694f6d87f19b6378 Mon Sep 17 00:00:00 2001 From: Stas Parshin Date: Wed, 5 Jun 2019 01:03:40 +0700 Subject: [PATCH] Add model/request classes in ModelTest --- .../java/com/pengrad/telegrambot/ModelTest.java | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/library/src/test/java/com/pengrad/telegrambot/ModelTest.java b/library/src/test/java/com/pengrad/telegrambot/ModelTest.java index 2f432f23..a1895fb2 100644 --- a/library/src/test/java/com/pengrad/telegrambot/ModelTest.java +++ b/library/src/test/java/com/pengrad/telegrambot/ModelTest.java @@ -4,6 +4,8 @@ import com.pengrad.telegrambot.model.CallbackQuery; import com.pengrad.telegrambot.model.Message; import com.pengrad.telegrambot.model.Update; +import com.pengrad.telegrambot.model.request.InlineKeyboardButton; +import com.pengrad.telegrambot.model.request.InlineKeyboardMarkup; import com.pengrad.telegrambot.passport.Credentials; import nl.jqno.equalsverifier.EqualsVerifier; import nl.jqno.equalsverifier.Warning; @@ -15,8 +17,10 @@ import java.lang.reflect.Field; import java.lang.reflect.Modifier; import java.util.Arrays; +import java.util.HashMap; import java.util.List; import java.util.Set; +import java.util.function.Supplier; import java.util.stream.Collectors; import static org.junit.Assert.assertTrue; @@ -28,6 +32,7 @@ public class ModelTest { private Set classes; + private HashMap> customInstance = new HashMap<>(); @Before public void setClasses() { @@ -42,6 +47,12 @@ public void setClasses() { && !clazz.getSimpleName().startsWith("PassportElementError") && !Modifier.isAbstract(clazz.getModifiers()) ).collect(Collectors.toSet()); + + // classes from model/request available in responses + classes.add(InlineKeyboardMarkup.class); + classes.add(InlineKeyboardButton.class); + customInstance.put(InlineKeyboardMarkup.class, InlineKeyboardMarkup::new); + customInstance.put(InlineKeyboardButton.class, () -> new InlineKeyboardButton("")); } @Test @@ -76,7 +87,8 @@ public void testEquals() throws IllegalAccessException, InstantiationException, @Test public void testToString() throws IllegalAccessException, InstantiationException { for (Class c : classes) { - String toString = c.newInstance().toString(); + Object instance = customInstance.containsKey(c) ? customInstance.get(c).get() : c.newInstance(); + String toString = instance.toString(); for (Field f : c.getDeclaredFields()) { if (Modifier.isStatic(f.getModifiers())) { continue;