diff --git a/telegrambots-abilities/src/test/java/org/telegram/abilitybots/api/bot/AbilityBotI18nTest.java b/telegrambots-abilities/src/test/java/org/telegram/abilitybots/api/bot/AbilityBotI18nTest.java new file mode 100644 index 00000000..b8799004 --- /dev/null +++ b/telegrambots-abilities/src/test/java/org/telegram/abilitybots/api/bot/AbilityBotI18nTest.java @@ -0,0 +1,76 @@ +package org.telegram.abilitybots.api.bot; + +import org.junit.After; +import org.junit.Before; +import org.junit.Test; +import org.telegram.abilitybots.api.db.DBContext; +import org.telegram.abilitybots.api.objects.EndUser; +import org.telegram.abilitybots.api.objects.MessageContext; +import org.telegram.abilitybots.api.sender.MessageSender; +import org.telegram.abilitybots.api.sender.SilentSender; + +import java.io.IOException; +import java.util.Locale; + +import static org.apache.commons.lang3.StringUtils.EMPTY; +import static org.mockito.Mockito.*; +import static org.mockito.internal.verification.VerificationModeFactory.times; +import static org.telegram.abilitybots.api.db.MapDBContext.offlineInstance; +import static org.telegram.abilitybots.api.objects.EndUser.endUser; + +public class AbilityBotI18nTest { + public static final EndUser NO_LANGUAGE_USER = endUser(1, "first", "last", "username", null); + public static final EndUser ITALIAN_USER = endUser(2, "first", "last", "username", Locale.ITALY); + + private DBContext db; + private DefaultBot bot; + + private NoPublicCommandsBot noCommandsBot; + + private MessageSender sender; + private SilentSender silent; + + @Before + public void setUp() { + db = offlineInstance("db"); + bot = new DefaultBot(EMPTY, EMPTY, db); + + silent = mock(SilentSender.class); + + bot.sender = sender; + bot.silent = silent; + } + + @Test + public void missingPublicCommandsLocalizedCorrectly() { + NoPublicCommandsBot noCommandsBot = new NoPublicCommandsBot(EMPTY, EMPTY, db); + noCommandsBot.silent = silent; + + MessageContext context = mock(MessageContext.class); + when(context.chatId()).thenReturn(Long.valueOf(NO_LANGUAGE_USER.id())); + when(context.user()).thenReturn(NO_LANGUAGE_USER); + + noCommandsBot.reportCommands().action().accept(context); + + verify(silent, times(1)) + .send("No public commands found.", NO_LANGUAGE_USER.id()); + + // + + MessageContext context1 = mock(MessageContext.class); + when(context1.chatId()).thenReturn(Long.valueOf(ITALIAN_USER.id())); + when(context1.user()).thenReturn(ITALIAN_USER); + + noCommandsBot.reportCommands().action().accept(context1); + + verify(silent, times(1)) + .send("Non sono presenti comandi pubblici.", ITALIAN_USER.id()); + } + + + @After + public void tearDown() throws IOException { + db.clear(); + db.close(); + } +} diff --git a/telegrambots-abilities/src/test/java/org/telegram/abilitybots/api/bot/NoPublicCommandsBot.java b/telegrambots-abilities/src/test/java/org/telegram/abilitybots/api/bot/NoPublicCommandsBot.java new file mode 100644 index 00000000..fa7b70e5 --- /dev/null +++ b/telegrambots-abilities/src/test/java/org/telegram/abilitybots/api/bot/NoPublicCommandsBot.java @@ -0,0 +1,16 @@ +package org.telegram.abilitybots.api.bot; + +import org.telegram.abilitybots.api.db.DBContext; + +public class NoPublicCommandsBot extends AbilityBot { + + + protected NoPublicCommandsBot(String botToken, String botUsername, DBContext db) { + super(botToken, botUsername, db); + } + + @Override + public int creatorId() { + return 0; + } +} \ No newline at end of file diff --git a/telegrambots-abilities/src/test/resources/messages_it_IT.properties b/telegrambots-abilities/src/test/resources/messages_it_IT.properties new file mode 100644 index 00000000..c5656cc1 --- /dev/null +++ b/telegrambots-abilities/src/test/resources/messages_it_IT.properties @@ -0,0 +1 @@ +ability.commands.notFound=Non sono presenti comandi pubblici. \ No newline at end of file