Skip to content

Commit

Permalink
Add model/request classes in ModelTest
Browse files Browse the repository at this point in the history
  • Loading branch information
pengrad committed Jun 4, 2019
1 parent 49056d5 commit 097afbd
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion library/src/test/java/com/pengrad/telegrambot/ModelTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -28,6 +32,7 @@
public class ModelTest {

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

@Before
public void setClasses() {
Expand All @@ -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
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit 097afbd

Please sign in to comment.