44import com .pengrad .telegrambot .model .CallbackQuery ;
55import com .pengrad .telegrambot .model .Message ;
66import com .pengrad .telegrambot .model .Update ;
7+ import com .pengrad .telegrambot .model .request .InlineKeyboardButton ;
8+ import com .pengrad .telegrambot .model .request .InlineKeyboardMarkup ;
79import com .pengrad .telegrambot .passport .Credentials ;
810import nl .jqno .equalsverifier .EqualsVerifier ;
911import nl .jqno .equalsverifier .Warning ;
1517import java .lang .reflect .Field ;
1618import java .lang .reflect .Modifier ;
1719import java .util .Arrays ;
20+ import java .util .HashMap ;
1821import java .util .List ;
1922import java .util .Set ;
23+ import java .util .function .Supplier ;
2024import java .util .stream .Collectors ;
2125
2226import static org .junit .Assert .assertTrue ;
2832public 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