Skip to content

Keyboard improvements + generics #209

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

Merged
merged 2 commits into from
Aug 4, 2020

Conversation

marcovaneck
Copy link
Contributor

Hi,

I renamed the keyboard-methods to addRow, and only the trivial-changes. The changes to TelegamBotClient have been excluded. They gave me more information on the incorrect-message it sent (deserialization & generics are not always friends).

Best regards

return new Request.Builder()
.url(baseUrl + request.getMethod())
.post(createRequestBody(request))
.build();
}

private RequestBody createRequestBody(BaseRequest<?, ?> request) {
RequestBody createRequestBody(BaseRequest<?, ?> request) {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

let's keep it private.
I will explain my point below in TelegramBotClientTest

}
return builder.build();
}
}

String toParamValue(Object obj) {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

also can be private, if we remove TelegramBotClientTest

@@ -10,28 +13,49 @@
public class InlineKeyboardMarkup extends Keyboard implements Serializable {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tests in ModelTest fails because this class now.
There are 2 things:

  • equalsVerifier fails, need to revert o instanceof InlineKeyboardMarkup in equals()
  • Keyboard before implemented custom toString, so testToString passed, need to generate it for this class


@Test
public void parseSendResponseBadRequest() {
String responseFromTelegram = "{\"ok\":false,\"error_code\":400,\"description\":\"Bad Request: message can't be edited\"}";
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is probably same TelegramBotTest.testResponseParameters() and not related to TelegramBotClient.
I suggest to remove


@Test
public void sendMessageBody() throws IOException {
Keyboard oldKeyboard = new ReplyKeyboardMarkup(
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it's more "migration" test for new ReplyKeyboardMarkup.
And we anyway need to check it via integration test with real API (TelegramBotTest)
yeah, this test can't be launched now coz I used private properties, I will try to change this in future.

so I think we can close createRequestBody method to private and remove this class.
I really believe it's much useful to test all methods with real API.
and then client implementation details will be automatically covered.

what do you think?


@Test
public void sendPollBody() throws IOException {
SendPoll request = new SendPoll("chatId", "Huh", "Bird", "Bear", "Chicken");
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is the same, it's just another version of sendPoll test and should be in TelegramBotTest.
(it's probably already covered there)


@Test
public void toParamValue() {
Assert.assertEquals("1",client.toParamValue(1));
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is also covered by higher integration test.
it does look useful, and maybe if it will be a separate "Serializer" class then this test make sense.
but in this case I think we can keep toParamValue as private

return new ReplyKeyboardMarkup().addRow(firstLine);
}

public static ReplyKeyboardMarkup create(KeyboardButton... firstLine) {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we also make sure that all new constructors are used in TelegramBotTest and thus covered?
you can just change some existing to new ones.

@pengrad
Copy link
Owner

pengrad commented Aug 1, 2020

the biggest issue that you combined all these changes in 1 PR.
I would really prefer to have generics, json, keyboards as separate ones.

there is also 1 test fail:
SendPoll.type() and SendPoll.explanationParseMode() put enum in parameters which gets serialised by json with extra quotes.
Can be changed in toParamValue but more correct to update in SendPoll by using enum.name() as in other places.
I will fix it in master

anyway now it's reviewed and we are closer to merge, hope with next iteration we have all tests green :)
thanks for your contribution!

@pengrad pengrad changed the base branch from master to keyboard-generics August 4, 2020 13:10
@pengrad pengrad merged commit 025ce41 into pengrad:keyboard-generics Aug 4, 2020
pengrad pushed a commit that referenced this pull request Aug 4, 2020
* Keyboard improvements + generics

* Applied review comments
@pengrad
Copy link
Owner

pengrad commented Aug 4, 2020

thank you @marcovaneck!
I moved it here #214 to run check and also added additional constructors for markup with 1-dimensional array, which was very nice idea originally.
have merged to master already

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Centralize gson-calls, generics and simplified Keyboard creations
2 participants