Add constructor with bot username
This commit is contained in:
parent
323d7607d6
commit
5ea6fc9f09
@ -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
|
||||
|
@ -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");
|
||||
|
Loading…
Reference in New Issue
Block a user