Skip to content

Commit 75ffef6

Browse files
committed
Increase test coverage
1 parent 01729f2 commit 75ffef6

File tree

10 files changed

+370
-99
lines changed

10 files changed

+370
-99
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ public int hashCode() {
4343
public String toString() {
4444
return "UserProfilePhotos{" +
4545
"total_count=" + total_count +
46-
", photos=" + Arrays.toString(photos) +
46+
", photos=" + Arrays.deepToString(photos) +
4747
'}';
4848
}
4949
}

library/src/main/java/com/pengrad/telegrambot/request/SetGameScore.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ public SetGameScore(int userId, int score, Object chatId, int messageId) {
1515
}
1616

1717
public SetGameScore(int userId, int score, String inlineMessageId) {
18-
super(SendResponse.class);
18+
super(BaseResponse.class);
1919
add("user_id", userId).add("score", score).add("inline_message_id", inlineMessageId);
2020
}
2121

library/src/main/java/com/pengrad/telegrambot/response/GetWebhookInfoResponse.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ public WebhookInfo webhookInfo() {
1717
@Override
1818
public String toString() {
1919
return "GetWebhookInfoResponse{" +
20-
"webhookInfo=" + result +
20+
"result=" + result +
2121
'}';
2222
}
2323
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
package com.pengrad.telegrambot;
2+
3+
import com.pengrad.telegrambot.model.Animation;
4+
5+
import static org.junit.Assert.assertNotNull;
6+
import static org.junit.Assert.assertTrue;
7+
8+
/**
9+
* Stas Parshin
10+
* 04 June 2017
11+
*/
12+
public class AnimationTest {
13+
14+
public static void check(Animation animation) {
15+
assertNotNull(animation.fileId());
16+
assertNotNull(animation.fileName());
17+
assertNotNull(animation.mimeType());
18+
assertTrue(animation.fileSize() > 0);
19+
PhotoSizeTest.checkPhotos(animation.thumb());
20+
}
21+
22+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
package com.pengrad.telegrambot;
2+
3+
import com.pengrad.telegrambot.model.GameHighScore;
4+
5+
import static org.junit.Assert.assertEquals;
6+
import static org.junit.Assert.assertNotNull;
7+
8+
/**
9+
* Stas Parshin
10+
* 05 June 2017
11+
*/
12+
public class GameHighScoreTest {
13+
14+
public static void check(GameHighScore... scores) {
15+
for (int i = 0; i < scores.length; i++) {
16+
GameHighScore score = scores[i];
17+
Integer expectedPos = i + 1;
18+
assertEquals(expectedPos, score.position());
19+
assertNotNull(score.score());
20+
UserTest.checkUser(score.user());
21+
}
22+
}
23+
}

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

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
import com.pengrad.telegrambot.model.Game;
44

55
import static org.junit.Assert.assertNotNull;
6-
import static org.junit.Assert.assertNull;
76

87
/**
98
* Stas Parshin
@@ -14,10 +13,10 @@ public class GameTest {
1413
public static void check(Game game) {
1514
assertNotNull(game.title());
1615
assertNotNull(game.description());
17-
assertNull(game.text());
18-
assertNull(game.textEntities());
19-
assertNull(game.animation());
16+
assertNotNull(game.text());
17+
assertNotNull(game.textEntities());
2018
PhotoSizeTest.checkPhotos(game.photo());
19+
AnimationTest.check(game.animation());
2120
}
2221

2322
}
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
package com.pengrad.telegrambot;
2+
3+
import com.pengrad.telegrambot.response.*;
4+
import org.junit.Before;
5+
import org.junit.Test;
6+
7+
import java.lang.reflect.Constructor;
8+
import java.lang.reflect.Field;
9+
import java.lang.reflect.InvocationTargetException;
10+
import java.lang.reflect.Modifier;
11+
12+
import static org.junit.Assert.assertTrue;
13+
14+
/**
15+
* Stas Parshin
16+
* 31 May 2017
17+
*/
18+
public class ResponseTest {
19+
20+
private Class[] classes;
21+
22+
@Before
23+
public void setClasses() {
24+
classes = new Class[]{
25+
BaseResponse.class,
26+
GetChatAdministratorsResponse.class,
27+
GetChatMemberResponse.class,
28+
GetChatMembersCountResponse.class,
29+
GetChatResponse.class,
30+
GetFileResponse.class,
31+
GetGameHighScoresResponse.class,
32+
GetMeResponse.class,
33+
GetUpdatesResponse.class,
34+
GetUserProfilePhotosResponse.class,
35+
GetWebhookInfoResponse.class,
36+
SendResponse.class
37+
};
38+
}
39+
40+
@Test
41+
public void testToString() throws IllegalAccessException, InstantiationException, InvocationTargetException {
42+
for (Class c : classes) {
43+
Constructor constructor = c.getDeclaredConstructors()[0];
44+
constructor.setAccessible(true);
45+
String toString = constructor.newInstance().toString();
46+
for (Field f : c.getDeclaredFields()) {
47+
if (Modifier.isStatic(f.getModifiers())) {
48+
continue;
49+
}
50+
assertTrue(c.getSimpleName() + " toString doesn't contain " + f.getName(), toString.contains(f.getName()));
51+
}
52+
}
53+
}
54+
}

0 commit comments

Comments
 (0)