Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix deserialization failures in GetMyXYZ bot API methods #1475

Open
wants to merge 1 commit into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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