Add constructor with bot username

This commit is contained in:
Grig Alex 2020-10-21 22:16:38 +03:00
parent 323d7607d6
commit 5ea6fc9f09
No known key found for this signature in database
GPG Key ID: 7176EDB56B1B35CB
2 changed files with 21 additions and 0 deletions

View File

@ -24,6 +24,18 @@ public final class CommandRegistry implements ICommandRegistry {
private final Supplier<String> botUsernameSupplier;
private BiConsumer<AbsSender, Message> defaultConsumer;
/**
* Creates a Command registry
*
* @param allowCommandsWithUsername True to allow commands with username, false otherwise
* @param botUsername Bot username
*/
public CommandRegistry(boolean allowCommandsWithUsername, String botUsername) {
Objects.requireNonNull(botUsername, "Bot username must not be null");
this.allowCommandsWithUsername = allowCommandsWithUsername;
this.botUsernameSupplier = () -> botUsername;
}
/**
* Creates a Command registry
* @param allowCommandsWithUsername True to allow commands with username, false otherwise

View File

@ -8,6 +8,15 @@ import org.telegram.telegrambots.meta.bots.AbsSender;
class CommandRegistryTest {
@Test
void should_create_registry() {
CommandRegistry registry = new CommandRegistry(true, "BotUsername");
Assertions.assertNotNull(registry, "CommandRegistry is not created");
NullPointerException exception = Assertions.assertThrows(NullPointerException.class,
() -> new CommandRegistry(true, (String) null));
Assertions.assertEquals("Bot username must not be null", exception.getMessage(), "Invalid exception message");
}
@Test
void should_executes_commandWithBotUsername() {
CommandRegistry registry = new CommandRegistry(true, () -> "BotUsername");