11package ru .untitleddevs .core .client ;
22
3- import org .apache .commons .logging .Log ;
43import org .apache .logging .log4j .Logger ;
54import org .junit .jupiter .api .BeforeEach ;
65import org .junit .jupiter .api .Test ;
6+ import org .telegram .telegrambots .meta .api .methods .AnswerCallbackQuery ;
77import org .telegram .telegrambots .meta .api .methods .groupadministration .BanChatMember ;
88import org .telegram .telegrambots .meta .api .methods .send .SendMessage ;
9+ import org .telegram .telegrambots .meta .api .methods .send .SendPhoto ;
10+ import org .telegram .telegrambots .meta .api .methods .updatingmessages .DeleteMessage ;
11+ import org .telegram .telegrambots .meta .api .methods .updatingmessages .EditMessageReplyMarkup ;
12+ import org .telegram .telegrambots .meta .api .methods .updatingmessages .EditMessageText ;
913import org .telegram .telegrambots .meta .api .objects .CallbackQuery ;
1014import org .telegram .telegrambots .meta .api .objects .Message ;
1115import org .telegram .telegrambots .meta .api .objects .Update ;
1216import org .telegram .telegrambots .meta .api .objects .User ;
17+ import org .telegram .telegrambots .meta .api .objects .replykeyboard .InlineKeyboardMarkup ;
1318import org .telegram .telegrambots .meta .exceptions .TelegramApiException ;
1419import ru .untitled_devs .core .client .Bot ;
1520import ru .untitled_devs .core .fsm .context .FSMContext ;
1621import ru .untitled_devs .core .fsm .storage .StorageKey ;
1722import ru .untitled_devs .core .fsm .storage .Storage ;
1823import ru .untitled_devs .core .routers .Router ;
1924
25+ import java .util .Base64 ;
26+
2027import static org .junit .jupiter .api .Assertions .*;
2128import static org .mockito .ArgumentMatchers .any ;
2229import static org .mockito .Mockito .*;
@@ -26,13 +33,12 @@ class BotTest {
2633 private Bot bot ;
2734 private Storage storage ;
2835 private Router router ;
29- private Logger logger ;
3036
3137 @ BeforeEach
3238 void setUp () {
3339 storage = mock (Storage .class );
3440 router = mock (Router .class );
35- logger = mock (Logger .class );
41+ Logger logger = mock (Logger .class );
3642 bot = new Bot ("testToken" , "testUsername" , storage , logger );
3743 bot .addRouter (router );
3844 }
@@ -50,6 +56,21 @@ void sendMessageSuccessfullySendsMessage() throws TelegramApiException {
5056 verify (bot , times (1 )).execute (any (SendMessage .class ));
5157 }
5258
59+ @ Test
60+ void sendMessageSuccessfullySendsMessageWithMarkup () throws TelegramApiException {
61+ bot = spy (bot );
62+ doReturn (null ).when (bot ).execute (any (SendMessage .class ));
63+
64+ InlineKeyboardMarkup markup = new InlineKeyboardMarkup ();
65+
66+ assertDoesNotThrow (
67+ () -> bot .sendMessage (12345L , "Hello, World!" , markup ),
68+ "sendMessage should not throw any exception when execute(...) returns null"
69+ );
70+
71+ verify (bot , times (1 )).execute (any (SendMessage .class ));
72+ }
73+
5374 @ Test
5475 void sendMessageHandlesTelegramApiException () throws TelegramApiException {
5576 bot = spy (bot );
@@ -89,6 +110,78 @@ void banChatMemberHandlesTelegramApiException() throws TelegramApiException {
89110 verify (bot , times (1 )).execute (any (BanChatMember .class ));
90111 }
91112
113+ @ Test
114+ void seditMessageSuccessfullyEditMessageText () throws TelegramApiException {
115+ bot = spy (bot );
116+ doReturn (null ).when (bot ).execute (any (EditMessageText .class ));
117+
118+ assertDoesNotThrow (
119+ () -> bot .editMessageText (12345L , 12415125 ,"Hello, World!" ),
120+ "sendMessage should not throw any exception when execute(...) returns null"
121+ );
122+
123+ verify (bot , times (1 )).execute (any (EditMessageText .class ));
124+ }
125+
126+ @ Test
127+ void EditMessageMarkupSuccessfullyEditMessageMarkup () throws TelegramApiException {
128+ bot = spy (bot );
129+ doReturn (null ).when (bot ).execute (any (EditMessageReplyMarkup .class ));
130+
131+ InlineKeyboardMarkup markup = new InlineKeyboardMarkup ();
132+
133+ assertDoesNotThrow (
134+ () -> bot .editMessageReplyMarkup (12345L , 12415125 , markup ),
135+ "sendMessage should not throw any exception when execute(...) returns null"
136+ );
137+
138+ verify (bot , times (1 )).execute (any (EditMessageReplyMarkup .class ));
139+ }
140+
141+ @ Test
142+ void deleteMessageSuccessfullyDeletesMessage () throws TelegramApiException {
143+ bot = spy (bot );
144+ doReturn (null ).when (bot ).execute (any (DeleteMessage .class ));
145+
146+ assertDoesNotThrow (
147+ () -> bot .deleteMessage (12345L , 12415125 ),
148+ "sendMessage should not throw any exception when execute(...) returns null"
149+ );
150+
151+ verify (bot , times (1 )).execute (any (DeleteMessage .class ));
152+ }
153+
154+ @ Test
155+ void sendPhotoSuccessfullySendsPhoto () throws TelegramApiException {
156+ bot = spy (bot );
157+ doReturn (null ).when (bot ).execute (any (SendPhoto .class ));
158+
159+ byte [] photo = Base64 .getDecoder ().decode (
160+ "iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAQAAAC1HAwCAAAAC0lEQVQI12NgYAAAAAMAASsJTYQAAAAASUVORK5CYII="
161+ );
162+
163+ assertDoesNotThrow (
164+ () -> bot .sendPhoto (12345L , "12415125" , photo ),
165+ "sendMessage should not throw any exception when execute(...) returns null"
166+ );
167+
168+ verify (bot , times (1 )).execute (any (SendPhoto .class ));
169+ }
170+
171+ @ Test
172+ void answerCallbackQuerySuccessfullyAnswersCallback () throws TelegramApiException {
173+ bot = spy (bot );
174+ doReturn (null ).when (bot ).execute (any (AnswerCallbackQuery .class ));
175+
176+ assertDoesNotThrow (
177+ () -> bot .answerCallbackQuery ("21323" , "12415125" , false ),
178+ "sendMessage should not throw any exception when execute(...) returns null"
179+ );
180+
181+ verify (bot , times (1 )).execute (any (AnswerCallbackQuery .class ));
182+ }
183+
184+
92185 @ Test
93186 void onUpdateMessageReceivedRoutesUpdateToAllRouters () {
94187 Update update = mock (Update .class );
0 commit comments