214
214
*/
215
215
public class TelegramBotTest {
216
216
217
- private static Properties props = new Properties ();
217
+ private static final Properties props = new Properties ();
218
218
219
219
static String getProp (String key ) {
220
220
return props .getProperty (key , System .getenv (key ));
@@ -223,7 +223,8 @@ static String getProp(String key) {
223
223
static {
224
224
try {
225
225
props .load (new FileInputStream ("local.properties" ));
226
- } catch (Exception ignored ) {}
226
+ } catch (Exception ignored ) {
227
+ }
227
228
228
229
String chat = getProp ("CHAT_ID" );
229
230
String group = getProp ("GROUP_ID" );
@@ -455,11 +456,8 @@ public void editMessageCaption() {
455
456
public void editMessageReplyMarkup () {
456
457
String text = "Update" + System .currentTimeMillis ();
457
458
458
- InlineKeyboardMarkup keyboard = new InlineKeyboardMarkup (new InlineKeyboardButton []{
459
- new InlineKeyboardButton (text ).url ("https://google.com" )});
460
-
461
- InlineKeyboardMarkup gameKeyboard = new InlineKeyboardMarkup (new InlineKeyboardButton []{
462
- new InlineKeyboardButton (text ).callbackGame ("test game" )});
459
+ InlineKeyboardMarkup keyboard = new InlineKeyboardMarkup (new InlineKeyboardButton (text ).url ("https://google.com" ));
460
+ InlineKeyboardMarkup gameKeyboard = new InlineKeyboardMarkup (new InlineKeyboardButton (text ).callbackGame ("test game" ));
463
461
464
462
BaseResponse response = bot .execute (new EditMessageReplyMarkup (chatId , 8124 ).replyMarkup (keyboard ));
465
463
assertTrue (response .isOk ());
@@ -488,16 +486,15 @@ public void answerInline() {
488
486
assertNull (inlineQuery .location ());
489
487
490
488
491
- InlineKeyboardMarkup keyboardMarkup = new InlineKeyboardMarkup (new InlineKeyboardButton []{
489
+ InlineKeyboardMarkup keyboardMarkup = new InlineKeyboardMarkup (
492
490
new InlineKeyboardButton ("inline game" ).callbackGame ("pengrad test game description" ),
493
491
new InlineKeyboardButton ("inline ok" ).callbackData ("callback ok" ),
494
492
new InlineKeyboardButton ("cancel" ).callbackData ("callback cancel" ),
495
493
new InlineKeyboardButton ("url" ).url (someUrl ),
496
494
new InlineKeyboardButton ("switch inline" ).switchInlineQuery ("query" ),
497
- new InlineKeyboardButton ("switch inline current" ).switchInlineQueryCurrentChat ("query" ),
498
- });
495
+ new InlineKeyboardButton ("switch inline current" ).switchInlineQueryCurrentChat ("query" ));
499
496
500
- InlineQueryResult [] results = new InlineQueryResult []{
497
+ InlineQueryResult <?> [] results = new InlineQueryResult []{
501
498
new InlineQueryResultArticle ("1" , "title" ,
502
499
new InputTextMessageContent ("message" ).disableWebPagePreview (false ).parseMode (ParseMode .HTML ))
503
500
.url (someUrl ).hideUrl (true ).description ("desc" ).thumbUrl (someUrl ).thumbHeight (100 ).thumbWidth (100 ),
@@ -697,16 +694,16 @@ public void sendMessage() {
697
694
sendResponse = bot .execute (new SendMessage (chatId , "message with keyboard" )
698
695
.parseMode (ParseMode .HTML )
699
696
.disableWebPagePreview (false )
700
- .replyMarkup (new ReplyKeyboardMarkup (new KeyboardButton []{
697
+ .replyMarkup (new ReplyKeyboardMarkup (
701
698
new KeyboardButton ("contact" ).requestContact (true ),
702
- new KeyboardButton ("location" ).requestLocation (true )} )
699
+ new KeyboardButton ("location" ).requestLocation (true ))
703
700
.oneTimeKeyboard (true )
704
701
.resizeKeyboard (true )
705
702
.selective (true )));
706
703
MessageTest .checkTextMessage (sendResponse .message ());
707
704
708
705
sendResponse = bot .execute (new SendMessage (chatId , "simple buttons" )
709
- .replyMarkup (new ReplyKeyboardMarkup (new String []{ "ok" , "cancel" } )));
706
+ .replyMarkup (new ReplyKeyboardMarkup ("ok" , "cancel" )));
710
707
MessageTest .checkTextMessage (sendResponse .message ());
711
708
}
712
709
@@ -1318,12 +1315,12 @@ public void getStickerSet() {
1318
1315
StickerTest .check (sticker , true , true );
1319
1316
}
1320
1317
assertTrue (stickerSet .containsMasks ());
1321
- assertEquals (this .stickerSet , stickerSet .name ());
1318
+ assertEquals (TelegramBotTest .stickerSet , stickerSet .name ());
1322
1319
assertEquals ("test1" , stickerSet .title ());
1323
1320
assertFalse (stickerSet .isAnimated ());
1324
1321
1325
1322
Sticker sticker = stickerSet .stickers ()[0 ];
1326
- assertEquals (this .stickerSet , sticker .setName ());
1323
+ assertEquals (TelegramBotTest .stickerSet , sticker .setName ());
1327
1324
MaskPosition maskPosition = sticker .maskPosition ();
1328
1325
assertEquals (MaskPosition .Point .forehead .name (), maskPosition .point ());
1329
1326
assertEquals (0f , maskPosition .xShift (), 0 );
@@ -1424,9 +1421,7 @@ public void editMessageLiveLocation() {
1424
1421
String buttonText = "btn_" + System .currentTimeMillis ();
1425
1422
response = bot .execute (
1426
1423
new EditMessageLiveLocation ("AgAAAPrwAQCj_Q4D2s-51_8jsuU" , 21 , 102 )
1427
- .replyMarkup (new InlineKeyboardMarkup (
1428
- new InlineKeyboardButton []{new InlineKeyboardButton (buttonText ).callbackGame (buttonText )}
1429
- ))
1424
+ .replyMarkup (new InlineKeyboardMarkup (new InlineKeyboardButton (buttonText ).callbackGame (buttonText )))
1430
1425
);
1431
1426
assertTrue (response .isOk ());
1432
1427
}
@@ -1653,7 +1648,7 @@ public void decryptPassport() throws Exception {
1653
1648
if (encElement .translation () != null ) {
1654
1649
files .addAll (Arrays .asList (encElement .translation ()));
1655
1650
}
1656
- for (PassportFile file : files ) {
1651
+ for (PassportFile file : files ) {
1657
1652
if (file == null ) continue ;
1658
1653
byte [] data = encElement .decryptFile (file , credentials , bot );
1659
1654
assertTrue (data .length > 0 );
@@ -1708,11 +1703,10 @@ public void sendPollWithKeyboard() {
1708
1703
new SendPoll (chatId , question , answers )
1709
1704
.type ("regular" )
1710
1705
.allowsMultipleAnswers (true )
1711
- .replyMarkup (new ReplyKeyboardMarkup (new KeyboardButton []{
1706
+ .replyMarkup (new ReplyKeyboardMarkup (
1712
1707
new KeyboardButton ("all polls" ).requestPoll (new KeyboardButtonPollType ()),
1713
1708
new KeyboardButton ("quiz" ).requestPoll (new KeyboardButtonPollType (Poll .Type .quiz )),
1714
- new KeyboardButton ("regular" ).requestPoll (new KeyboardButtonPollType ("regular" ))
1715
- }))
1709
+ new KeyboardButton ("regular" ).requestPoll (new KeyboardButtonPollType ("regular" ))))
1716
1710
.closeDate (closeDate )
1717
1711
);
1718
1712
Poll poll = sendResponse .message ().poll ();
@@ -1800,12 +1794,11 @@ public void loginButton() {
1800
1794
String text = "login" ;
1801
1795
String url = "http://pengrad.herokuapp.com/hello" ;
1802
1796
SendResponse response = bot .execute (
1803
- new SendMessage (chatId , "Login button" ).replyMarkup (new InlineKeyboardMarkup (new InlineKeyboardButton []{
1797
+ new SendMessage (chatId , "Login button" ).replyMarkup (new InlineKeyboardMarkup (
1804
1798
new InlineKeyboardButton (text ).loginUrl (new LoginUrl (url )
1805
1799
.forwardText ("forwarded login" )
1806
1800
.botUsername ("pengrad_test_bot" )
1807
- .requestWriteAccess (true ))
1808
- })));
1801
+ .requestWriteAccess (true )))));
1809
1802
assertTrue (response .isOk ());
1810
1803
InlineKeyboardButton button = response .message ().replyMarkup ().inlineKeyboard ()[0 ][0 ];
1811
1804
assertEquals (text , button .text ());
0 commit comments