TDLightTelegramBots/telegrambots-abilities/src/test/java/org/telegram/abilitybots/api/bot/AbilityBotI18nTest.java

83 lines
2.6 KiB
Java
Raw Normal View History

2018-05-04 18:15:02 +02:00
package org.telegram.abilitybots.api.bot;
2022-02-24 02:04:29 +01:00
import static org.apache.commons.lang3.StringUtils.EMPTY;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;
import static org.mockito.internal.verification.VerificationModeFactory.times;
import static org.telegram.abilitybots.api.bot.TestUtils.mockContext;
import static org.telegram.abilitybots.api.db.MapDBContext.offlineInstance;
import java.io.IOException;
2019-07-08 21:22:51 +02:00
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
2018-05-04 18:15:02 +02:00
import org.telegram.abilitybots.api.db.DBContext;
import org.telegram.abilitybots.api.objects.MessageContext;
import org.telegram.abilitybots.api.sender.MessageSender;
import org.telegram.abilitybots.api.sender.SilentSender;
2018-07-16 19:54:26 +02:00
import org.telegram.telegrambots.meta.api.objects.User;
2018-05-04 18:15:02 +02:00
2019-07-08 21:22:51 +02:00
class AbilityBotI18nTest {
2022-06-22 18:46:44 +02:00
private static final User NO_LANGUAGE_USER = new User(1L, "first", false, "last", "username", null, false, false, false, false, false, false, false, false, false, false, false);
private static final User ITALIAN_USER = new User(2L, "first", false, "last", "username", "it-IT", false, false, false, false, false, false, false, false, false, false, false);
2018-05-04 18:15:02 +02:00
2018-05-18 10:40:27 +02:00
private DBContext db;
private NoPublicCommandsBot bot;
private DefaultAbilities defaultAbs;
2018-05-04 18:15:02 +02:00
2018-05-18 10:40:27 +02:00
private MessageSender sender;
private SilentSender silent;
2018-05-04 18:15:02 +02:00
2019-07-08 21:22:51 +02:00
@BeforeEach
void setUp() {
2018-05-18 10:40:27 +02:00
db = offlineInstance("db");
bot = new NoPublicCommandsBot(EMPTY, EMPTY, db);
bot.onRegister();
defaultAbs = new DefaultAbilities(bot);
2018-05-04 18:15:02 +02:00
2018-05-18 10:40:27 +02:00
sender = mock(MessageSender.class);
silent = mock(SilentSender.class);
2018-05-04 18:15:02 +02:00
2018-05-18 10:40:27 +02:00
bot.sender = sender;
bot.silent = silent;
2019-07-08 21:22:51 +02:00
}
2019-07-08 21:22:51 +02:00
@AfterEach
void tearDown() throws IOException {
db.clear();
db.close();
2018-05-18 10:40:27 +02:00
}
2018-05-04 18:15:02 +02:00
2018-05-18 10:40:27 +02:00
@Test
2019-07-08 21:22:51 +02:00
void missingPublicCommandsLocalizedInEnglishByDefault() {
2018-05-18 10:40:27 +02:00
MessageContext context = mockContext(NO_LANGUAGE_USER);
2018-05-04 18:15:02 +02:00
defaultAbs.reportCommands().action().accept(context);
2018-05-04 18:15:02 +02:00
2018-05-18 10:40:27 +02:00
verify(silent, times(1))
.send("No available commands found.", NO_LANGUAGE_USER.getId());
2018-05-18 10:40:27 +02:00
}
2018-05-04 18:15:02 +02:00
2018-05-18 10:40:27 +02:00
@Test
2019-07-08 21:22:51 +02:00
void missingPublicCommandsLocalizedInItalian() {
2018-05-21 13:01:45 +02:00
MessageContext context = mockContext(ITALIAN_USER);
2018-05-04 18:15:02 +02:00
defaultAbs.reportCommands().action().accept(context);
2018-05-04 18:15:02 +02:00
2018-05-18 10:40:27 +02:00
verify(silent, times(1))
.send("Non sono presenti comandi disponibile.", ITALIAN_USER.getId());
2018-05-18 10:40:27 +02:00
}
2018-05-04 18:15:02 +02:00
2018-05-18 10:40:27 +02:00
public static class NoPublicCommandsBot extends AbilityBot {
2018-05-04 18:15:02 +02:00
2019-07-08 21:22:51 +02:00
NoPublicCommandsBot(String botToken, String botUsername, DBContext db) {
super(botToken, botUsername, db);
}
2018-05-18 10:40:27 +02:00
@Override
2021-03-09 11:59:28 +01:00
public long creatorId() {
return 1;
}
2018-05-18 10:40:27 +02:00
}
2018-05-04 18:15:02 +02:00
}