diff --git a/RELEASE_NOTES.md b/RELEASE_NOTES.md index f9b77d4..e2cfc16 100644 --- a/RELEASE_NOTES.md +++ b/RELEASE_NOTES.md @@ -1,2 +1,5 @@ JRTB-2: added stub telegram bot JRTB-0: added SpringBoot skeleton project + +## 0.2.0 +* impelements command pattern for handling Telegram bot command diff --git a/pom.xml b/pom.xml index 553d816..8b71895 100644 --- a/pom.xml +++ b/pom.xml @@ -10,7 +10,7 @@ com.github.JBolivarLi javarush-telegrambot - 0.1.0-SNAPSHOT + 0.2.0-SNAPSHOT javarush-telegrambot Telegram bot for Javarush from community to community diff --git a/src/main/java/com/github/JBolivarLi/javarushtelegrambot/bot/JavarushTelegrambotApplication.java b/src/main/java/com/github/JBolivarLi/javarushtelegrambot/bot/JavarushTelegrambotApplication.java index f38ce0e..1cc2c7b 100644 --- a/src/main/java/com/github/JBolivarLi/javarushtelegrambot/bot/JavarushTelegrambotApplication.java +++ b/src/main/java/com/github/JBolivarLi/javarushtelegrambot/bot/JavarushTelegrambotApplication.java @@ -6,13 +6,10 @@ import org.springframework.context.annotation.ComponentScan; - @SpringBootApplication - public class JavarushTelegrambotApplication { - - public static void main(String[] args) { - SpringApplication.run(JavarushTelegrambotApplication.class, args); - } + public static void main(String[] args) { + SpringApplication.run(JavarushTelegrambotApplication.class, args); + } } diff --git a/src/main/java/com/github/JBolivarLi/javarushtelegrambot/bot/bot/JavarushTelegramBot.java b/src/main/java/com/github/JBolivarLi/javarushtelegrambot/bot/bot/JavarushTelegramBot.java index de99213..902665d 100644 --- a/src/main/java/com/github/JBolivarLi/javarushtelegrambot/bot/bot/JavarushTelegramBot.java +++ b/src/main/java/com/github/JBolivarLi/javarushtelegrambot/bot/bot/JavarushTelegramBot.java @@ -1,4 +1,6 @@ package com.github.JBolivarLi.javarushtelegrambot.bot.bot; +import com.github.JBolivarLi.javarushtelegrambot.bot.command.CommandContainer; +import com.github.JBolivarLi.javarushtelegrambot.bot.service.SendBotMessageServiceImpl; import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Component; import org.telegram.telegrambots.bots.TelegramLongPollingBot; @@ -6,8 +8,11 @@ import org.telegram.telegrambots.meta.api.objects.Update; import org.telegram.telegrambots.meta.exceptions.TelegramApiException; +import static com.github.JBolivarLi.javarushtelegrambot.bot.command.CommandName.NO; + @Component public class JavarushTelegramBot extends TelegramLongPollingBot { + public static String COMMAND_PREFIX = "/"; @Value("${bot.username}") private String username; @@ -22,22 +27,21 @@ public String getBotToken() { return token; } + + private final CommandContainer commandContainer; + public JavarushTelegramBot() { + this.commandContainer = new CommandContainer(new SendBotMessageServiceImpl(this)); + } + public void onUpdateReceived(Update update) { if(update.hasMessage() && update.getMessage().hasText()) { String message = update.getMessage().getText().trim(); - String chatId = update.getMessage().getChatId().toString(); - - SendMessage sm = new SendMessage(); - sm.setChatId(chatId); - sm.setText(message + "\n" + "fromBolivarBotWithLove"); - - try { - execute(sm); - } catch (TelegramApiException e) { - //todo add logging to the project. - e.printStackTrace(); + if (message.startsWith(COMMAND_PREFIX)){ + String commandIdentifier = message.split(" ")[0].toLowerCase(); + commandContainer.retrieveCommand(commandIdentifier).execute(update); + } else { + commandContainer.retrieveCommand(NO.getCommandName()).execute(update); } } - } -} +} \ No newline at end of file diff --git a/src/main/java/com/github/JBolivarLi/javarushtelegrambot/bot/command/Command.java b/src/main/java/com/github/JBolivarLi/javarushtelegrambot/bot/command/Command.java new file mode 100644 index 0000000..0981374 --- /dev/null +++ b/src/main/java/com/github/JBolivarLi/javarushtelegrambot/bot/command/Command.java @@ -0,0 +1,9 @@ +package com.github.JBolivarLi.javarushtelegrambot.bot.command; + +import org.telegram.telegrambots.meta.api.objects.Update; +/** + * Command interface for handling telegram-bot commands. + */ +public interface Command { + void execute(Update update); +} diff --git a/src/main/java/com/github/JBolivarLi/javarushtelegrambot/bot/command/CommandContainer.java b/src/main/java/com/github/JBolivarLi/javarushtelegrambot/bot/command/CommandContainer.java new file mode 100644 index 0000000..f2d1e6d --- /dev/null +++ b/src/main/java/com/github/JBolivarLi/javarushtelegrambot/bot/command/CommandContainer.java @@ -0,0 +1,26 @@ +package com.github.JBolivarLi.javarushtelegrambot.bot.command; + +import com.github.JBolivarLi.javarushtelegrambot.bot.service.SendBotMessageService; +import com.github.JBolivarLi.javarushtelegrambot.bot.service.SendBotMessageServiceImpl; + +import java.util.Map; + +import static com.github.JBolivarLi.javarushtelegrambot.bot.command.CommandName.*; + +public class CommandContainer { + private final Map commandMap; + private final Command unknownCommand; + + public CommandContainer(SendBotMessageService sendBotMessageService) { + commandMap = Map.ofEntries(Map.entry(START.getCommandName(), new StartCommand(sendBotMessageService)), + Map.entry(STOP.getCommandName(), new StopCommand(sendBotMessageService)), + Map.entry(HELP.getCommandName(), new HelpCommand(sendBotMessageService)), + Map.entry(NO.getCommandName(), new NoCommand(sendBotMessageService))); + + unknownCommand = new UnknownCommand(sendBotMessageService); + } + + public Command retrieveCommand(String commandIdentifier) { + return commandMap.getOrDefault(commandIdentifier, unknownCommand); + } +} diff --git a/src/main/java/com/github/JBolivarLi/javarushtelegrambot/bot/command/CommandName.java b/src/main/java/com/github/JBolivarLi/javarushtelegrambot/bot/command/CommandName.java new file mode 100644 index 0000000..55e3c88 --- /dev/null +++ b/src/main/java/com/github/JBolivarLi/javarushtelegrambot/bot/command/CommandName.java @@ -0,0 +1,19 @@ +package com.github.JBolivarLi.javarushtelegrambot.bot.command; + +public enum CommandName { + + START("/start"), + STOP("/stop"), + HELP("/help"), + NO("nocommand"); + + private final String commandName; + + CommandName(String commandName) { + this.commandName = commandName; + } + + public String getCommandName() { + return commandName; + } +} diff --git a/src/main/java/com/github/JBolivarLi/javarushtelegrambot/bot/command/HelpCommand.java b/src/main/java/com/github/JBolivarLi/javarushtelegrambot/bot/command/HelpCommand.java new file mode 100644 index 0000000..341554c --- /dev/null +++ b/src/main/java/com/github/JBolivarLi/javarushtelegrambot/bot/command/HelpCommand.java @@ -0,0 +1,29 @@ +package com.github.JBolivarLi.javarushtelegrambot.bot.command; + +import com.github.JBolivarLi.javarushtelegrambot.bot.service.SendBotMessageService; +import org.telegram.telegrambots.meta.api.objects.Update; + +import static com.github.JBolivarLi.javarushtelegrambot.bot.command.CommandName.*; + + +public class HelpCommand implements Command { + + private final SendBotMessageService sendBotMessageService; + + public static final String HELP_MESSAGE = String.format("✨Дотупные команды✨\n\n" + + + "Начать\\закончить работу с ботом\n" + + "%s - начать работу со мной\n" + + "%s - приостановить работу со мной\n\n" + + "%s - получить помощь в работе со мной\n", + START.getCommandName(), STOP.getCommandName(), HELP.getCommandName()); + + public HelpCommand(SendBotMessageService sendBotMessageService) { + this.sendBotMessageService = sendBotMessageService; + } + + @Override + public void execute(Update update) { + sendBotMessageService.sendMessage(update.getMessage().getChatId().toString(), HELP_MESSAGE); + } +} \ No newline at end of file diff --git a/src/main/java/com/github/JBolivarLi/javarushtelegrambot/bot/command/NoCommand.java b/src/main/java/com/github/JBolivarLi/javarushtelegrambot/bot/command/NoCommand.java new file mode 100644 index 0000000..7f00fdf --- /dev/null +++ b/src/main/java/com/github/JBolivarLi/javarushtelegrambot/bot/command/NoCommand.java @@ -0,0 +1,21 @@ +package com.github.JBolivarLi.javarushtelegrambot.bot.command; + +import com.github.JBolivarLi.javarushtelegrambot.bot.service.SendBotMessageService; +import org.telegram.telegrambots.meta.api.objects.Update; + +public class NoCommand implements Command { + + private final SendBotMessageService sendBotMessageService; + + public static final String NO_MESSAGE = "Я поддерживаю команды, начинающиеся со слеша(/).\n" + + "Чтобы посмотреть список команд введите /help"; + + public NoCommand(SendBotMessageService sendBotMessageService) { + this.sendBotMessageService = sendBotMessageService; + } + + @Override + public void execute(Update update) { + sendBotMessageService.sendMessage(update.getMessage().getChatId().toString(), NO_MESSAGE); + } +} diff --git a/src/main/java/com/github/JBolivarLi/javarushtelegrambot/bot/command/StartCommand.java b/src/main/java/com/github/JBolivarLi/javarushtelegrambot/bot/command/StartCommand.java new file mode 100644 index 0000000..dbde2fb --- /dev/null +++ b/src/main/java/com/github/JBolivarLi/javarushtelegrambot/bot/command/StartCommand.java @@ -0,0 +1,24 @@ +package com.github.JBolivarLi.javarushtelegrambot.bot.command; + +import com.github.JBolivarLi.javarushtelegrambot.bot.service.SendBotMessageService; +import org.telegram.telegrambots.meta.api.objects.Update; + +public class StartCommand implements Command { + + private final SendBotMessageService sendBotMessageService; + + public final static String START_MESSAGE = "Привет. Я JBolivar Telegram Bot. Я помогу тебе быть в курсе последних " + + "статей тех авторов, котрые тебе интересны. Я еще маленький и только учусь."; + + // Здесь не добавляем сервис через получение из Application Context. + // Потому что если это сделать так, то будет циклическая зависимость, которая + // ломает работу приложения. + public StartCommand(SendBotMessageService sendBotMessageService) { + this.sendBotMessageService = sendBotMessageService; + } + + @Override + public void execute(Update update) { + sendBotMessageService.sendMessage(update.getMessage().getChatId().toString(), START_MESSAGE); + } +} \ No newline at end of file diff --git a/src/main/java/com/github/JBolivarLi/javarushtelegrambot/bot/command/StopCommand.java b/src/main/java/com/github/JBolivarLi/javarushtelegrambot/bot/command/StopCommand.java new file mode 100644 index 0000000..4bf3a1d --- /dev/null +++ b/src/main/java/com/github/JBolivarLi/javarushtelegrambot/bot/command/StopCommand.java @@ -0,0 +1,20 @@ +package com.github.JBolivarLi.javarushtelegrambot.bot.command; + +import com.github.JBolivarLi.javarushtelegrambot.bot.service.SendBotMessageService; +import org.telegram.telegrambots.meta.api.objects.Update; + +public class StopCommand implements Command { + + private final SendBotMessageService sendBotMessageService; + + public static final String STOP_MESSAGE = "Деактивировал все ваши подписки \uD83D\uDE1F."; + + public StopCommand(SendBotMessageService sendBotMessageService) { + this.sendBotMessageService = sendBotMessageService; + } + + @Override + public void execute(Update update) { + sendBotMessageService.sendMessage(update.getMessage().getChatId().toString(), STOP_MESSAGE); + } +} \ No newline at end of file diff --git a/src/main/java/com/github/JBolivarLi/javarushtelegrambot/bot/command/UnknownCommand.java b/src/main/java/com/github/JBolivarLi/javarushtelegrambot/bot/command/UnknownCommand.java new file mode 100644 index 0000000..aa7f4e0 --- /dev/null +++ b/src/main/java/com/github/JBolivarLi/javarushtelegrambot/bot/command/UnknownCommand.java @@ -0,0 +1,19 @@ +package com.github.JBolivarLi.javarushtelegrambot.bot.command; + +import com.github.JBolivarLi.javarushtelegrambot.bot.service.SendBotMessageService; +import org.telegram.telegrambots.meta.api.objects.Update; + +public class UnknownCommand implements Command{ + public static final String UNKNOWN_MESSAGE = "Не понимаю вас \uD83D\uDE1F, напишите /help чтобы узнать что я понимаю."; + + private final SendBotMessageService sendBotMessageService; + + public UnknownCommand(SendBotMessageService sendBotMessageService) { + this.sendBotMessageService = sendBotMessageService; + } + + @Override + public void execute(Update update) { + sendBotMessageService.sendMessage(update.getMessage().getChatId().toString(), UNKNOWN_MESSAGE); + } +} diff --git a/src/main/java/com/github/JBolivarLi/javarushtelegrambot/bot/service/SendBotMessageService.java b/src/main/java/com/github/JBolivarLi/javarushtelegrambot/bot/service/SendBotMessageService.java new file mode 100644 index 0000000..54545de --- /dev/null +++ b/src/main/java/com/github/JBolivarLi/javarushtelegrambot/bot/service/SendBotMessageService.java @@ -0,0 +1,11 @@ +package com.github.JBolivarLi.javarushtelegrambot.bot.service; + +public interface SendBotMessageService { + /** + * Send message via telegram bot. + * + * @param chatId provided chatId in which messages would be sent. + * @param message provided message to be sent. + */ + void sendMessage(String chatId, String message); +} diff --git a/src/main/java/com/github/JBolivarLi/javarushtelegrambot/bot/service/SendBotMessageServiceImpl.java b/src/main/java/com/github/JBolivarLi/javarushtelegrambot/bot/service/SendBotMessageServiceImpl.java new file mode 100644 index 0000000..b2286c2 --- /dev/null +++ b/src/main/java/com/github/JBolivarLi/javarushtelegrambot/bot/service/SendBotMessageServiceImpl.java @@ -0,0 +1,32 @@ +package com.github.JBolivarLi.javarushtelegrambot.bot.service; + +import com.github.JBolivarLi.javarushtelegrambot.bot.bot.JavarushTelegramBot; +import org.jvnet.hk2.annotations.Service; +import org.springframework.beans.factory.annotation.Autowired; +import org.telegram.telegrambots.meta.api.methods.send.SendMessage; +import org.telegram.telegrambots.meta.exceptions.TelegramApiException; + +@Service +public class SendBotMessageServiceImpl implements SendBotMessageService{ + private final JavarushTelegramBot javarushBot; + + @Autowired + public SendBotMessageServiceImpl(JavarushTelegramBot javarushBot) { + this.javarushBot = javarushBot; + } + + @Override + public void sendMessage(String chatId, String message) { + SendMessage sendMessage = new SendMessage(); + sendMessage.setChatId(chatId); + sendMessage.enableHtml(true); + sendMessage.setText(message); + + try { + javarushBot.execute(sendMessage); + } catch (TelegramApiException e) { + //todo add logging to the project. + e.printStackTrace(); + } + } +} diff --git a/src/test/java/AbstractCommandTest.java b/src/test/java/AbstractCommandTest.java new file mode 100644 index 0000000..7233fce --- /dev/null +++ b/src/test/java/AbstractCommandTest.java @@ -0,0 +1,48 @@ +import com.github.JBolivarLi.javarushtelegrambot.bot.bot.JavarushTelegramBot; +import com.github.JBolivarLi.javarushtelegrambot.bot.command.Command; +import com.github.JBolivarLi.javarushtelegrambot.bot.service.SendBotMessageService; +import com.github.JBolivarLi.javarushtelegrambot.bot.service.SendBotMessageServiceImpl; +import org.junit.jupiter.api.Test; +import org.mockito.Mockito; +import org.telegram.telegrambots.meta.api.methods.send.SendMessage; +import org.telegram.telegrambots.meta.api.objects.Message; +import org.telegram.telegrambots.meta.api.objects.Update; +import org.telegram.telegrambots.meta.exceptions.TelegramApiException; + +/** + * Abstract class for testing {@link Command}s. + */ +abstract class AbstractCommandTest { + + protected JavarushTelegramBot javarushBot = Mockito.mock(JavarushTelegramBot.class); + protected SendBotMessageService sendBotMessageService = new SendBotMessageServiceImpl(javarushBot); + + abstract String getCommandName(); + + abstract String getCommandMessage(); + + abstract Command getCommand(); + + @Test + public void shouldProperlyExecuteCommand() throws TelegramApiException { + //given + Long chatId = 1234567824356L; + + Update update = new Update(); + Message message = Mockito.mock(Message.class); + Mockito.when(message.getChatId()).thenReturn(chatId); + Mockito.when(message.getText()).thenReturn(getCommandName()); + update.setMessage(message); + + SendMessage sendMessage = new SendMessage(); + sendMessage.setChatId(chatId.toString()); + sendMessage.setText(getCommandMessage()); + sendMessage.enableHtml(true); + + //when + getCommand().execute(update); + + //then + Mockito.verify(javarushBot).execute(sendMessage); + } +} \ No newline at end of file diff --git a/src/test/java/CommandContainerTest.java b/src/test/java/CommandContainerTest.java new file mode 100644 index 0000000..9088609 --- /dev/null +++ b/src/test/java/CommandContainerTest.java @@ -0,0 +1,45 @@ +import com.github.JBolivarLi.javarushtelegrambot.bot.command.Command; +import com.github.JBolivarLi.javarushtelegrambot.bot.command.CommandContainer; +import com.github.JBolivarLi.javarushtelegrambot.bot.command.CommandName; +import com.github.JBolivarLi.javarushtelegrambot.bot.command.UnknownCommand; +import com.github.JBolivarLi.javarushtelegrambot.bot.service.SendBotMessageService; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Test; +import org.mockito.Mockito; + +import java.util.Arrays; + +@DisplayName("Unit-level testing for CommandContainer") +class CommandContainerTest { + private CommandContainer commandContainer; + @BeforeEach + public void unit() { + SendBotMessageService sendBotMessageService = Mockito.mock(SendBotMessageService.class); + commandContainer = new CommandContainer(sendBotMessageService); + } + @Test + public void shouldGetAllTheExistingCommands() { + //when-then + Arrays.stream(CommandName.values()) + .forEach(commandName -> { + Command command = commandContainer.retrieveCommand(commandName.getCommandName()); + Assertions.assertNotEquals(UnknownCommand.class, command.getClass()); + }); + } + @Test + public void shouldReturnUnknownCommand() { + //given + String unknownCommand = "/fgjhdfgdf"; + + //when + Command command = commandContainer.retrieveCommand(unknownCommand); + + + //then + Assertions.assertEquals(UnknownCommand.class, command.getClass()); + } + + +} diff --git a/src/test/java/HelpCommandTest.java b/src/test/java/HelpCommandTest.java new file mode 100644 index 0000000..4824ff8 --- /dev/null +++ b/src/test/java/HelpCommandTest.java @@ -0,0 +1,25 @@ +import com.github.JBolivarLi.javarushtelegrambot.bot.command.Command; +import com.github.JBolivarLi.javarushtelegrambot.bot.command.HelpCommand; +import org.junit.jupiter.api.DisplayName; + +import static com.github.JBolivarLi.javarushtelegrambot.bot.command.CommandName.*; +import static com.github.JBolivarLi.javarushtelegrambot.bot.command.HelpCommand.HELP_MESSAGE; + +public class HelpCommandTest extends AbstractCommandTest{ + + @DisplayName("Unit-level testing for HelpCommand") + @Override + String getCommandName() { + return HELP.getCommandName(); + } + + @Override + String getCommandMessage() { + return HELP_MESSAGE; + } + + @Override + Command getCommand() { + return new HelpCommand(sendBotMessageService); + } +} diff --git a/src/test/java/NoCommandTest.java b/src/test/java/NoCommandTest.java new file mode 100644 index 0000000..17afbc5 --- /dev/null +++ b/src/test/java/NoCommandTest.java @@ -0,0 +1,23 @@ +import com.github.JBolivarLi.javarushtelegrambot.bot.command.Command; +import com.github.JBolivarLi.javarushtelegrambot.bot.command.NoCommand; +import org.junit.jupiter.api.DisplayName; + +import static com.github.JBolivarLi.javarushtelegrambot.bot.command.CommandName.*; +import static com.github.JBolivarLi.javarushtelegrambot.bot.command.NoCommand.NO_MESSAGE; + +public class NoCommandTest extends AbstractCommandTest{ + @Override + String getCommandName() { + return NO.getCommandName(); + } + + @Override + String getCommandMessage() { + return NO_MESSAGE; + } + + @Override + Command getCommand() { + return new NoCommand(sendBotMessageService); + } +} diff --git a/src/test/java/SendBotMessageServiceTest.java b/src/test/java/SendBotMessageServiceTest.java new file mode 100644 index 0000000..7ad377a --- /dev/null +++ b/src/test/java/SendBotMessageServiceTest.java @@ -0,0 +1,39 @@ +import com.github.JBolivarLi.javarushtelegrambot.bot.bot.JavarushTelegramBot; +import com.github.JBolivarLi.javarushtelegrambot.bot.service.SendBotMessageService; +import com.github.JBolivarLi.javarushtelegrambot.bot.service.SendBotMessageServiceImpl; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Test; +import org.mockito.Mockito; +import org.telegram.telegrambots.meta.api.methods.send.SendMessage; +import org.telegram.telegrambots.meta.exceptions.TelegramApiException; + +@DisplayName("Unit-level testing for SendBotMessageService") +public class SendBotMessageServiceTest { + private SendBotMessageService sendBotMessageService; + private JavarushTelegramBot javarushBot; + + @BeforeEach + public void init() { + javarushBot = Mockito.mock(JavarushTelegramBot.class); + sendBotMessageService = new SendBotMessageServiceImpl(javarushBot); + } + + @Test + public void shouldProperlySendMessage() throws TelegramApiException { + //given + String chatId = "test_chat_id"; + String message = "test_message"; + + SendMessage sendMessage = new SendMessage(); + sendMessage.setText(message); + sendMessage.setChatId(chatId); + sendMessage.enableHtml(true); + + //when + sendBotMessageService.sendMessage(chatId, message); + + //then + Mockito.verify(javarushBot).execute(sendMessage); + } +} diff --git a/src/test/java/StartCommandTest.java b/src/test/java/StartCommandTest.java new file mode 100644 index 0000000..3bf40e7 --- /dev/null +++ b/src/test/java/StartCommandTest.java @@ -0,0 +1,23 @@ +import com.github.JBolivarLi.javarushtelegrambot.bot.command.Command; +import com.github.JBolivarLi.javarushtelegrambot.bot.command.StartCommand; +import com.github.JBolivarLi.javarushtelegrambot.bot.command.StopCommand; + +import static com.github.JBolivarLi.javarushtelegrambot.bot.command.CommandName.*; +import static com.github.JBolivarLi.javarushtelegrambot.bot.command.StartCommand.START_MESSAGE; + +public class StartCommandTest extends AbstractCommandTest{ + @Override + String getCommandName() { + return START.getCommandName(); + } + + @Override + String getCommandMessage() { + return START_MESSAGE; + } + + @Override + Command getCommand() { + return new StartCommand(sendBotMessageService); + } +} diff --git a/src/test/java/StopCommandTest.java b/src/test/java/StopCommandTest.java new file mode 100644 index 0000000..fb91d6a --- /dev/null +++ b/src/test/java/StopCommandTest.java @@ -0,0 +1,22 @@ +import com.github.JBolivarLi.javarushtelegrambot.bot.command.Command; +import com.github.JBolivarLi.javarushtelegrambot.bot.command.StopCommand; + +import static com.github.JBolivarLi.javarushtelegrambot.bot.command.CommandName.*; +import static com.github.JBolivarLi.javarushtelegrambot.bot.command.StopCommand.STOP_MESSAGE; + +public class StopCommandTest extends AbstractCommandTest{ + @Override + String getCommandName() { + return STOP.getCommandName(); + } + + @Override + String getCommandMessage() { + return STOP_MESSAGE; + } + + @Override + Command getCommand() { + return new StopCommand(sendBotMessageService); + } +} diff --git a/src/test/java/UnknownCommandTest.java b/src/test/java/UnknownCommandTest.java new file mode 100644 index 0000000..9e37688 --- /dev/null +++ b/src/test/java/UnknownCommandTest.java @@ -0,0 +1,21 @@ +import com.github.JBolivarLi.javarushtelegrambot.bot.command.Command; +import com.github.JBolivarLi.javarushtelegrambot.bot.command.UnknownCommand; + +import static com.github.JBolivarLi.javarushtelegrambot.bot.command.UnknownCommand.UNKNOWN_MESSAGE; + +public class UnknownCommandTest extends AbstractCommandTest{ + @Override + String getCommandName() { + return "/kdjfksdjfksj"; + } + + @Override + String getCommandMessage() { + return UNKNOWN_MESSAGE; + } + + @Override + Command getCommand() { + return new UnknownCommand(sendBotMessageService); + } +} diff --git a/src/test/java/com/github/JBolivarLi/javarushtelegrambot/JavarushTelegrambotApplicationTests.java b/src/test/java/com/github/JBolivarLi/javarushtelegrambot/JavarushTelegrambotApplicationTests.java index a99cc8b..fc9c7b9 100644 --- a/src/test/java/com/github/JBolivarLi/javarushtelegrambot/JavarushTelegrambotApplicationTests.java +++ b/src/test/java/com/github/JBolivarLi/javarushtelegrambot/JavarushTelegrambotApplicationTests.java @@ -2,12 +2,12 @@ import org.junit.jupiter.api.Test; import org.springframework.boot.test.context.SpringBootTest; - -//@SpringBootTest/ -class JavarushTelegrambotApplicationTests { - - @Test - void contextLoads() { - } - -} +// +////@SpringBootTest +//class JavarushTelegrambotApplicationTests { +// +// @Test +// void contextLoads() { +// } +// +//}