Skip to content

Commit 642c7ca

Browse files
committed
Update tests
1 parent 2c3ddcc commit 642c7ca

File tree

2 files changed

+40
-13
lines changed

2 files changed

+40
-13
lines changed

src/main/java/com/pengrad/telegrambot/model/CallbackQuery.java

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ public class CallbackQuery {
1111
private Message message;
1212
private String inline_message_id;
1313
private String data;
14+
private String game_short_name;
1415

1516
public String id() {
1617
return id;
@@ -32,20 +33,24 @@ public String data() {
3233
return data;
3334
}
3435

36+
public String gameShortName() {
37+
return game_short_name;
38+
}
39+
3540
@Override
3641
public boolean equals(Object o) {
3742
if (this == o) return true;
3843
if (o == null || getClass() != o.getClass()) return false;
3944

4045
CallbackQuery that = (CallbackQuery) o;
4146

42-
if (id != null ? !id.equals(that.id) : that.id != null) return false;
43-
if (from != null ? !from.equals(that.from) : that.from != null) return false;
47+
if (!id.equals(that.id)) return false;
48+
if (!from.equals(that.from)) return false;
4449
if (message != null ? !message.equals(that.message) : that.message != null) return false;
4550
if (inline_message_id != null ? !inline_message_id.equals(that.inline_message_id) : that.inline_message_id != null)
4651
return false;
47-
return data != null ? data.equals(that.data) : that.data == null;
48-
52+
if (data != null ? !data.equals(that.data) : that.data != null) return false;
53+
return game_short_name != null ? game_short_name.equals(that.game_short_name) : that.game_short_name == null;
4954
}
5055

5156
@Override
@@ -61,6 +66,7 @@ public String toString() {
6166
", message=" + message +
6267
", inline_message_id='" + inline_message_id + '\'' +
6368
", data='" + data + '\'' +
69+
", game_short_name='" + game_short_name + '\'' +
6470
'}';
6571
}
6672
}

src/test/java/com/pengrad/telegrambot/TelegramBotTest.java

Lines changed: 30 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
11
package com.pengrad.telegrambot;
22

3-
import com.pengrad.telegrambot.model.ChatMember;
4-
import com.pengrad.telegrambot.model.InlineQuery;
5-
import com.pengrad.telegrambot.model.Message;
6-
import com.pengrad.telegrambot.model.Update;
3+
import com.pengrad.telegrambot.model.*;
74
import com.pengrad.telegrambot.model.request.InlineKeyboardButton;
85
import com.pengrad.telegrambot.model.request.InlineKeyboardMarkup;
96
import com.pengrad.telegrambot.model.request.InlineQueryResult;
@@ -68,7 +65,7 @@ public void getMe() {
6865

6966
@Test
7067
public void getUpdates() {
71-
GetUpdatesResponse response = bot.execute(new GetUpdates().offset(279823236).timeout(25));
68+
GetUpdatesResponse response = bot.execute(new GetUpdates().offset(279823304).timeout(25));
7269
System.out.println(response);
7370
}
7471

@@ -96,10 +93,15 @@ public void answerInline() {
9693

9794
String inlineQueryId = lastInlineQuery.id();
9895

99-
InlineKeyboardMarkup keyboardMarkup = new InlineKeyboardMarkup(new InlineKeyboardButton[]{new InlineKeyboardButton("inline ok").callbackData("callback ok"), new InlineKeyboardButton("inline cancel").callbackData("callback cancel")});
96+
InlineKeyboardMarkup keyboardMarkup = new InlineKeyboardMarkup(
97+
new InlineKeyboardButton[]{
98+
new InlineKeyboardButton("inline game").callbackGame("pengrad_test_game"),
99+
new InlineKeyboardButton("inline ok").callbackData("callback ok")
100+
101+
});
102+
100103
InlineQueryResult r1 = new InlineQueryResultArticle("1", "title", "message").replyMarkup(keyboardMarkup);
101-
InlineQueryResult r2 = new InlineQueryResultArticle("2", "2 title", "2 message").replyMarkup(keyboardMarkup);
102-
bot.execute(new AnswerInlineQuery(inlineQueryId, r1, r2));
104+
bot.execute(new AnswerInlineQuery(inlineQueryId, r1));
103105
}
104106

105107
private InlineQuery getLastInlineQuery() {
@@ -116,7 +118,26 @@ private InlineQuery getLastInlineQuery() {
116118

117119
@Test
118120
public void answerCallback() {
119-
bot.execute(new AnswerCallbackQuery("220392309269028729").text("answer callback"));
121+
CallbackQuery callbackQuery = getLastCallbackQuery();
122+
if (callbackQuery == null) return;
123+
124+
System.out.println(callbackQuery);
125+
126+
bot.execute(new AnswerCallbackQuery(callbackQuery.id())
127+
.text("answer callback")
128+
.url("https://telegram.me/pengrad_test_bot?start=callback"));
129+
}
130+
131+
private CallbackQuery getLastCallbackQuery() {
132+
GetUpdatesResponse updatesResponse = bot.execute(new GetUpdates());
133+
List<Update> updates = updatesResponse.updates();
134+
Collections.reverse(updates);
135+
for (Update update : updates) {
136+
if (update.callbackQuery() != null) {
137+
return update.callbackQuery();
138+
}
139+
}
140+
return null;
120141
}
121142

122143
@Test

0 commit comments

Comments
 (0)