Skip to content

Commit

Permalink
Fix deserialization failures in GetMyXYZ bot API methods
Browse files Browse the repository at this point in the history
  • Loading branch information
aNNiMON committed Jan 8, 2025
1 parent 8b1f0cd commit 9775789
Show file tree
Hide file tree
Showing 4 changed files with 101 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,13 @@
import org.telegram.telegrambots.client.okhttp.OkHttpTelegramClient;
import org.telegram.telegrambots.meta.TelegramUrl;
import org.telegram.telegrambots.meta.api.methods.botapimethods.PartialBotApiMethod;
import org.telegram.telegrambots.meta.api.methods.commands.GetMyCommands;
import org.telegram.telegrambots.meta.api.methods.description.GetMyDescription;
import org.telegram.telegrambots.meta.api.methods.description.GetMyShortDescription;
import org.telegram.telegrambots.meta.api.methods.description.SetMyDescription;
import org.telegram.telegrambots.meta.api.methods.description.SetMyShortDescription;
import org.telegram.telegrambots.meta.api.methods.name.GetMyName;
import org.telegram.telegrambots.meta.api.methods.name.SetMyName;
import org.telegram.telegrambots.meta.api.methods.send.SendAnimation;
import org.telegram.telegrambots.meta.api.methods.send.SendAudio;
import org.telegram.telegrambots.meta.api.methods.send.SendDocument;
Expand All @@ -24,16 +31,22 @@
import org.telegram.telegrambots.meta.api.methods.send.SendVideoNote;
import org.telegram.telegrambots.meta.api.methods.send.SendVoice;
import org.telegram.telegrambots.meta.api.objects.InputFile;
import org.telegram.telegrambots.meta.api.objects.commands.BotCommand;
import org.telegram.telegrambots.meta.api.objects.description.BotDescription;
import org.telegram.telegrambots.meta.api.objects.description.BotShortDescription;
import org.telegram.telegrambots.meta.api.objects.message.Message;
import org.telegram.telegrambots.meta.api.objects.name.BotName;
import org.telegram.telegrambots.meta.exceptions.TelegramApiException;
import org.telegram.telegrambots.meta.exceptions.TelegramApiRequestException;

import java.io.File;
import java.io.Serializable;
import java.util.ArrayList;
import static org.junit.jupiter.api.Assertions.*;

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

public class TestTelegramClientIntegration {
class TestTelegramClientIntegration {
private MockWebServer webServer;

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

@Test
void testGetMyName() throws TelegramApiException {
var method = new GetMyName();

var expected = new BotName(TestData.BOT_USER.getFirstName());
mockMethod(method, expected);

var actual = client.execute(method);
assertEquals(expected, actual);
}

@Test
void testSetMyName() throws TelegramApiException {
var method = new SetMyName();
method.setName(TestData.BOT_USER.getFirstName());

mockMethod(method, Boolean.TRUE);

assertTrue(client.execute(method));
}

@Test
void testGetMyDescription() throws TelegramApiException {
var method = new GetMyDescription();

var expected = new BotDescription("description");
mockMethod(method, expected);

var actual = client.execute(method);
assertEquals(expected, actual);
}

@Test
void testSetMyDescription() throws TelegramApiException {
var method = new SetMyDescription();
method.setDescription("description");

mockMethod(method, Boolean.TRUE);

assertTrue(client.execute(method));
}

@Test
void testGetMyShortDescription() throws TelegramApiException {
var method = new GetMyShortDescription();

var expected = new BotShortDescription("short");
mockMethod(method, expected);

var actual = client.execute(method);
assertEquals(expected, actual);
}

@Test
void testSetMyShortDescription() throws TelegramApiException {
var method = new SetMyShortDescription();
method.setShortDescription("description");

mockMethod(method, Boolean.TRUE);

assertTrue(client.execute(method));
}

@Test
void testGetMyCommands() throws TelegramApiException {
var method = new GetMyCommands();

var expected = new ArrayList<BotCommand>();
expected.add(BotCommand.builder()
.command("command")
.description("description")
.build());
mockMethod(method, expected);

var actual = client.execute(method);
assertEquals(expected, actual);
}

@Test
void testSendMessageException() {
SendMessage method = new SendMessage("someChatId", "someText");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import lombok.Getter;
import lombok.Setter;
import lombok.ToString;
import lombok.extern.jackson.Jacksonized;
import org.telegram.telegrambots.meta.api.interfaces.BotApiObject;

/**
Expand All @@ -20,7 +21,8 @@
@ToString
@AllArgsConstructor
@Builder
public class BotDescription implements BotApiObject {
@Jacksonized
public class BotDescription implements BotApiObject {
private static final String DESCRIPTION_FIELD = "description";

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import lombok.Getter;
import lombok.Setter;
import lombok.ToString;
import lombok.extern.jackson.Jacksonized;
import org.telegram.telegrambots.meta.api.interfaces.BotApiObject;

/**
Expand All @@ -20,7 +21,8 @@
@ToString
@AllArgsConstructor
@Builder
public class BotShortDescription implements BotApiObject {
@Jacksonized
public class BotShortDescription implements BotApiObject {
private static final String SHORT_DESCRIPTION_FIELD = "short_description";

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import lombok.Getter;
import lombok.Setter;
import lombok.ToString;
import lombok.extern.jackson.Jacksonized;
import org.telegram.telegrambots.meta.api.interfaces.BotApiObject;

/**
Expand All @@ -20,7 +21,8 @@
@ToString
@AllArgsConstructor
@Builder
public class BotName implements BotApiObject {
@Jacksonized
public class BotName implements BotApiObject {
private static final String NAME_FIELD = "name";

/**
Expand Down

0 comments on commit 9775789

Please sign in to comment.