From 54096d2e850ce700c5b2da32336199a6eec22a68 Mon Sep 17 00:00:00 2001 From: Abbas Abou Daya Date: Sat, 18 Jul 2020 00:43:28 -0700 Subject: [PATCH] Add test --- .../abilitybots/api/bot/AbilityBotTest.java | 15 +++++++++++++++ .../telegram/abilitybots/api/bot/DefaultBot.java | 7 +++++++ 2 files changed, 22 insertions(+) diff --git a/telegrambots-abilities/src/test/java/org/telegram/abilitybots/api/bot/AbilityBotTest.java b/telegrambots-abilities/src/test/java/org/telegram/abilitybots/api/bot/AbilityBotTest.java index 476b3b1e..f6823690 100644 --- a/telegrambots-abilities/src/test/java/org/telegram/abilitybots/api/bot/AbilityBotTest.java +++ b/telegrambots-abilities/src/test/java/org/telegram/abilitybots/api/bot/AbilityBotTest.java @@ -644,6 +644,21 @@ public class AbilityBotTest { verify(silent, times(1)).send(expected, GROUP_ID); } + @Test + void canProcessChannelPosts() { + Update update = mock(Update.class); + Message message = mock(Message.class); + when(message.getChatId()).thenReturn(1L); + + when(update.getChannelPost()).thenReturn(message); + when(update.hasChannelPost()).thenReturn(true); + + bot.onUpdateReceived(update); + + String expected = "test channel post"; + verify(silent, times(1)).send(expected, 1); + } + private void handlesAllUpdates(Consumer utilMethod) { Arrays.stream(Update.class.getMethods()) // filter to all these methods of hasXXX (hasPoll, hasMessage, etc...) diff --git a/telegrambots-abilities/src/test/java/org/telegram/abilitybots/api/bot/DefaultBot.java b/telegrambots-abilities/src/test/java/org/telegram/abilitybots/api/bot/DefaultBot.java index 462453da..7838d07f 100644 --- a/telegrambots-abilities/src/test/java/org/telegram/abilitybots/api/bot/DefaultBot.java +++ b/telegrambots-abilities/src/test/java/org/telegram/abilitybots/api/bot/DefaultBot.java @@ -3,6 +3,7 @@ package org.telegram.abilitybots.api.bot; import org.telegram.abilitybots.api.db.DBContext; import org.telegram.abilitybots.api.objects.Ability; import org.telegram.abilitybots.api.objects.Ability.AbilityBuilder; +import org.telegram.abilitybots.api.objects.Flag; import org.telegram.abilitybots.api.objects.Reply; import org.telegram.abilitybots.api.toggle.AbilityToggle; @@ -72,6 +73,12 @@ public class DefaultBot extends AbilityBot { .build(); } + public Reply channelPostReply() { + return Reply.of( + upd -> silent.send("test channel post", upd.getChannelPost().getChatId()), Flag.CHANNEL_POST + ); + } + public Ability testAbility() { return getDefaultBuilder().build(); }