Skip to content

Commit d0b1677

Browse files
aNNiMONrubenlagus
andcommitted
Fix deserialization failures in GetMyXYZ bot API methods (#1475)
Co-authored-by: Ruben Bermudez <[email protected]>
1 parent e530ff4 commit d0b1677

File tree

4 files changed

+101
-4
lines changed

4 files changed

+101
-4
lines changed

telegrambots-client/src/test/java/org/telegram/telegrambots/client/TestTelegramClientIntegration.java

Lines changed: 92 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,13 @@
1414
import org.telegram.telegrambots.client.okhttp.OkHttpTelegramClient;
1515
import org.telegram.telegrambots.meta.TelegramUrl;
1616
import org.telegram.telegrambots.meta.api.methods.botapimethods.PartialBotApiMethod;
17+
import org.telegram.telegrambots.meta.api.methods.commands.GetMyCommands;
18+
import org.telegram.telegrambots.meta.api.methods.description.GetMyDescription;
19+
import org.telegram.telegrambots.meta.api.methods.description.GetMyShortDescription;
20+
import org.telegram.telegrambots.meta.api.methods.description.SetMyDescription;
21+
import org.telegram.telegrambots.meta.api.methods.description.SetMyShortDescription;
22+
import org.telegram.telegrambots.meta.api.methods.name.GetMyName;
23+
import org.telegram.telegrambots.meta.api.methods.name.SetMyName;
1724
import org.telegram.telegrambots.meta.api.methods.send.SendAnimation;
1825
import org.telegram.telegrambots.meta.api.methods.send.SendAudio;
1926
import org.telegram.telegrambots.meta.api.methods.send.SendDocument;
@@ -24,16 +31,22 @@
2431
import org.telegram.telegrambots.meta.api.methods.send.SendVideoNote;
2532
import org.telegram.telegrambots.meta.api.methods.send.SendVoice;
2633
import org.telegram.telegrambots.meta.api.objects.InputFile;
34+
import org.telegram.telegrambots.meta.api.objects.commands.BotCommand;
35+
import org.telegram.telegrambots.meta.api.objects.description.BotDescription;
36+
import org.telegram.telegrambots.meta.api.objects.description.BotShortDescription;
2737
import org.telegram.telegrambots.meta.api.objects.message.Message;
38+
import org.telegram.telegrambots.meta.api.objects.name.BotName;
2839
import org.telegram.telegrambots.meta.exceptions.TelegramApiException;
2940
import org.telegram.telegrambots.meta.exceptions.TelegramApiRequestException;
3041

3142
import java.io.File;
3243
import java.io.Serializable;
44+
import java.util.ArrayList;
45+
import static org.junit.jupiter.api.Assertions.*;
3346

3447
import static org.junit.jupiter.api.Assertions.assertEquals;
3548

36-
public class TestTelegramClientIntegration {
49+
class TestTelegramClientIntegration {
3750
private MockWebServer webServer;
3851

3952
private static final String TOKEN = "testToken";
@@ -168,6 +181,84 @@ void testSendAnimation() throws TelegramApiException {
168181
assertEquals(responseMessage, parsedMessage);
169182
}
170183

184+
@Test
185+
void testGetMyName() throws TelegramApiException {
186+
var method = new GetMyName();
187+
188+
var expected = new BotName(TestData.BOT_USER.getFirstName());
189+
mockMethod(method, expected);
190+
191+
var actual = client.execute(method);
192+
assertEquals(expected, actual);
193+
}
194+
195+
@Test
196+
void testSetMyName() throws TelegramApiException {
197+
var method = new SetMyName();
198+
method.setName(TestData.BOT_USER.getFirstName());
199+
200+
mockMethod(method, Boolean.TRUE);
201+
202+
assertTrue(client.execute(method));
203+
}
204+
205+
@Test
206+
void testGetMyDescription() throws TelegramApiException {
207+
var method = new GetMyDescription();
208+
209+
var expected = new BotDescription("description");
210+
mockMethod(method, expected);
211+
212+
var actual = client.execute(method);
213+
assertEquals(expected, actual);
214+
}
215+
216+
@Test
217+
void testSetMyDescription() throws TelegramApiException {
218+
var method = new SetMyDescription();
219+
method.setDescription("description");
220+
221+
mockMethod(method, Boolean.TRUE);
222+
223+
assertTrue(client.execute(method));
224+
}
225+
226+
@Test
227+
void testGetMyShortDescription() throws TelegramApiException {
228+
var method = new GetMyShortDescription();
229+
230+
var expected = new BotShortDescription("short");
231+
mockMethod(method, expected);
232+
233+
var actual = client.execute(method);
234+
assertEquals(expected, actual);
235+
}
236+
237+
@Test
238+
void testSetMyShortDescription() throws TelegramApiException {
239+
var method = new SetMyShortDescription();
240+
method.setShortDescription("description");
241+
242+
mockMethod(method, Boolean.TRUE);
243+
244+
assertTrue(client.execute(method));
245+
}
246+
247+
@Test
248+
void testGetMyCommands() throws TelegramApiException {
249+
var method = new GetMyCommands();
250+
251+
var expected = new ArrayList<BotCommand>();
252+
expected.add(BotCommand.builder()
253+
.command("command")
254+
.description("description")
255+
.build());
256+
mockMethod(method, expected);
257+
258+
var actual = client.execute(method);
259+
assertEquals(expected, actual);
260+
}
261+
171262
@Test
172263
void testSendMessageException() {
173264
SendMessage method = new SendMessage("someChatId", "someText");

telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/description/BotDescription.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import lombok.Getter;
88
import lombok.Setter;
99
import lombok.ToString;
10+
import lombok.extern.jackson.Jacksonized;
1011
import org.telegram.telegrambots.meta.api.interfaces.BotApiObject;
1112

1213
/**
@@ -20,7 +21,8 @@
2021
@ToString
2122
@AllArgsConstructor
2223
@Builder
23-
public class BotDescription implements BotApiObject {
24+
@Jacksonized
25+
public class BotDescription implements BotApiObject {
2426
private static final String DESCRIPTION_FIELD = "description";
2527

2628
/**

telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/description/BotShortDescription.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import lombok.Getter;
88
import lombok.Setter;
99
import lombok.ToString;
10+
import lombok.extern.jackson.Jacksonized;
1011
import org.telegram.telegrambots.meta.api.interfaces.BotApiObject;
1112

1213
/**
@@ -20,7 +21,8 @@
2021
@ToString
2122
@AllArgsConstructor
2223
@Builder
23-
public class BotShortDescription implements BotApiObject {
24+
@Jacksonized
25+
public class BotShortDescription implements BotApiObject {
2426
private static final String SHORT_DESCRIPTION_FIELD = "short_description";
2527

2628
/**

telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/name/BotName.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import lombok.Getter;
88
import lombok.Setter;
99
import lombok.ToString;
10+
import lombok.extern.jackson.Jacksonized;
1011
import org.telegram.telegrambots.meta.api.interfaces.BotApiObject;
1112

1213
/**
@@ -20,7 +21,8 @@
2021
@ToString
2122
@AllArgsConstructor
2223
@Builder
23-
public class BotName implements BotApiObject {
24+
@Jacksonized
25+
public class BotName implements BotApiObject {
2426
private static final String NAME_FIELD = "name";
2527

2628
/**

0 commit comments

Comments
 (0)