diff --git a/.travis.yml b/.travis.yml index 81b32439..ff7b873c 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,6 +1,10 @@ language: java jdk: - oraclejdk8 + - oraclejdk11 + - openjdk8 + - openjdk11 + - openjdk-ea install: mvn install -Dgpg.skip script: mvn clean compile test after_success: @@ -9,3 +13,6 @@ notifications: webhooks: secure: "jC7dK/x67ONWQoeLZg4HfW0mHhcjDerJjsLLkrbcpltiqAbw2p7XfY8Pk4zHoD72a+5o6WKu5WvYvZ4OdldnjP8Y6ZUbliQ5RG3olg3gFDoe0+sc3geeb4HRYVcdI20O0z4Bup/qO0ZihxPBc0D5IpHmFxlaqlZG0WeST4CicU8PNnBh6aX9/VMrwXhkMb2vfzmjmIhMbx/uK5+93bnk/vR5Uwu00/Yd2cTAAWMaqK1MRdtR0WLbxlUNsprEfCjYiH3n9XZnlKXs6cLC8EOU436Wx7aepiAszW0wWFMe/7nVqOqztrQiKNvL0qXYwlQf0BLechJdt458EopL9QCu687TNDFYvg1yERAmCRiaayYZcX3PbUSMr6H5Q+Odntjs3XKyzfgSqqlkgf/SAND5jny1/1uteVoplZmFXuZFIiK4H8Rl2ezy1/8pnbp+JD3YEfiA2NuRjlou1BZXyMhiqqVXbrJqk/tXF6yZSkDlYJfNsWzRCGfra4B6JjEvUP927chIFm1ii3dgNstXDo1evV46+OQQO4HKvMPdtU2FPvWpPlkTxnmpZRZjB+bjmybluJdWT3E+e1C3wm7YbRe3vporhpfNPlnod6M0G10y9CKzl9Fbcku6X1FtM+IoPO/aqZ8S4/CBZoYEuR/Nk6bcvsYouxtyIl6PSuF9E8YjpJE=" email: false +matrix: + allow_failures: + - jdk: openjdk-ea \ No newline at end of file diff --git a/Bots.ipr b/Bots.ipr index 242d28a4..06f47553 100644 --- a/Bots.ipr +++ b/Bots.ipr @@ -12,6 +12,12 @@ + + + + + + @@ -23,21 +29,15 @@ - - - - - - - - - - - - - + + + + + + + @@ -757,7 +757,7 @@ - - + @@ -898,15 +898,15 @@ - + - + - + - + @@ -975,26 +975,48 @@ - + - + - + - + - + - + - + - + + + + + + + + + + + + + + + + + + + + + + + @@ -1008,15 +1030,15 @@ - + - + - + - + @@ -1030,15 +1052,15 @@ - + - + - + - + @@ -1052,15 +1074,15 @@ - + - + - + - + @@ -1074,15 +1096,37 @@ - + - + - + - + + + + + + + + + + + + + + + + + + + + + + + @@ -1096,48 +1140,15 @@ - + - + - + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + @@ -1151,15 +1162,26 @@ - + - + - + - + + + + + + + + + + + + @@ -1173,466 +1195,422 @@ - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + @@ -1646,37 +1624,37 @@ - + - + - + - + - + - + - + - + - + - + - + - + @@ -1690,6 +1668,50 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -1701,26 +1723,59 @@ - + - + - + - + - + - + - + - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -1734,103 +1789,103 @@ - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + diff --git a/pom.xml b/pom.xml index ad35c9ed..888c69b8 100644 --- a/pom.xml +++ b/pom.xml @@ -27,6 +27,70 @@ + 11 + ${java.version} + ${java.version} + true + + 5.5.0 + 3.0.0 + 2.23.4 + 2.9.9 + + + + + org.junit.jupiter + junit-jupiter-api + ${junit.version} + test + + + org.mockito + mockito-core + ${mockito.version} + test + + + com.fasterxml.jackson.core + jackson-annotations + ${jackson.version} + + + com.fasterxml.jackson.module + jackson-module-jaxb-annotations + ${jackson.version} + + + com.fasterxml.jackson.core + jackson-databind + ${jackson.version} + + + + + + + org.mockito + mockito-core + ${mockito.version} + test + + + + org.mockito + mockito-junit-jupiter + ${mockitojupiter.version} + test + + + + org.junit.jupiter + junit-jupiter-engine + ${junit.version} + test + + \ No newline at end of file diff --git a/telegrambots-abilities/pom.xml b/telegrambots-abilities/pom.xml index f8e1194b..04c1d1bc 100644 --- a/telegrambots-abilities/pom.xml +++ b/telegrambots-abilities/pom.xml @@ -3,9 +3,15 @@ xmlns="http://maven.apache.org/POM/4.0.0" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> 4.0.0 - org.telegram + + + org.telegram + Bots + 4.3.1 + + telegrambots-abilities - 4.3.1 + ${project.parent.version} jar Telegram Ability Bot @@ -63,10 +69,15 @@ + 11 + ${java.version} + ${java.version} + UTF-8 UTF-8 - 3.5 - 3.0.4 + + 3.9 + 3.0.7 @@ -91,18 +102,6 @@ - - org.mockito - mockito-all - 2.0.2-beta - test - - - junit - junit - 4.11 - test - @@ -112,10 +111,15 @@ ${project.build.directory}/test-classes ${project.basedir}/src/main/java + + org.apache.maven.plugins + maven-surefire-plugin + 3.0.0-M3 + org.apache.maven.plugins maven-gpg-plugin - 1.5 + 1.6 sign-artifacts @@ -129,7 +133,7 @@ org.sonatype.plugins nexus-staging-maven-plugin - 1.6.3 + 1.6.8 true ossrh @@ -139,7 +143,7 @@ maven-clean-plugin - 3.0.0 + 3.1.0 clean-project @@ -152,7 +156,7 @@ maven-assembly-plugin - 2.6 + 3.1.1 jar-with-dependencies @@ -171,7 +175,7 @@ org.apache.maven.plugins maven-source-plugin - 3.0.0 + 3.1.0 @@ -183,14 +187,14 @@ org.apache.maven.plugins maven-javadoc-plugin - 2.10.3 + 3.1.0 jar - -Xdoclint:none + none @@ -198,7 +202,7 @@ org.jacoco jacoco-maven-plugin - 0.7.7.201606060606 + 0.8.4 @@ -217,7 +221,7 @@ org.apache.maven.plugins maven-enforcer-plugin - 1.4.1 + 3.0.0-M2 enforce-versions @@ -235,7 +239,7 @@ org.apache.maven.plugins maven-dependency-plugin - 2.4 + 3.1.1 copy @@ -249,9 +253,10 @@ org.apache.maven.plugins maven-compiler-plugin + 3.8.1 - 1.8 - 1.8 + ${java.version} + ${java.version} UTF-8 diff --git a/telegrambots-abilities/src/main/java/org/telegram/abilitybots/api/bot/BaseAbilityBot.java b/telegrambots-abilities/src/main/java/org/telegram/abilitybots/api/bot/BaseAbilityBot.java index 301f2eab..529013a4 100644 --- a/telegrambots-abilities/src/main/java/org/telegram/abilitybots/api/bot/BaseAbilityBot.java +++ b/telegrambots-abilities/src/main/java/org/telegram/abilitybots/api/bot/BaseAbilityBot.java @@ -53,7 +53,6 @@ import static java.util.Optional.ofNullable; import static java.util.regex.Pattern.CASE_INSENSITIVE; import static java.util.regex.Pattern.compile; import static java.util.stream.Collectors.joining; -import static jersey.repackaged.com.google.common.base.Throwables.propagate; import static org.apache.commons.lang3.StringUtils.isEmpty; import static org.telegram.abilitybots.api.objects.Ability.builder; import static org.telegram.abilitybots.api.objects.Flag.*; @@ -281,7 +280,7 @@ public abstract class BaseAbilityBot extends DefaultAbsSender implements Ability return getUser(username).getId(); } catch (IllegalStateException ex) { silent.send(getLocalizedMessage(USER_NOT_FOUND, ctx.user().getLanguageCode(), username), ctx.chatId()); - throw propagate(ex); + throw ex; } } @@ -308,12 +307,12 @@ public abstract class BaseAbilityBot extends DefaultAbsSender implements Ability .privacy(CREATOR) .input(0) .action(ctx -> { - String commands = abilities.entrySet().stream() - .filter(entry -> nonNull(entry.getValue().info())) - .map(entry -> { - String name = entry.getValue().name(); - String info = entry.getValue().info(); - return format("%s - %s", name, info); + String commands = abilities.values().stream() + .filter(ability -> nonNull(ability.info())) + .map(ability -> { + String name = ability.name(); + String info = ability.info(); + return format("%s - %s", name, info); }) .sorted() .reduce((a, b) -> format("%s%n%s", a, b)) @@ -350,14 +349,14 @@ public abstract class BaseAbilityBot extends DefaultAbsSender implements Ability .action(ctx -> { Privacy privacy = getPrivacy(ctx.update(), ctx.user().getId()); - ListMultimap abilitiesPerPrivacy = abilities.entrySet().stream() - .map(entry -> { - String name = entry.getValue().name(); - String info = entry.getValue().info(); + ListMultimap abilitiesPerPrivacy = abilities.values().stream() + .map(ability -> { + String name = ability.name(); + String info = ability.info(); - if (!isEmpty(info)) - return Pair.of(entry.getValue().privacy(), format("/%s - %s", name, info)); - return Pair.of(entry.getValue().privacy(), format("/%s", name)); + if (!isEmpty(info)) + return Pair.of(ability.privacy(), format("/%s - %s", name, info)); + return Pair.of(ability.privacy(), format("/%s", name)); }) .sorted(comparing(Pair::b)) .collect(() -> hashKeys().arrayListValues().build(), @@ -652,7 +651,7 @@ public abstract class BaseAbilityBot extends DefaultAbsSender implements Ability .build(); } catch (IllegalStateException e) { BotLogger.error(TAG, "Duplicate names found while registering abilities. Make sure that the abilities declared don't clash with the reserved ones.", e); - throw propagate(e); + throw new RuntimeException(e); } } @@ -676,7 +675,7 @@ public abstract class BaseAbilityBot extends DefaultAbsSender implements Ability return (AbilityExtension) method.invoke(obj); } catch (IllegalAccessException | InvocationTargetException e) { BotLogger.error("Could not add ability extension", TAG, e); - throw propagate(e); + throw new RuntimeException(e); } }; } @@ -693,7 +692,7 @@ public abstract class BaseAbilityBot extends DefaultAbsSender implements Ability return (Ability) method.invoke(obj); } catch (IllegalAccessException | InvocationTargetException e) { BotLogger.error("Could not add ability", TAG, e); - throw propagate(e); + throw new RuntimeException(e); } }; } @@ -710,7 +709,7 @@ public abstract class BaseAbilityBot extends DefaultAbsSender implements Ability return (Reply) method.invoke(obj); } catch (IllegalAccessException | InvocationTargetException e) { BotLogger.error("Could not add reply", TAG, e); - throw propagate(e); + throw new RuntimeException(e); } }; } diff --git a/telegrambots-abilities/src/main/java/org/telegram/abilitybots/api/db/MapDBContext.java b/telegrambots-abilities/src/main/java/org/telegram/abilitybots/api/db/MapDBContext.java index 781d5b87..3af7fa8b 100644 --- a/telegrambots-abilities/src/main/java/org/telegram/abilitybots/api/db/MapDBContext.java +++ b/telegrambots-abilities/src/main/java/org/telegram/abilitybots/api/db/MapDBContext.java @@ -11,17 +11,20 @@ import org.telegram.abilitybots.api.util.Pair; import org.telegram.telegrambots.meta.logging.BotLogger; import java.io.IOException; -import java.util.*; +import java.util.Collection; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Set; +import java.util.StringJoiner; import static com.google.common.collect.Lists.newArrayList; -import static com.google.common.collect.Maps.newHashMap; import static com.google.common.collect.Sets.newHashSet; import static java.lang.String.format; import static java.util.Objects.isNull; import static java.util.stream.Collectors.toMap; import static java.util.stream.StreamSupport.stream; import static org.mapdb.Serializer.JAVA; -import static org.telegram.abilitybots.api.bot.BaseAbilityBot.USERS; /** * An implementation of {@link DBContext} that relies on a {@link DB}. @@ -71,7 +74,6 @@ public class MapDBContext implements DBContext { .fileDB(name) .fileMmapEnableIfSupported() .closeOnJvmShutdown() - .cleanerHackEnable() .transactionEnable() .fileDeleteAfterClose() .make(); 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 index 456a2424..5494c595 100644 --- 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 @@ -1,8 +1,8 @@ package org.telegram.abilitybots.api.bot; -import org.junit.After; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.telegram.abilitybots.api.db.DBContext; import org.telegram.abilitybots.api.objects.MessageContext; import org.telegram.abilitybots.api.sender.MessageSender; @@ -18,7 +18,7 @@ import static org.mockito.internal.verification.VerificationModeFactory.times; import static org.telegram.abilitybots.api.bot.AbilityBotTest.mockContext; import static org.telegram.abilitybots.api.db.MapDBContext.offlineInstance; -public class AbilityBotI18nTest { +class AbilityBotI18nTest { private static final User NO_LANGUAGE_USER = new User(1, "first", false, "last", "username", null); private static final User ITALIAN_USER = new User(2, "first", false, "last", "username", "it-IT"); @@ -28,8 +28,8 @@ public class AbilityBotI18nTest { private MessageSender sender; private SilentSender silent; - @Before - public void setUp() { + @BeforeEach + void setUp() { db = offlineInstance("db"); bot = new NoPublicCommandsBot(EMPTY, EMPTY, db); @@ -38,11 +38,16 @@ public class AbilityBotI18nTest { bot.sender = sender; bot.silent = silent; + } + @AfterEach + void tearDown() throws IOException { + db.clear(); + db.close(); } @Test - public void missingPublicCommandsLocalizedInEnglishByDefault() { + void missingPublicCommandsLocalizedInEnglishByDefault() { MessageContext context = mockContext(NO_LANGUAGE_USER); bot.reportCommands().action().accept(context); @@ -52,7 +57,7 @@ public class AbilityBotI18nTest { } @Test - public void missingPublicCommandsLocalizedInItalian() { + void missingPublicCommandsLocalizedInItalian() { MessageContext context = mockContext(ITALIAN_USER); bot.reportCommands().action().accept(context); @@ -61,15 +66,9 @@ public class AbilityBotI18nTest { .send("Non sono presenti comandi disponibile.", ITALIAN_USER.getId()); } - @After - public void tearDown() throws IOException { - db.clear(); - db.close(); - } - public static class NoPublicCommandsBot extends AbilityBot { - protected NoPublicCommandsBot(String botToken, String botUsername, DBContext db) { + NoPublicCommandsBot(String botToken, String botUsername, DBContext db) { super(botToken, botUsername, db); } diff --git a/telegrambots-abilities/src/test/java/org/telegram/abilitybots/api/bot/AbilityBotTest.java b/telegrambots-abilities/src/test/java/org/telegram/abilitybots/api/bot/AbilityBotTest.java index 7ad96030..49567207 100644 --- a/telegrambots-abilities/src/test/java/org/telegram/abilitybots/api/bot/AbilityBotTest.java +++ b/telegrambots-abilities/src/test/java/org/telegram/abilitybots/api/bot/AbilityBotTest.java @@ -3,9 +3,10 @@ package org.telegram.abilitybots.api.bot; import com.google.common.collect.ImmutableMap; import com.google.common.io.Files; import org.jetbrains.annotations.NotNull; -import org.junit.After; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.telegram.abilitybots.api.db.DBContext; import org.telegram.abilitybots.api.objects.*; import org.telegram.abilitybots.api.sender.MessageSender; @@ -13,7 +14,12 @@ import org.telegram.abilitybots.api.sender.SilentSender; import org.telegram.abilitybots.api.util.Pair; import org.telegram.abilitybots.api.util.Trio; import org.telegram.telegrambots.meta.api.methods.groupadministration.GetChatAdministrators; -import org.telegram.telegrambots.meta.api.objects.*; +import org.telegram.telegrambots.meta.api.objects.ChatMember; +import org.telegram.telegrambots.meta.api.objects.Document; +import org.telegram.telegrambots.meta.api.objects.File; +import org.telegram.telegrambots.meta.api.objects.Message; +import org.telegram.telegrambots.meta.api.objects.Update; +import org.telegram.telegrambots.meta.api.objects.User; import org.telegram.telegrambots.meta.exceptions.TelegramApiException; import java.io.BufferedWriter; @@ -32,9 +38,13 @@ import static java.util.Optional.empty; import static org.apache.commons.io.FileUtils.deleteQuietly; import static org.apache.commons.lang3.ArrayUtils.addAll; import static org.apache.commons.lang3.StringUtils.EMPTY; -import static org.junit.Assert.*; -import static org.mockito.Matchers.any; -import static org.mockito.Mockito.*; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.mockito.Mockito.any; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; import static org.mockito.internal.verification.VerificationModeFactory.times; import static org.telegram.abilitybots.api.bot.DefaultBot.getDefaultBuilder; import static org.telegram.abilitybots.api.db.MapDBContext.offlineInstance; @@ -62,8 +72,8 @@ public class AbilityBotTest { private MessageSender sender; private SilentSender silent; - @Before - public void setUp() { + @BeforeEach + void setUp() { db = offlineInstance("db"); bot = new DefaultBot(EMPTY, EMPTY, db); @@ -74,8 +84,14 @@ public class AbilityBotTest { bot.silent = silent; } + @AfterEach + void tearDown() throws IOException { + db.clear(); + db.close(); + } + @Test - public void sendsPrivacyViolation() { + void sendsPrivacyViolation() { Update update = mockFullUpdate(USER, "/admin"); bot.onUpdateReceived(update); @@ -84,7 +100,7 @@ public class AbilityBotTest { } @Test - public void sendsLocalityViolation() { + void sendsLocalityViolation() { Update update = mockFullUpdate(USER, "/group"); bot.onUpdateReceived(update); @@ -94,7 +110,7 @@ public class AbilityBotTest { } @Test - public void sendsInputArgsViolation() { + void sendsInputArgsViolation() { Update update = mockFullUpdate(USER, "/count 1 2 3"); bot.onUpdateReceived(update); @@ -103,7 +119,7 @@ public class AbilityBotTest { } @Test - public void canProcessRepliesIfSatisfyRequirements() { + void canProcessRepliesIfSatisfyRequirements() { Update update = mockFullUpdate(USER, "must reply"); // False means the update was not pushed down the stream since it has been consumed by the reply @@ -112,7 +128,7 @@ public class AbilityBotTest { } @Test - public void canBackupDB() throws TelegramApiException { + void canBackupDB() throws TelegramApiException { MessageContext context = defaultContext(); bot.backupDB().action().accept(context); @@ -122,7 +138,7 @@ public class AbilityBotTest { } @Test - public void canRecoverDB() throws TelegramApiException, IOException { + void canRecoverDB() throws TelegramApiException, IOException { Update update = mockBackupUpdate(); Object backup = getDbBackup(); java.io.File backupFile = createBackupFile(backup); @@ -131,12 +147,12 @@ public class AbilityBotTest { bot.recoverDB().replies().get(0).actOn(update); verify(silent, times(1)).send(RECOVER_SUCCESS, GROUP_ID); - assertEquals("Bot recovered but the DB is still not in sync", db.getSet(TEST), newHashSet(TEST)); - assertTrue("Could not delete backup file", backupFile.delete()); + assertEquals(db.getSet(TEST), newHashSet(TEST), "Bot recovered but the DB is still not in sync"); + assertTrue(backupFile.delete(), "Could not delete backup file"); } @Test - public void canFilterOutReplies() { + void canFilterOutReplies() { Update update = mock(Update.class); when(update.hasMessage()).thenReturn(false); @@ -144,7 +160,7 @@ public class AbilityBotTest { } @Test - public void canDemote() { + void canDemote() { addUsers(USER); bot.admins().add(USER.getId()); @@ -154,11 +170,11 @@ public class AbilityBotTest { Set actual = bot.admins(); Set expected = emptySet(); - assertEquals("Could not sudont super-admin", expected, actual); + assertEquals(expected, actual, "Could not sudont super-admin"); } @Test - public void canPromote() { + void canPromote() { addUsers(USER); MessageContext context = defaultContext(); @@ -167,11 +183,11 @@ public class AbilityBotTest { Set actual = bot.admins(); Set expected = newHashSet(USER.getId()); - assertEquals("Could not sudo user", expected, actual); + assertEquals(expected, actual, "Could not sudo user"); } @Test - public void canBanUser() { + void canBanUser() { addUsers(USER); MessageContext context = defaultContext(); @@ -179,11 +195,11 @@ public class AbilityBotTest { Set actual = bot.blacklist(); Set expected = newHashSet(USER.getId()); - assertEquals("The ban was not emplaced", expected, actual); + assertEquals(expected, actual, "The ban was not emplaced"); } @Test - public void canUnbanUser() { + void canUnbanUser() { addUsers(USER); bot.blacklist().add(USER.getId()); @@ -193,7 +209,7 @@ public class AbilityBotTest { Set actual = bot.blacklist(); Set expected = newHashSet(); - assertEquals("The ban was not lifted", expected, actual); + assertEquals(expected, actual, "The ban was not lifted"); } @NotNull @@ -202,7 +218,7 @@ public class AbilityBotTest { } @Test - public void cannotBanCreator() { + void cannotBanCreator() { addUsers(USER, CREATOR); MessageContext context = mockContext(USER, GROUP_ID, CREATOR.getUserName()); @@ -210,7 +226,7 @@ public class AbilityBotTest { Set actual = bot.blacklist(); Set expected = newHashSet(USER.getId()); - assertEquals("Impostor was not added to the blacklist", expected, actual); + assertEquals(expected, actual, "Impostor was not added to the blacklist"); } private void addUsers(User... users) { @@ -221,18 +237,18 @@ public class AbilityBotTest { } @Test - public void creatorCanClaimBot() { + void creatorCanClaimBot() { MessageContext context = mockContext(CREATOR, GROUP_ID); bot.claimCreator().action().accept(context); Set actual = bot.admins(); Set expected = newHashSet(CREATOR.getId()); - assertEquals("Creator was not properly added to the super admins set", expected, actual); + assertEquals(expected, actual, "Creator was not properly added to the super admins set"); } @Test - public void bannedCreatorPassesBlacklistCheck() { + void bannedCreatorPassesBlacklistCheck() { bot.blacklist().add(CREATOR.getId()); Update update = mock(Update.class); Message message = mock(Message.class); @@ -241,11 +257,11 @@ public class AbilityBotTest { mockUser(update, message, user); boolean notBanned = bot.checkBlacklist(update); - assertTrue("Creator is banned", notBanned); + assertTrue(notBanned, "Creator is banned"); } @Test - public void canAddUser() { + void canAddUser() { Update update = mock(Update.class); Message message = mock(Message.class); @@ -255,12 +271,12 @@ public class AbilityBotTest { Map expectedUserIds = ImmutableMap.of(USER.getUserName(), USER.getId()); Map expectedUsers = ImmutableMap.of(USER.getId(), USER); - assertEquals("User was not added", expectedUserIds, bot.userIds()); - assertEquals("User was not added", expectedUsers, bot.users()); + assertEquals(expectedUserIds, bot.userIds(), "User was not added"); + assertEquals(expectedUsers, bot.users(), "User was not added"); } @Test - public void canEditUser() { + void canEditUser() { addUsers(USER); Update update = mock(Update.class); Message message = mock(Message.class); @@ -277,22 +293,22 @@ public class AbilityBotTest { Map expectedUserIds = ImmutableMap.of(changedUser.getUserName(), changedUser.getId()); Map expectedUsers = ImmutableMap.of(changedUser.getId(), changedUser); - assertEquals("User was not properly edited", bot.userIds(), expectedUserIds); - assertEquals("User was not properly edited", expectedUsers, expectedUsers); + assertEquals(bot.userIds(), expectedUserIds, "User was not properly edited"); + assertEquals(expectedUsers, expectedUsers, "User was not properly edited"); } @Test - public void canValidateAbility() { + void canValidateAbility() { Trio invalidPair = Trio.of(null, null, null); Ability validAbility = getDefaultBuilder().build(); Trio validPair = Trio.of(null, validAbility, null); - assertFalse("Bot can't validate ability properly", bot.validateAbility(invalidPair)); - assertTrue("Bot can't validate ability properly", bot.validateAbility(validPair)); + assertFalse(bot.validateAbility(invalidPair), "Bot can't validate ability properly"); + assertTrue(bot.validateAbility(validPair), "Bot can't validate ability properly"); } @Test - public void canCheckInput() { + void canCheckInput() { Update update = mockFullUpdate(USER, "/something"); Ability abilityWithOneInput = getDefaultBuilder() .build(); @@ -303,19 +319,19 @@ public class AbilityBotTest { Trio trioOneArg = Trio.of(update, abilityWithOneInput, TEXT); Trio trioZeroArg = Trio.of(update, abilityWithZeroInput, TEXT); - assertTrue("Unexpected result when applying token filter", bot.checkInput(trioOneArg)); + assertTrue(bot.checkInput(trioOneArg), "Unexpected result when applying token filter"); trioOneArg = Trio.of(update, abilityWithOneInput, addAll(TEXT, TEXT)); - assertFalse("Unexpected result when applying token filter", bot.checkInput(trioOneArg)); + assertFalse(bot.checkInput(trioOneArg), "Unexpected result when applying token filter"); - assertTrue("Unexpected result when applying token filter", bot.checkInput(trioZeroArg)); + assertTrue(bot.checkInput(trioZeroArg), "Unexpected result when applying token filter"); trioZeroArg = Trio.of(update, abilityWithZeroInput, EMPTY_ARRAY); - assertTrue("Unexpected result when applying token filter", bot.checkInput(trioZeroArg)); + assertTrue(bot.checkInput(trioZeroArg), "Unexpected result when applying token filter"); } @Test - public void canCheckPrivacy() { + void canCheckPrivacy() { Update update = mock(Update.class); Message message = mock(Message.class); User user = mock(User.class); @@ -331,14 +347,14 @@ public class AbilityBotTest { mockUser(update, message, user); - assertTrue("Unexpected result when checking for privacy", bot.checkPrivacy(publicTrio)); - assertFalse("Unexpected result when checking for privacy", bot.checkPrivacy(groupAdminTrio)); - assertFalse("Unexpected result when checking for privacy", bot.checkPrivacy(adminTrio)); - assertFalse("Unexpected result when checking for privacy", bot.checkPrivacy(creatorTrio)); + assertTrue(bot.checkPrivacy(publicTrio), "Unexpected result when checking for privacy"); + assertFalse(bot.checkPrivacy(groupAdminTrio), "Unexpected result when checking for privacy"); + assertFalse(bot.checkPrivacy(adminTrio), "Unexpected result when checking for privacy"); + assertFalse(bot.checkPrivacy(creatorTrio), "Unexpected result when checking for privacy"); } @Test - public void canValidateGroupAdminPrivacy() { + void canValidateGroupAdminPrivacy() { Update update = mock(Update.class); Message message = mock(Message.class); User user = mock(User.class); @@ -355,11 +371,11 @@ public class AbilityBotTest { when(silent.execute(any(GetChatAdministrators.class))).thenReturn(Optional.of(newArrayList(member))); - assertTrue("Unexpected result when checking for privacy", bot.checkPrivacy(groupAdminTrio)); + assertTrue(bot.checkPrivacy(groupAdminTrio), "Unexpected result when checking for privacy"); } @Test - public void canRestrictNormalUsersFromGroupAdminAbilities() { + void canRestrictNormalUsersFromGroupAdminAbilities() { Update update = mock(Update.class); Message message = mock(Message.class); User user = mock(User.class); @@ -372,11 +388,11 @@ public class AbilityBotTest { when(silent.execute(any(GetChatAdministrators.class))).thenReturn(empty()); - assertFalse("Unexpected result when checking for privacy", bot.checkPrivacy(groupAdminTrio)); + assertFalse(bot.checkPrivacy(groupAdminTrio), "Unexpected result when checking for privacy"); } @Test - public void canBlockAdminsFromCreatorAbilities() { + void canBlockAdminsFromCreatorAbilities() { Update update = mock(Update.class); Message message = mock(Message.class); User user = mock(User.class); @@ -387,11 +403,11 @@ public class AbilityBotTest { bot.admins().add(USER.getId()); mockUser(update, message, user); - assertFalse("Unexpected result when checking for privacy", bot.checkPrivacy(creatorTrio)); + assertFalse(bot.checkPrivacy(creatorTrio), "Unexpected result when checking for privacy"); } @Test - public void canCheckLocality() { + void canCheckLocality() { Update update = mock(Update.class); Message message = mock(Message.class); User user = mock(User.class); @@ -406,13 +422,13 @@ public class AbilityBotTest { mockUser(update, message, user); when(message.isUserMessage()).thenReturn(true); - assertTrue("Unexpected result when checking for locality", bot.checkLocality(publicTrio)); - assertTrue("Unexpected result when checking for locality", bot.checkLocality(userTrio)); - assertFalse("Unexpected result when checking for locality", bot.checkLocality(groupTrio)); + assertTrue(bot.checkLocality(publicTrio), "Unexpected result when checking for locality"); + assertTrue(bot.checkLocality(userTrio), "Unexpected result when checking for locality"); + assertFalse(bot.checkLocality(groupTrio), "Unexpected result when checking for locality"); } @Test - public void canRetrieveContext() { + void canRetrieveContext() { Update update = mock(Update.class); Message message = mock(Message.class); Ability ability = getDefaultBuilder().build(); @@ -424,17 +440,17 @@ public class AbilityBotTest { Pair actualPair = bot.getContext(trio); Pair expectedPair = Pair.of(newContext(update, USER, GROUP_ID, TEXT), ability); - assertEquals("Unexpected result when fetching for context", expectedPair, actualPair); + assertEquals(expectedPair, actualPair, "Unexpected result when fetching for context"); } @Test - public void defaultGlobalFlagIsTrue() { + void defaultGlobalFlagIsTrue() { Update update = mock(Update.class); - assertTrue("Unexpected result when checking for the default global flags", bot.checkGlobalFlags(update)); + assertTrue(bot.checkGlobalFlags(update), "Unexpected result when checking for the default global flags"); } - @Test(expected = ArithmeticException.class) - public void canConsumeUpdate() { + @Test + void canConsumeUpdate() { Ability ability = getDefaultBuilder() .action((context) -> { int x = 1 / 0; @@ -443,11 +459,13 @@ public class AbilityBotTest { Pair pair = Pair.of(context, ability); - bot.consumeUpdate(pair); + Assertions.assertThrows(ArithmeticException.class, () -> { + bot.consumeUpdate(pair); + }); } @Test - public void canFetchAbility() { + void canFetchAbility() { Update update = mock(Update.class); Message message = mock(Message.class); @@ -462,11 +480,11 @@ public class AbilityBotTest { Ability expected = bot.testAbility(); Ability actual = trio.b(); - assertEquals("Wrong ability was fetched", expected, actual); + assertEquals(expected, actual, "Wrong ability was fetched"); } @Test - public void canFetchAbilityCaseInsensitive() { + void canFetchAbilityCaseInsensitive() { Update update = mock(Update.class); Message message = mock(Message.class); @@ -481,11 +499,11 @@ public class AbilityBotTest { Ability expected = bot.testAbility(); Ability actual = trio.b(); - assertEquals("Wrong ability was fetched", expected, actual); + assertEquals(expected, actual, "Wrong ability was fetched"); } @Test - public void canFetchDefaultAbility() { + void canFetchDefaultAbility() { Update update = mock(Update.class); Message message = mock(Message.class); @@ -498,11 +516,11 @@ public class AbilityBotTest { Ability expected = bot.defaultAbility(); Ability actual = trio.b(); - assertEquals("Wrong ability was fetched", expected, actual); + assertEquals(expected, actual, "Wrong ability was fetched"); } @Test - public void canCheckAbilityFlags() { + void canCheckAbilityFlags() { Update update = mock(Update.class); Message message = mock(Message.class); @@ -517,12 +535,12 @@ public class AbilityBotTest { Trio docTrio = Trio.of(update, documentAbility, TEXT); Trio textTrio = Trio.of(update, textAbility, TEXT); - assertFalse("Unexpected result when checking for message flags", bot.checkMessageFlags(docTrio)); - assertTrue("Unexpected result when checking for message flags", bot.checkMessageFlags(textTrio)); + assertFalse(bot.checkMessageFlags(docTrio), "Unexpected result when checking for message flags"); + assertTrue(bot.checkMessageFlags(textTrio), "Unexpected result when checking for message flags"); } @Test - public void canReportCommands() { + void canReportCommands() { MessageContext context = mockContext(USER, GROUP_ID); bot.reportCommands().action().accept(context); @@ -531,12 +549,12 @@ public class AbilityBotTest { } @NotNull - public static MessageContext mockContext(User user) { + static MessageContext mockContext(User user) { return mockContext(user, user.getId()); } @NotNull - public static MessageContext mockContext(User user, long groupId, String... args) { + static MessageContext mockContext(User user, long groupId, String... args) { Update update = mock(Update.class); Message message = mock(Message.class); @@ -550,7 +568,7 @@ public class AbilityBotTest { } @Test - public void canPrintCommandsBasedOnPrivacy() { + void canPrintCommandsBasedOnPrivacy() { Update update = mock(Update.class); Message message = mock(Message.class); @@ -566,7 +584,7 @@ public class AbilityBotTest { } @Test - public void printsOnlyPublicCommandsForNormalUser() { + void printsOnlyPublicCommandsForNormalUser() { Update update = mock(Update.class); Message message = mock(Message.class); @@ -582,12 +600,6 @@ public class AbilityBotTest { verify(silent, times(1)).send(expected, GROUP_ID); } - @After - public void tearDown() throws IOException { - db.clear(); - db.close(); - } - @NotNull private Update mockFullUpdate(User user, String args) { bot.users().put(USER.getId(), USER); diff --git a/telegrambots-abilities/src/test/java/org/telegram/abilitybots/api/bot/ExtensionTest.java b/telegrambots-abilities/src/test/java/org/telegram/abilitybots/api/bot/ExtensionTest.java index 43bb8da5..8be53c13 100644 --- a/telegrambots-abilities/src/test/java/org/telegram/abilitybots/api/bot/ExtensionTest.java +++ b/telegrambots-abilities/src/test/java/org/telegram/abilitybots/api/bot/ExtensionTest.java @@ -1,45 +1,45 @@ package org.telegram.abilitybots.api.bot; -import org.junit.After; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.telegram.abilitybots.api.objects.Ability; import org.telegram.abilitybots.api.util.AbilityExtension; import java.io.IOException; -import static junit.framework.TestCase.assertTrue; +import static org.junit.jupiter.api.Assertions.assertTrue; import static org.telegram.abilitybots.api.db.MapDBContext.offlineInstance; import static org.telegram.abilitybots.api.objects.Locality.ALL; import static org.telegram.abilitybots.api.objects.Privacy.PUBLIC; -public class ExtensionTest { +class ExtensionTest { private ExtensionUsingBot bot; - @Before - public void setUp() { + @BeforeEach + void setUp() { bot = new ExtensionUsingBot(); } - @Test - public void methodReturningAbilities() { - assertTrue("Failed to find Ability in directly declared in root extension/bot", hasAbilityNamed("direct")); - assertTrue("Failed to find Ability in directly declared in extension returned by method returning the AbilityExtension class", hasAbilityNamed("returningSuperClass0abc")); - assertTrue("Failed to find Ability in directly declared in extension returned by method returning the AbilityExtension subclass", hasAbilityNamed("returningSubClass0abc")); - } - - @After - public void tearDown() throws IOException { + @AfterEach + void tearDown() throws IOException { bot.db.clear(); bot.db.close(); } + @Test + void methodReturningAbilities() { + assertTrue(hasAbilityNamed("direct"), "Failed to find Ability in directly declared in root extension/bot"); + assertTrue(hasAbilityNamed("returningSuperClass0abc"), "Failed to find Ability in directly declared in extension returned by method returning the AbilityExtension class"); + assertTrue(hasAbilityNamed("returningSubClass0abc"), "Failed to find Ability in directly declared in extension returned by method returning the AbilityExtension subclass"); + } + private boolean hasAbilityNamed(String name) { return bot.abilities().values().stream().map(Ability::name).anyMatch(name::equals); } public static class ExtensionUsingBot extends AbilityBot { - public ExtensionUsingBot() { + ExtensionUsingBot() { super("", "", offlineInstance("testing")); } @@ -71,7 +71,7 @@ public class ExtensionTest { public static class AbilityBotExtension implements AbilityExtension { private String name; - public AbilityBotExtension(String name) { + AbilityBotExtension(String name) { this.name = name; } diff --git a/telegrambots-abilities/src/test/java/org/telegram/abilitybots/api/db/MapDBContextTest.java b/telegrambots-abilities/src/test/java/org/telegram/abilitybots/api/db/MapDBContextTest.java index 5a835e77..ff8f55c6 100644 --- a/telegrambots-abilities/src/test/java/org/telegram/abilitybots/api/db/MapDBContextTest.java +++ b/telegrambots-abilities/src/test/java/org/telegram/abilitybots/api/db/MapDBContextTest.java @@ -1,8 +1,9 @@ package org.telegram.abilitybots.api.db; -import org.junit.After; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.telegram.telegrambots.meta.api.objects.User; import java.io.IOException; @@ -12,25 +13,33 @@ import java.util.Set; import static com.google.common.collect.Maps.newHashMap; import static com.google.common.collect.Sets.newHashSet; import static java.lang.String.format; -import static org.junit.Assert.*; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertTrue; import static org.telegram.abilitybots.api.bot.AbilityBotTest.CREATOR; import static org.telegram.abilitybots.api.bot.AbilityBotTest.USER; import static org.telegram.abilitybots.api.db.MapDBContext.offlineInstance; -public class MapDBContextTest { +class MapDBContextTest { private static final String USERS = "USERS"; private static final String USER_ID = "USER_ID"; private static final String TEST = "TEST"; private DBContext db; - @Before - public void setUp() { + @BeforeEach + void setUp() { db = offlineInstance("db"); } + @AfterEach + void tearDown() throws IOException { + db.clear(); + db.close(); + } + @Test - public void canRecoverDB() { + void canRecoverDB() { Map users = db.getMap(USERS); Map userIds = db.getMap(USER_ID); users.put(CREATOR.getId(), CREATOR); @@ -49,30 +58,30 @@ public class MapDBContextTest { Map recoveredUsers = db.getMap(USERS); String afterRecoveryInfo = db.info(USERS); - assertTrue("Could not recover database successfully", recovered); - assertEquals("Map info before and after recovery is different", beforeBackupInfo, afterRecoveryInfo); - assertEquals("Map before and after recovery are not equal", originalUsers, recoveredUsers); + assertTrue(recovered, "Could not recover database successfully"); + assertEquals(beforeBackupInfo, afterRecoveryInfo, "Map info before and after recovery is different"); + assertEquals(originalUsers, recoveredUsers, "Map before and after recovery are not equal"); } @Test - public void canFallbackDBIfRecoveryFails() { + void canFallbackDBIfRecoveryFails() { Set users = db.getSet(USERS); users.add(CREATOR); users.add(USER); Set originalSet = newHashSet(users); Object jsonBackup = db.backup(); - String corruptBackup = "!@#$" + String.valueOf(jsonBackup); + String corruptBackup = "!@#$" + jsonBackup; boolean recovered = db.recover(corruptBackup); Set recoveredSet = db.getSet(USERS); - assertFalse("Recovery was successful from a CORRUPT backup", recovered); - assertEquals("Set before and after corrupt recovery are not equal", originalSet, recoveredSet); + assertFalse(recovered, "Recovery was successful from a CORRUPT backup"); + assertEquals(originalSet, recoveredSet, "Set before and after corrupt recovery are not equal"); } @Test - public void canGetSummary() { + void canGetSummary() { String anotherTest = TEST + 1; db.getSet(TEST).add(TEST); db.getSet(anotherTest).add(anotherTest); @@ -85,7 +94,7 @@ public class MapDBContextTest { } @Test - public void canGetInfo() { + void canGetInfo() { db.getSet(TEST).add(TEST); String actualInfo = db.info(TEST); @@ -95,13 +104,13 @@ public class MapDBContextTest { assertEquals("Actual DB structure info does not match that of the expected", expectedInfo, actualInfo); } - @Test(expected = IllegalStateException.class) - public void cantGetInfoFromNonexistentDBStructureName() { - db.info(TEST); + @Test + void cantGetInfoFromNonexistentDBStructureName() { + Assertions.assertThrows(IllegalStateException.class, () -> db.info(TEST)); } @Test - public void canGetAndSetVariables() { + void canGetAndSetVariables() { String varName = "somevar"; Var var = db.getVar(varName); var.set(CREATOR); @@ -116,10 +125,4 @@ public class MapDBContextTest { Var changedVar = db.getVar(varName); assertEquals(changedVar.get(), USER); } - - @After - public void tearDown() throws IOException { - db.clear(); - db.close(); - } } diff --git a/telegrambots-abilities/src/test/java/org/telegram/abilitybots/api/objects/AbilityTest.java b/telegrambots-abilities/src/test/java/org/telegram/abilitybots/api/objects/AbilityTest.java index 5778dab3..0b97ed01 100644 --- a/telegrambots-abilities/src/test/java/org/telegram/abilitybots/api/objects/AbilityTest.java +++ b/telegrambots-abilities/src/test/java/org/telegram/abilitybots/api/objects/AbilityTest.java @@ -1,58 +1,73 @@ package org.telegram.abilitybots.api.objects; -import org.junit.Test; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotEquals; import static org.telegram.abilitybots.api.bot.DefaultBot.getDefaultBuilder; -public class AbilityTest { - @Test(expected = IllegalArgumentException.class) - public void argumentsCannotBeNegative() { - getDefaultBuilder().input(-4).build(); - } - - @Test(expected = IllegalArgumentException.class) - public void nameCannotBeEmpty() { - getDefaultBuilder().name("").build(); - } - - @Test(expected = IllegalArgumentException.class) - public void nameCannotBeNull() { - getDefaultBuilder().name(null).build(); - } - - @Test(expected = NullPointerException.class) - public void consumerCannotBeNull() { - getDefaultBuilder().action(null).build(); - } - - @Test(expected = NullPointerException.class) - public void localityCannotBeNull() { - getDefaultBuilder().locality(null).build(); - } - - @Test(expected = NullPointerException.class) - public void privacyCannotBeNull() { - getDefaultBuilder().privacy(null).build(); - } - - @Test(expected = IllegalArgumentException.class) - public void nameCannotContainSpaces() { - getDefaultBuilder().name("test test").build(); +class AbilityTest { + @Test + void argumentsCannotBeNegative() { + Assertions.assertThrows(IllegalArgumentException.class, () -> { + getDefaultBuilder().input(-4).build(); + }); } @Test - public void abilityEqualsMethod() { + void nameCannotBeEmpty() { + Assertions.assertThrows(IllegalArgumentException.class, () -> { + getDefaultBuilder().name("").build(); + }); + } + + @Test + void nameCannotBeNull() { + Assertions.assertThrows(IllegalArgumentException.class, () -> { + getDefaultBuilder().name(null).build(); + }); + } + + @Test + void consumerCannotBeNull() { + Assertions.assertThrows(NullPointerException.class, () -> { + getDefaultBuilder().action(null).build(); + }); + } + + @Test + void localityCannotBeNull() { + Assertions.assertThrows(NullPointerException.class, () -> { + getDefaultBuilder().locality(null).build(); + }); + } + + @Test + void privacyCannotBeNull() { + Assertions.assertThrows(NullPointerException.class, () -> { + getDefaultBuilder().privacy(null).build(); + }); + } + + @Test + void nameCannotContainSpaces() { + Assertions.assertThrows(IllegalArgumentException.class, () -> { + getDefaultBuilder().name("test test").build(); + }); + } + + @Test + void abilityEqualsMethod() { Ability ability1 = getDefaultBuilder().build(); Ability ability2 = getDefaultBuilder().build(); Ability ability3 = getDefaultBuilder().name("anotherconsumer").build(); Ability ability4 = getDefaultBuilder().action((context) -> { }).build(); - assertEquals("Abilities should not be equal", ability1, ability2); - assertEquals("Abilities should not be equal", ability1, ability4); - assertNotEquals("Abilities should be equal", ability1, ability3); + assertEquals(ability1, ability2, "Abilities should not be equal"); + assertEquals(ability1, ability4, "Abilities should not be equal"); + assertNotEquals(ability1, ability3, "Abilities should be equal"); } } diff --git a/telegrambots-abilities/src/test/java/org/telegram/abilitybots/api/sender/SilentSenderTest.java b/telegrambots-abilities/src/test/java/org/telegram/abilitybots/api/sender/SilentSenderTest.java index 3b33ab36..96da662c 100644 --- a/telegrambots-abilities/src/test/java/org/telegram/abilitybots/api/sender/SilentSenderTest.java +++ b/telegrambots-abilities/src/test/java/org/telegram/abilitybots/api/sender/SilentSenderTest.java @@ -1,43 +1,43 @@ package org.telegram.abilitybots.api.sender; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.telegram.telegrambots.meta.exceptions.TelegramApiException; import java.util.Optional; -import static junit.framework.TestCase.assertEquals; -import static junit.framework.TestCase.assertFalse; -import static org.mockito.Matchers.any; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; -public class SilentSenderTest { +class SilentSenderTest { private SilentSender silent; private MessageSender sender; - @Before - public void setUp() { + @BeforeEach + void setUp() { sender = mock(MessageSender.class); silent = new SilentSender(sender); } @Test - public void returnsEmptyOnError() throws TelegramApiException { + void returnsEmptyOnError() throws TelegramApiException { when(sender.execute(any())).thenThrow(TelegramApiException.class); Optional execute = silent.execute(null); - assertFalse("Execution of a bot API method with execption results in a nonempty optional", execute.isPresent()); + assertFalse(execute.isPresent(), "Execution of a bot API method with execption results in a nonempty optional"); } @Test - public void returnOptionalOnSuccess() throws TelegramApiException { + void returnOptionalOnSuccess() throws TelegramApiException { String data = "data"; when(sender.execute(any())).thenReturn(data); Optional execute = silent.execute(null); - assertEquals("Silent execution resulted in a different object", data, execute.get()); + assertEquals(data, execute.get(), "Silent execution resulted in a different object"); } } \ No newline at end of file diff --git a/telegrambots-chat-session-bot/pom.xml b/telegrambots-chat-session-bot/pom.xml index 058b2f00..b578a82f 100644 --- a/telegrambots-chat-session-bot/pom.xml +++ b/telegrambots-chat-session-bot/pom.xml @@ -3,9 +3,15 @@ xmlns="http://maven.apache.org/POM/4.0.0" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> 4.0.0 - org.telegram + + + org.telegram + Bots + 4.3.1 + + telegrambots-chat-session-bot - 4.3.1 + ${project.parent.version} jar Telegram Bots Chat Session Bot @@ -63,9 +69,14 @@ + 11 + ${java.version} + ${java.version} + UTF-8 UTF-8 - 1.4.0 + + 1.4.1 @@ -82,19 +93,6 @@ shiro-core ${shiro.version} - - - org.mockito - mockito-all - 2.0.2-beta - test - - - junit - junit - 4.11 - test - @@ -104,10 +102,15 @@ ${project.build.directory}/test-classes ${project.basedir}/src/main/java + + org.apache.maven.plugins + maven-surefire-plugin + 3.0.0-M3 + org.apache.maven.plugins maven-gpg-plugin - 1.5 + 1.6 sign-artifacts @@ -121,7 +124,7 @@ org.sonatype.plugins nexus-staging-maven-plugin - 1.6.3 + 1.6.8 true ossrh @@ -131,7 +134,7 @@ maven-clean-plugin - 3.0.0 + 3.1.0 clean-project @@ -144,7 +147,7 @@ maven-assembly-plugin - 2.6 + 3.1.1 jar-with-dependencies @@ -163,7 +166,7 @@ org.apache.maven.plugins maven-source-plugin - 3.0.0 + 3.1.0 @@ -175,14 +178,14 @@ org.apache.maven.plugins maven-javadoc-plugin - 2.10.3 + 3.1.0 jar - -Xdoclint:none + none @@ -190,7 +193,7 @@ org.jacoco jacoco-maven-plugin - 0.7.7.201606060606 + 0.8.4 @@ -209,7 +212,7 @@ org.apache.maven.plugins maven-enforcer-plugin - 1.4.1 + 3.0.0-M2 enforce-versions @@ -227,7 +230,7 @@ org.apache.maven.plugins maven-dependency-plugin - 2.4 + 3.1.1 copy @@ -241,9 +244,10 @@ org.apache.maven.plugins maven-compiler-plugin + 3.8.1 - 1.8 - 1.8 + ${java.version} + ${java.version} UTF-8 diff --git a/telegrambots-extensions/pom.xml b/telegrambots-extensions/pom.xml index 92863d35..d2dce980 100644 --- a/telegrambots-extensions/pom.xml +++ b/telegrambots-extensions/pom.xml @@ -3,9 +3,15 @@ xmlns="http://maven.apache.org/POM/4.0.0" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> 4.0.0 - org.telegram + + + org.telegram + Bots + 4.3.1 + + telegrambotsextensions - 4.3.1 + ${project.parent.version} jar Telegram Bots Extensions @@ -57,6 +63,10 @@ + 11 + ${java.version} + ${java.version} + UTF-8 UTF-8 @@ -76,10 +86,15 @@ ${project.build.directory}/test-classes ${project.basedir}/src/main/java + + org.apache.maven.plugins + maven-surefire-plugin + 3.0.0-M3 + org.apache.maven.plugins maven-gpg-plugin - 1.5 + 1.6 sign-artifacts @@ -93,7 +108,7 @@ org.sonatype.plugins nexus-staging-maven-plugin - 1.6.3 + 1.6.8 true ossrh @@ -103,7 +118,7 @@ maven-clean-plugin - 3.0.0 + 3.1.0 clean-project @@ -116,7 +131,7 @@ maven-assembly-plugin - 2.6 + 3.1.1 jar-with-dependencies @@ -135,7 +150,7 @@ org.apache.maven.plugins maven-source-plugin - 3.0.0 + 3.1.0 @@ -147,14 +162,14 @@ org.apache.maven.plugins maven-javadoc-plugin - 2.10.3 + 3.1.0 jar - -Xdoclint:none + none @@ -162,7 +177,7 @@ org.jacoco jacoco-maven-plugin - 0.7.7.201606060606 + 0.8.4 @@ -181,7 +196,7 @@ org.apache.maven.plugins maven-enforcer-plugin - 1.4.1 + 3.0.0-M2 enforce-versions @@ -199,7 +214,7 @@ org.apache.maven.plugins maven-dependency-plugin - 2.4 + 3.1.1 copy @@ -213,9 +228,10 @@ org.apache.maven.plugins maven-compiler-plugin + 3.8.1 - 1.8 - 1.8 + ${java.version} + ${java.version} UTF-8 diff --git a/telegrambots-meta/pom.xml b/telegrambots-meta/pom.xml index 5162dd71..e90b44dc 100644 --- a/telegrambots-meta/pom.xml +++ b/telegrambots-meta/pom.xml @@ -3,9 +3,15 @@ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> 4.0.0 - org.telegram + + + org.telegram + Bots + 4.3.1 + + telegrambots-meta - 4.3.1 + ${project.parent.version} jar Telegram Bots Meta @@ -57,14 +63,17 @@ + 11 + ${java.version} + ${java.version} + UTF-8 UTF-8 4.2.2 2.9.9 - 2.9.0 + 2.9.9 20180813 - 4.12 - 25.1-jre + 28.0-jre @@ -105,12 +114,6 @@ json ${json.version} - - junit - junit - ${junit.version} - test - @@ -123,7 +126,7 @@ org.apache.maven.plugins maven-gpg-plugin - 1.5 + 1.6 sign-artifacts @@ -137,7 +140,7 @@ org.sonatype.plugins nexus-staging-maven-plugin - 1.6.3 + 1.6.8 true ossrh @@ -147,7 +150,7 @@ maven-clean-plugin - 3.0.0 + 3.1.0 clean-project @@ -160,7 +163,7 @@ maven-assembly-plugin - 2.6 + 3.1.1 jar-with-dependencies @@ -179,7 +182,7 @@ org.apache.maven.plugins maven-source-plugin - 3.0.0 + 3.1.0 @@ -191,14 +194,14 @@ org.apache.maven.plugins maven-javadoc-plugin - 2.10.3 + 3.1.0 jar - -Xdoclint:none + none @@ -206,7 +209,7 @@ org.jacoco jacoco-maven-plugin - 0.7.7.201606060606 + 0.8.4 @@ -225,7 +228,7 @@ org.apache.maven.plugins maven-enforcer-plugin - 1.4.1 + 3.0.0-M2 enforce @@ -243,7 +246,7 @@ org.apache.maven.plugins maven-dependency-plugin - 2.4 + 3.1.1 copy @@ -251,15 +254,21 @@ + + org.apache.maven.plugins + maven-surefire-plugin + 3.0.0-M3 + org.apache.maven.plugins maven-compiler-plugin + 3.8.1 - 1.8 - 1.8 + ${java.version} + ${java.version} UTF-8 diff --git a/telegrambots-meta/src/test/java/org/telegram/telegrambots/meta/api/methods/send/SendMessageTest.java b/telegrambots-meta/src/test/java/org/telegram/telegrambots/meta/api/methods/send/SendMessageTest.java index a56a4350..f6dc3a7f 100644 --- a/telegrambots-meta/src/test/java/org/telegram/telegrambots/meta/api/methods/send/SendMessageTest.java +++ b/telegrambots-meta/src/test/java/org/telegram/telegrambots/meta/api/methods/send/SendMessageTest.java @@ -1,25 +1,26 @@ package org.telegram.telegrambots.meta.api.methods.send; -import org.junit.Test; +import org.junit.jupiter.api.Test; -import static org.junit.Assert.*; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotEquals; -public class SendMessageTest { +class SendMessageTest { @Test - public void comparison() throws Exception { + void comparison() { SendMessage sm1 = new SendMessage().setChatId(1L).setText("Hello World"); SendMessage sm2 = new SendMessage().setChatId(1L).setText("Hello World"); SendMessage noMessage = new SendMessage().setChatId(1L); SendMessage disabledNotification = new SendMessage().setChatId(1L).setText("Hello World").disableNotification(); - assertTrue(sm1.equals(sm2)); - assertFalse(sm1.equals(noMessage)); - assertFalse(sm1.equals(disabledNotification)); + assertEquals(sm1, sm2); + assertNotEquals(sm1, noMessage); + assertNotEquals(sm1, disabledNotification); - assertTrue(sm1.hashCode() == sm2.hashCode()); - assertFalse(sm1.hashCode() == noMessage.hashCode()); - assertFalse(sm1.hashCode() == disabledNotification.hashCode()); + assertEquals(sm1.hashCode(), sm2.hashCode()); + assertNotEquals(sm1.hashCode(), noMessage.hashCode()); + assertNotEquals(sm1.hashCode(), disabledNotification.hashCode()); } } \ No newline at end of file diff --git a/telegrambots-meta/src/test/java/org/telegram/telegrambots/meta/api/objects/replykeyboard/buttons/KeyboardRowTest.java b/telegrambots-meta/src/test/java/org/telegram/telegrambots/meta/api/objects/replykeyboard/buttons/KeyboardRowTest.java index 3e4f87f6..ac702503 100644 --- a/telegrambots-meta/src/test/java/org/telegram/telegrambots/meta/api/objects/replykeyboard/buttons/KeyboardRowTest.java +++ b/telegrambots-meta/src/test/java/org/telegram/telegrambots/meta/api/objects/replykeyboard/buttons/KeyboardRowTest.java @@ -1,31 +1,30 @@ package org.telegram.telegrambots.meta.api.objects.replykeyboard.buttons; -import org.junit.Test; + +import org.junit.jupiter.api.Test; import java.util.ArrayList; -import java.util.Collections; import java.util.List; import static java.util.Arrays.asList; -import static org.hamcrest.core.Is.is; -import static org.junit.Assert.assertThat; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertTrue; -public class KeyboardRowTest { +class KeyboardRowTest { private static final List BUTTON_NAMES = asList("Carlotta Valdes", "Jimmy Stewart"); @Test - public void shouldAddAllButtons() { + void shouldAddAllButtons() { final KeyboardRow keyboardRow = new KeyboardRow(); keyboardRow.addAll(BUTTON_NAMES); - assertThat(keyboardRow.size(), is(2)); - assertThat(keyboardRow.get(0).getText(), is("Carlotta Valdes")); - assertThat(keyboardRow.get(1).getText(), is("Jimmy Stewart")); + assertEquals(2, keyboardRow.size()); + assertEquals("Carlotta Valdes", keyboardRow.get(0).getText()); + assertEquals("Jimmy Stewart", keyboardRow.get(1).getText()); } @Test - public void shouldAddNoButtons() { + void shouldAddNoButtons() { final KeyboardRow keyboardRow = new KeyboardRow(); keyboardRow.addAll(new ArrayList()); assertTrue(keyboardRow.isEmpty()); diff --git a/telegrambots-meta/src/test/java/org/telegram/telegrambots/meta/test/TestDeserialization.java b/telegrambots-meta/src/test/java/org/telegram/telegrambots/meta/test/TestDeserialization.java index c65db037..02893c15 100644 --- a/telegrambots-meta/src/test/java/org/telegram/telegrambots/meta/test/TestDeserialization.java +++ b/telegrambots-meta/src/test/java/org/telegram/telegrambots/meta/test/TestDeserialization.java @@ -3,9 +3,9 @@ package org.telegram.telegrambots.meta.test; import com.fasterxml.jackson.core.type.TypeReference; import com.fasterxml.jackson.databind.ObjectMapper; -import org.junit.Assert; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.telegram.telegrambots.meta.api.objects.ApiResponse; import org.telegram.telegrambots.meta.api.objects.Audio; import org.telegram.telegrambots.meta.api.objects.CallbackQuery; import org.telegram.telegrambots.meta.api.objects.Chat; @@ -18,63 +18,67 @@ import org.telegram.telegrambots.meta.api.objects.User; import org.telegram.telegrambots.meta.api.objects.Voice; import org.telegram.telegrambots.meta.api.objects.inlinequery.ChosenInlineQuery; import org.telegram.telegrambots.meta.api.objects.inlinequery.InlineQuery; -import org.telegram.telegrambots.meta.api.objects.ApiResponse; import java.io.IOException; import java.util.ArrayList; import java.util.List; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertTrue; + /** * @author Ruben Bermudez * @version 1.0 */ -public class TestDeserialization { +class TestDeserialization { private ObjectMapper mapper; - @Before - public void setUp() { + @BeforeEach + void setUp() { mapper = new ObjectMapper(); } @Test - public void TestUpdateDeserialization() throws Exception { + void TestUpdateDeserialization() throws Exception { Update update = mapper.readValue(TelegramBotsHelper.GetUpdate(), Update.class); assertUpdate(update); } @Test - public void TestUpdateDeserializationWithInlineKeyboard() throws Exception { + void TestUpdateDeserializationWithInlineKeyboard() throws Exception { Update update = mapper.readValue(TelegramBotsHelper.GetUpdateWithMessageInCallbackQuery(), Update.class); - Assert.assertNotNull(update); - Assert.assertNotNull(update.getCallbackQuery()); - Assert.assertNotNull(update.getCallbackQuery().getMessage()); - Assert.assertNotNull(update.getCallbackQuery().getMessage().getReplyMarkup()); + assertNotNull(update); + assertNotNull(update.getCallbackQuery()); + assertNotNull(update.getCallbackQuery().getMessage()); + assertNotNull(update.getCallbackQuery().getMessage().getReplyMarkup()); } @Test - public void TestResponseWithoutErrorDeserialization() throws IOException { + void TestResponseWithoutErrorDeserialization() throws IOException { ApiResponse> result = mapper.readValue(TelegramBotsHelper.GetResponseWithoutError(), new TypeReference>>(){}); - Assert.assertNotNull(result); - Assert.assertTrue(result.getOk()); - Assert.assertEquals(1, result.getResult().size()); + assertNotNull(result); + assertTrue(result.getOk()); + assertEquals(1, result.getResult().size()); assertUpdate(result.getResult().get(0)); } @Test - public void TestResponseWithErrorDeserialization() throws IOException { + void TestResponseWithErrorDeserialization() throws IOException { ApiResponse> result = mapper.readValue(TelegramBotsHelper.GetResponseWithError(), new TypeReference>>(){}); - Assert.assertNotNull(result); - Assert.assertFalse(result.getOk()); - Assert.assertEquals(Integer.valueOf(400), result.getErrorCode()); - Assert.assertEquals("Error descriptions", result.getErrorDescription()); - Assert.assertNotNull(result.getParameters()); - Assert.assertEquals(Long.valueOf(12345), result.getParameters().getMigrateToChatId()); - Assert.assertEquals(Integer.valueOf(12), result.getParameters().getRetryAfter()); + assertNotNull(result); + assertFalse(result.getOk()); + assertEquals(Integer.valueOf(400), result.getErrorCode()); + assertEquals("Error descriptions", result.getErrorDescription()); + assertNotNull(result.getParameters()); + assertEquals(Long.valueOf(12345), result.getParameters().getMigrateToChatId()); + assertEquals(Integer.valueOf(12), result.getParameters().getRetryAfter()); } private void assertUpdate(Update update) { - Assert.assertNotNull(update); - Assert.assertEquals((Integer) 10000, update.getUpdateId()); + assertNotNull(update); + assertEquals((Integer) 10000, update.getUpdateId()); assertEditedMessage(update.getEditedMessage()); assertCallbackQuery(update.getCallbackQuery()); assertInlineQuery(update.getInlineQuery()); @@ -83,11 +87,11 @@ public class TestDeserialization { } private void assertMessage(Message message) { - Assert.assertNotNull(message); - Assert.assertEquals(Integer.valueOf(1441645532), message.getDate()); - Assert.assertEquals(Integer.valueOf(1365), message.getMessageId()); - Assert.assertEquals(Integer.valueOf(1441645550), message.getForwardDate()); - Assert.assertEquals("Bold and italics", message.getText()); + assertNotNull(message); + assertEquals(Integer.valueOf(1441645532), message.getDate()); + assertEquals(Integer.valueOf(1365), message.getMessageId()); + assertEquals(Integer.valueOf(1441645550), message.getForwardDate()); + assertEquals("Bold and italics", message.getText()); assertPrivateChat(message.getChat()); assertFromUser(message.getFrom()); assertForwardFrom(message.getForwardFrom()); @@ -99,119 +103,119 @@ public class TestDeserialization { } private void assertDocument(Document document) { - Assert.assertNotNull(document); - Assert.assertEquals("AwADBAADbXXXXXXXXXXXGBdhD2l6_XX", document.getFileId()); - Assert.assertEquals("Testfile.pdf", document.getFileName()); - Assert.assertEquals("application/pdf", document.getMimeType()); - Assert.assertEquals(Integer.valueOf(536392), document.getFileSize()); + assertNotNull(document); + assertEquals("AwADBAADbXXXXXXXXXXXGBdhD2l6_XX", document.getFileId()); + assertEquals("Testfile.pdf", document.getFileName()); + assertEquals("application/pdf", document.getMimeType()); + assertEquals(Integer.valueOf(536392), document.getFileSize()); } private void assertVoice(Voice voice) { - Assert.assertNotNull(voice); - Assert.assertEquals("AwADBAADbXXXXXXXXXXXGBdhD2l6_XX", voice.getFileId()); - Assert.assertEquals(Integer.valueOf(5), voice.getDuration()); - Assert.assertEquals("audio/ogg", voice.getMimeType()); - Assert.assertEquals(Integer.valueOf(23000), voice.getFileSize()); + assertNotNull(voice); + assertEquals("AwADBAADbXXXXXXXXXXXGBdhD2l6_XX", voice.getFileId()); + assertEquals(Integer.valueOf(5), voice.getDuration()); + assertEquals("audio/ogg", voice.getMimeType()); + assertEquals(Integer.valueOf(23000), voice.getFileSize()); } private void assertAudio(Audio audio) { - Assert.assertNotNull(audio); - Assert.assertEquals("AwADBAADbXXXXXXXXXXXGBdhD2l6_XX", audio.getFileId()); - Assert.assertEquals(Integer.valueOf(243), audio.getDuration()); - Assert.assertEquals("audio/mpeg", audio.getMimeType()); - Assert.assertEquals(Integer.valueOf(3897500), audio.getFileSize()); - Assert.assertEquals("Testmusicfile", audio.getTitle()); + assertNotNull(audio); + assertEquals("AwADBAADbXXXXXXXXXXXGBdhD2l6_XX", audio.getFileId()); + assertEquals(Integer.valueOf(243), audio.getDuration()); + assertEquals("audio/mpeg", audio.getMimeType()); + assertEquals(Integer.valueOf(3897500), audio.getFileSize()); + assertEquals("Testmusicfile", audio.getTitle()); } private void assertEntities(List entities) { - Assert.assertNotNull(entities); - Assert.assertEquals(2, entities.size()); - Assert.assertEquals(EntityType.ITALIC, entities.get(0).getType()); - Assert.assertEquals(Integer.valueOf(9), entities.get(0).getOffset()); - Assert.assertEquals(Integer.valueOf(7), entities.get(0).getLength()); - Assert.assertEquals("italics", entities.get(0).getText()); - Assert.assertEquals(EntityType.BOLD, entities.get(1).getType()); - Assert.assertEquals(Integer.valueOf(0), entities.get(1).getOffset()); - Assert.assertEquals(Integer.valueOf(4), entities.get(1).getLength()); - Assert.assertEquals("Bold", entities.get(1).getText()); + assertNotNull(entities); + assertEquals(2, entities.size()); + assertEquals(EntityType.ITALIC, entities.get(0).getType()); + assertEquals(Integer.valueOf(9), entities.get(0).getOffset()); + assertEquals(Integer.valueOf(7), entities.get(0).getLength()); + assertEquals("italics", entities.get(0).getText()); + assertEquals(EntityType.BOLD, entities.get(1).getType()); + assertEquals(Integer.valueOf(0), entities.get(1).getOffset()); + assertEquals(Integer.valueOf(4), entities.get(1).getLength()); + assertEquals("Bold", entities.get(1).getText()); } private void assertReplyToMessage(Message replyToMessage) { - Assert.assertNotNull(replyToMessage); - Assert.assertEquals(Integer.valueOf(1441645000), replyToMessage.getDate()); - Assert.assertEquals(Integer.valueOf(1334), replyToMessage.getMessageId()); - Assert.assertEquals("Original", replyToMessage.getText()); - Assert.assertNotNull(replyToMessage.getChat()); - Assert.assertEquals("ReplyLastname", replyToMessage.getChat().getLastName()); - Assert.assertEquals("ReplyFirstname", replyToMessage.getChat().getFirstName()); - Assert.assertEquals("Testusername", replyToMessage.getChat().getUserName()); - Assert.assertEquals(Long.valueOf(1111112), replyToMessage.getChat().getId()); + assertNotNull(replyToMessage); + assertEquals(Integer.valueOf(1441645000), replyToMessage.getDate()); + assertEquals(Integer.valueOf(1334), replyToMessage.getMessageId()); + assertEquals("Original", replyToMessage.getText()); + assertNotNull(replyToMessage.getChat()); + assertEquals("ReplyLastname", replyToMessage.getChat().getLastName()); + assertEquals("ReplyFirstname", replyToMessage.getChat().getFirstName()); + assertEquals("Testusername", replyToMessage.getChat().getUserName()); + assertEquals(Long.valueOf(1111112), replyToMessage.getChat().getId()); } private void assertForwardFrom(User forwardFrom) { - Assert.assertNotNull(forwardFrom); - Assert.assertEquals("ForwardLastname", forwardFrom.getLastName()); - Assert.assertEquals("ForwardFirstname", forwardFrom.getFirstName()); - Assert.assertEquals(Integer.valueOf(222222), forwardFrom.getId()); + assertNotNull(forwardFrom); + assertEquals("ForwardLastname", forwardFrom.getLastName()); + assertEquals("ForwardFirstname", forwardFrom.getFirstName()); + assertEquals(Integer.valueOf(222222), forwardFrom.getId()); } private void assertPrivateChat(Chat chat) { - Assert.assertNotNull(chat); - Assert.assertEquals(Long.valueOf(1111111), chat.getId()); - Assert.assertTrue(chat.isUserChat()); - Assert.assertEquals("Test Lastname", chat.getLastName()); - Assert.assertEquals("Test Firstname", chat.getFirstName()); - Assert.assertEquals("Testusername", chat.getUserName()); + assertNotNull(chat); + assertEquals(Long.valueOf(1111111), chat.getId()); + assertTrue(chat.isUserChat()); + assertEquals("Test Lastname", chat.getLastName()); + assertEquals("Test Firstname", chat.getFirstName()); + assertEquals("Testusername", chat.getUserName()); } private void assertChosenInlineQuery(ChosenInlineQuery chosenInlineQuery) { - Assert.assertNotNull(chosenInlineQuery); - Assert.assertEquals("12", chosenInlineQuery.getResultId()); - Assert.assertEquals("inline query", chosenInlineQuery.getQuery()); - Assert.assertEquals("1234csdbsk4839", chosenInlineQuery.getInlineMessageId()); + assertNotNull(chosenInlineQuery); + assertEquals("12", chosenInlineQuery.getResultId()); + assertEquals("inline query", chosenInlineQuery.getQuery()); + assertEquals("1234csdbsk4839", chosenInlineQuery.getInlineMessageId()); assertFromUser(chosenInlineQuery.getFrom()); } private void assertInlineQuery(InlineQuery inlineQuery) { - Assert.assertNotNull(inlineQuery); - Assert.assertEquals("134567890097", inlineQuery.getId()); - Assert.assertEquals("inline query", inlineQuery.getQuery()); - Assert.assertEquals("offset", inlineQuery.getOffset()); + assertNotNull(inlineQuery); + assertEquals("134567890097", inlineQuery.getId()); + assertEquals("inline query", inlineQuery.getQuery()); + assertEquals("offset", inlineQuery.getOffset()); assertFromUser(inlineQuery.getFrom()); - Assert.assertNotNull(inlineQuery.getLocation()); - Assert.assertEquals(Float.valueOf("0.234242534"), inlineQuery.getLocation().getLatitude()); - Assert.assertEquals(Float.valueOf("0.234242534"), inlineQuery.getLocation().getLongitude()); + assertNotNull(inlineQuery.getLocation()); + assertEquals(Float.valueOf("0.234242534"), inlineQuery.getLocation().getLatitude()); + assertEquals(Float.valueOf("0.234242534"), inlineQuery.getLocation().getLongitude()); } private void assertCallbackQuery(CallbackQuery callbackQuery) { - Assert.assertNotNull(callbackQuery); - Assert.assertEquals("4382bfdwdsb323b2d9", callbackQuery.getId()); - Assert.assertEquals("Data from button callback", callbackQuery.getData()); - Assert.assertEquals("1234csdbsk4839", callbackQuery.getInlineMessageId()); + assertNotNull(callbackQuery); + assertEquals("4382bfdwdsb323b2d9", callbackQuery.getId()); + assertEquals("Data from button callback", callbackQuery.getData()); + assertEquals("1234csdbsk4839", callbackQuery.getInlineMessageId()); assertFromUser(callbackQuery.getFrom()); } private void assertEditedMessage(Message message) { - Assert.assertEquals((Integer) 1441645532, message.getDate()); - Assert.assertEquals((Integer) 1441646600, message.getEditDate()); - Assert.assertEquals((Integer) 1365, message.getMessageId()); - Assert.assertEquals("Edited text", message.getText()); + assertEquals((Integer) 1441645532, message.getDate()); + assertEquals((Integer) 1441646600, message.getEditDate()); + assertEquals((Integer) 1365, message.getMessageId()); + assertEquals("Edited text", message.getText()); assertChannelChat(message.getChat()); assertFromUser(message.getFrom()); } private void assertFromUser(User from) { - Assert.assertNotNull(from); - Assert.assertEquals((Integer) 1111111, from.getId()); - Assert.assertEquals("Test Lastname", from.getLastName()); - Assert.assertEquals("Test Firstname", from.getFirstName()); - Assert.assertEquals("Testusername", from.getUserName()); + assertNotNull(from); + assertEquals((Integer) 1111111, from.getId()); + assertEquals("Test Lastname", from.getLastName()); + assertEquals("Test Firstname", from.getFirstName()); + assertEquals("Testusername", from.getUserName()); } private void assertChannelChat(Chat chat) { - Assert.assertNotNull(chat); - Assert.assertEquals(Long.valueOf(-10000000000L), chat.getId()); - Assert.assertTrue(chat.isChannelChat()); - Assert.assertEquals("Test channel", chat.getTitle()); + assertNotNull(chat); + assertEquals(Long.valueOf(-10000000000L), chat.getId()); + assertTrue(chat.isChannelChat()); + assertEquals("Test channel", chat.getTitle()); } -} +} \ No newline at end of file diff --git a/telegrambots-meta/src/test/java/org/telegram/telegrambots/meta/test/TestTelegramApi.java b/telegrambots-meta/src/test/java/org/telegram/telegrambots/meta/test/TestTelegramApi.java index 45b28c36..35dce949 100644 --- a/telegrambots-meta/src/test/java/org/telegram/telegrambots/meta/test/TestTelegramApi.java +++ b/telegrambots-meta/src/test/java/org/telegram/telegrambots/meta/test/TestTelegramApi.java @@ -1,46 +1,47 @@ package org.telegram.telegrambots.meta.test; -import org.junit.Assert; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.telegram.telegrambots.meta.TelegramBotsApi; -import org.telegram.telegrambots.meta.test.base.TestBase; import org.telegram.telegrambots.meta.exceptions.TelegramApiRequestException; +import org.telegram.telegrambots.meta.test.base.TestBase; + +import static org.junit.jupiter.api.Assertions.fail; /** * @author Ruben Bermudez * @version 1.0 */ -public class TestTelegramApi extends TestBase { +class TestTelegramApi extends TestBase { @Test - public void TestTelegramApiMustBeInitializableForLongPolling() { + void TestTelegramApiMustBeInitializableForLongPolling() { new TelegramBotsApi(); } @Test - public void TestTelegramApiMustBeInitializableForWebhookWithoutSecureSupport() { + void TestTelegramApiMustBeInitializableForWebhookWithoutSecureSupport() { try { new TelegramBotsApi("externalUrl", "internalUrl"); } catch (TelegramApiRequestException e) { - Assert.fail(); + fail(); } } @Test - public void TestTelegramApiMustBeInitializableForWebhook() { + void TestTelegramApiMustBeInitializableForWebhook() { try { new TelegramBotsApi("keyStore", "keyStorePassword", "externalUrl", "internalUrl"); } catch (TelegramApiRequestException e) { - Assert.fail(); + fail(); } } @Test - public void TestTelegramApiMustBeInitializableForWebhookWithSelfSignedCertificate() { + void TestTelegramApiMustBeInitializableForWebhookWithSelfSignedCertificate() { try { new TelegramBotsApi("keyStore", "keyStorePassword", "externalUrl", "internalUrl", "selfSignedPath"); } catch (TelegramApiRequestException e) { - Assert.fail(); + fail(); } } } diff --git a/telegrambots-meta/src/test/java/org/telegram/telegrambots/meta/test/apimethods/TestAnswerInlineQuery.java b/telegrambots-meta/src/test/java/org/telegram/telegrambots/meta/test/apimethods/TestAnswerInlineQuery.java index eea69669..75b4f6e1 100644 --- a/telegrambots-meta/src/test/java/org/telegram/telegrambots/meta/test/apimethods/TestAnswerInlineQuery.java +++ b/telegrambots-meta/src/test/java/org/telegram/telegrambots/meta/test/apimethods/TestAnswerInlineQuery.java @@ -1,56 +1,57 @@ package org.telegram.telegrambots.meta.test.apimethods; -import org.junit.Assert; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.telegram.telegrambots.meta.api.methods.AnswerInlineQuery; import org.telegram.telegrambots.meta.exceptions.TelegramApiValidationException; import java.util.ArrayList; +import static org.junit.jupiter.api.Assertions.assertEquals; + /** * @author Ruben Bermudez * @version 1.0 */ -public class TestAnswerInlineQuery { +class TestAnswerInlineQuery { private AnswerInlineQuery answerInlineQuery; - @Before - public void setUp() throws Exception { + @BeforeEach + void setUp() { answerInlineQuery = new AnswerInlineQuery(); } @Test - public void TestInlineQueryIdMustBePresent() throws Exception { + void TestInlineQueryIdMustBePresent() { try { answerInlineQuery.validate(); } catch (TelegramApiValidationException e) { - Assert.assertEquals("InlineQueryId can't be empty", e.getMessage()); + assertEquals("InlineQueryId can't be empty", e.getMessage()); } } @Test - public void TestInlineQueryIdCanNotBeEmpty() throws Exception { + void TestInlineQueryIdCanNotBeEmpty() { answerInlineQuery.setInlineQueryId(""); try { answerInlineQuery.validate(); } catch (TelegramApiValidationException e) { - Assert.assertEquals("InlineQueryId can't be empty", e.getMessage()); + assertEquals("InlineQueryId can't be empty", e.getMessage()); } } @Test - public void TestResultsMustBePresent() throws Exception { + void TestResultsMustBePresent() { answerInlineQuery.setInlineQueryId("RANDOMEID"); try { answerInlineQuery.validate(); } catch (TelegramApiValidationException e) { - Assert.assertEquals("Results array can't be null", e.getMessage()); + assertEquals("Results array can't be null", e.getMessage()); } } @Test - public void TestSwitchPmTextCanNotBeEmpty() throws Exception { + void TestSwitchPmTextCanNotBeEmpty() { answerInlineQuery.setInlineQueryId("RANDOMEID"); answerInlineQuery.setResults(new ArrayList<>()); answerInlineQuery.setSwitchPmText(""); @@ -58,12 +59,12 @@ public class TestAnswerInlineQuery { try { answerInlineQuery.validate(); } catch (TelegramApiValidationException e) { - Assert.assertEquals("SwitchPmText can't be empty", e.getMessage()); + assertEquals("SwitchPmText can't be empty", e.getMessage()); } } @Test - public void TestSwitchPmParameterIsMandatoryIfSwitchPmTextIsPresent() throws Exception { + void TestSwitchPmParameterIsMandatoryIfSwitchPmTextIsPresent() { answerInlineQuery.setInlineQueryId("RANDOMEID"); answerInlineQuery.setResults(new ArrayList<>()); answerInlineQuery.setSwitchPmText("Test Text"); @@ -71,12 +72,12 @@ public class TestAnswerInlineQuery { try { answerInlineQuery.validate(); } catch (TelegramApiValidationException e) { - Assert.assertEquals("SwitchPmParameter can't be empty if switchPmText is present", e.getMessage()); + assertEquals("SwitchPmParameter can't be empty if switchPmText is present", e.getMessage()); } } @Test - public void TestSwitchPmParameterCanNotBeEmptyIfSwitchPmTextIsPresent() throws Exception { + void TestSwitchPmParameterCanNotBeEmptyIfSwitchPmTextIsPresent() { answerInlineQuery.setInlineQueryId("RANDOMEID"); answerInlineQuery.setResults(new ArrayList<>()); answerInlineQuery.setSwitchPmText("Test Text"); @@ -85,12 +86,12 @@ public class TestAnswerInlineQuery { try { answerInlineQuery.validate(); } catch (TelegramApiValidationException e) { - Assert.assertEquals("SwitchPmParameter can't be empty if switchPmText is present", e.getMessage()); + assertEquals("SwitchPmParameter can't be empty if switchPmText is present", e.getMessage()); } } @Test - public void TestSwitchPmParameterContainsUpTo64Chars() throws Exception { + void TestSwitchPmParameterContainsUpTo64Chars() { answerInlineQuery.setInlineQueryId("RANDOMEID"); answerInlineQuery.setResults(new ArrayList<>()); answerInlineQuery.setSwitchPmText("Test Text"); @@ -99,12 +100,12 @@ public class TestAnswerInlineQuery { try { answerInlineQuery.validate(); } catch (TelegramApiValidationException e) { - Assert.assertEquals("SwitchPmParameter can't be longer than 64 chars", e.getMessage()); + assertEquals("SwitchPmParameter can't be longer than 64 chars", e.getMessage()); } } @Test - public void TestSwitchPmParameterOnlyContainsAcceptedCharacters() throws Exception { + void TestSwitchPmParameterOnlyContainsAcceptedCharacters() { answerInlineQuery.setInlineQueryId("RANDOMEID"); answerInlineQuery.setResults(new ArrayList<>()); answerInlineQuery.setSwitchPmText("Test Text"); @@ -113,7 +114,7 @@ public class TestAnswerInlineQuery { try { answerInlineQuery.validate(); } catch (TelegramApiValidationException e) { - Assert.assertEquals("SwitchPmParameter only allows A-Z, a-z, 0-9, _ and - characters", e.getMessage()); + assertEquals("SwitchPmParameter only allows A-Z, a-z, 0-9, _ and - characters", e.getMessage()); } } } diff --git a/telegrambots-meta/src/test/java/org/telegram/telegrambots/meta/test/apimethods/TestGetUpdates.java b/telegrambots-meta/src/test/java/org/telegram/telegrambots/meta/test/apimethods/TestGetUpdates.java index 9b4f8659..4d433f6e 100644 --- a/telegrambots-meta/src/test/java/org/telegram/telegrambots/meta/test/apimethods/TestGetUpdates.java +++ b/telegrambots-meta/src/test/java/org/telegram/telegrambots/meta/test/apimethods/TestGetUpdates.java @@ -2,27 +2,29 @@ package org.telegram.telegrambots.meta.test.apimethods; import com.fasterxml.jackson.databind.ObjectMapper; -import org.junit.Assert; -import org.junit.Before; -import org.junit.Test; -import org.telegram.telegrambots.meta.test.TelegramBotsHelper; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.telegram.telegrambots.meta.api.methods.updates.GetUpdates; import org.telegram.telegrambots.meta.api.objects.Update; import org.telegram.telegrambots.meta.exceptions.TelegramApiRequestException; +import org.telegram.telegrambots.meta.test.TelegramBotsHelper; import java.util.ArrayList; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; + /** * @author Ruben Bermudez * @version 1.0 */ -public class TestGetUpdates { +class TestGetUpdates { private GetUpdates getUpdates; private ObjectMapper mapper = new ObjectMapper(); - @Before - public void setUp() throws Exception { + @BeforeEach + void setUp() { getUpdates = new GetUpdates(); getUpdates.setOffset(15); getUpdates.setTimeout(50); @@ -30,28 +32,28 @@ public class TestGetUpdates { } @Test - public void TestGetUpdatesMustBeSerializable() throws Exception { + void TestGetUpdatesMustBeSerializable() throws Exception { String json = mapper.writeValueAsString(getUpdates); - Assert.assertNotNull(json); - Assert.assertEquals("{\"offset\":15,\"limit\":100,\"timeout\":50,\"method\":\"getupdates\"}", json); + assertNotNull(json); + assertEquals("{\"offset\":15,\"limit\":100,\"timeout\":50,\"method\":\"getupdates\"}", json); } @Test - public void TestGetUpdatesMustDeserializeCorrectResponse() throws Exception { + void TestGetUpdatesMustDeserializeCorrectResponse() throws Exception { ArrayList result = getUpdates.deserializeResponse(TelegramBotsHelper.GetResponseWithoutError()); - Assert.assertNotNull(result); - Assert.assertEquals(1, result.size()); + assertNotNull(result); + assertEquals(1, result.size()); } @Test - public void TestGetUpdatesMustThrowAnExceptionForInCorrectResponse() { + void TestGetUpdatesMustThrowAnExceptionForInCorrectResponse() { try { getUpdates.deserializeResponse(TelegramBotsHelper.GetResponseWithError()); } catch (TelegramApiRequestException e) { - Assert.assertNotNull(e.getParameters()); - Assert.assertEquals(Integer.valueOf(400), e.getErrorCode()); - Assert.assertEquals("Error descriptions", e.getApiResponse()); + assertNotNull(e.getParameters()); + assertEquals(Integer.valueOf(400), e.getErrorCode()); + assertEquals("Error descriptions", e.getApiResponse()); } } } diff --git a/telegrambots-meta/src/test/java/org/telegram/telegrambots/meta/test/apimethods/TestSetGameScore.java b/telegrambots-meta/src/test/java/org/telegram/telegrambots/meta/test/apimethods/TestSetGameScore.java index a04a9812..4c9a2835 100644 --- a/telegrambots-meta/src/test/java/org/telegram/telegrambots/meta/test/apimethods/TestSetGameScore.java +++ b/telegrambots-meta/src/test/java/org/telegram/telegrambots/meta/test/apimethods/TestSetGameScore.java @@ -2,26 +2,29 @@ package org.telegram.telegrambots.meta.test.apimethods; import com.fasterxml.jackson.databind.ObjectMapper; -import org.junit.Assert; -import org.junit.Before; -import org.junit.Test; -import org.telegram.telegrambots.meta.test.TelegramBotsHelper; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.telegram.telegrambots.meta.api.methods.games.SetGameScore; import org.telegram.telegrambots.meta.api.objects.Message; +import org.telegram.telegrambots.meta.test.TelegramBotsHelper; import java.io.Serializable; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertTrue; + /** * @author Ruben Bermudez * @version 1.0 */ -public class TestSetGameScore { +class TestSetGameScore { private SetGameScore setGameScore; private ObjectMapper mapper = new ObjectMapper(); - @Before - public void setUp() throws Exception { + @BeforeEach + void setUp() { setGameScore = new SetGameScore(); setGameScore.setChatId("12345"); setGameScore.setDisableEditMessage(true); @@ -31,25 +34,25 @@ public class TestSetGameScore { } @Test - public void TestGetUpdatesMustBeSerializable() throws Exception { + void TestGetUpdatesMustBeSerializable() throws Exception { String json = mapper.writeValueAsString(setGameScore); - Assert.assertNotNull(json); - Assert.assertEquals("{\"chat_id\":\"12345\",\"message_id\":54321,\"disable_edit_message\":true,\"user_id\":98765,\"score\":12,\"method\":\"setGameScore\"}", json); + assertNotNull(json); + assertEquals("{\"chat_id\":\"12345\",\"message_id\":54321,\"disable_edit_message\":true,\"user_id\":98765,\"score\":12,\"method\":\"setGameScore\"}", json); } @Test - public void TestGetUpdatesMustDeserializeCorrectResponse() throws Exception { + void TestGetUpdatesMustDeserializeCorrectResponse() throws Exception { Serializable result = setGameScore.deserializeResponse(TelegramBotsHelper.GetSetGameScoreBooleanResponse()); - Assert.assertNotNull(result); - Assert.assertTrue(result instanceof Boolean); - Assert.assertTrue((Boolean) result); + assertNotNull(result); + assertTrue(result instanceof Boolean); + assertTrue((Boolean) result); } @Test - public void TestGetUpdatesMustThrowAnExceptionForInCorrectResponse() throws Exception { + void TestGetUpdatesMustThrowAnExceptionForInCorrectResponse() throws Exception { Serializable result = setGameScore.deserializeResponse(TelegramBotsHelper.GetSetGameScoreMessageResponse()); - Assert.assertNotNull(result); - Assert.assertTrue(result instanceof Message); + assertNotNull(result); + assertTrue(result instanceof Message); } } diff --git a/telegrambots-meta/src/test/java/org/telegram/telegrambots/meta/test/base/TestBase.java b/telegrambots-meta/src/test/java/org/telegram/telegrambots/meta/test/base/TestBase.java index 14c18240..08fd07e6 100644 --- a/telegrambots-meta/src/test/java/org/telegram/telegrambots/meta/test/base/TestBase.java +++ b/telegrambots-meta/src/test/java/org/telegram/telegrambots/meta/test/base/TestBase.java @@ -1,11 +1,11 @@ package org.telegram.telegrambots.meta.test.base; -import org.junit.BeforeClass; +import org.junit.jupiter.api.BeforeAll; import org.telegram.telegrambots.meta.ApiContext; -import org.telegram.telegrambots.meta.test.fakes.FakeBotSession; -import org.telegram.telegrambots.meta.test.fakes.FakeWebhook; import org.telegram.telegrambots.meta.generics.BotSession; import org.telegram.telegrambots.meta.generics.Webhook; +import org.telegram.telegrambots.meta.test.fakes.FakeBotSession; +import org.telegram.telegrambots.meta.test.fakes.FakeWebhook; /** * @author Ruben Bermudez @@ -13,7 +13,7 @@ import org.telegram.telegrambots.meta.generics.Webhook; */ public abstract class TestBase { - @BeforeClass + @BeforeAll public static void beforeClass() { ApiContext.register(BotSession.class, FakeBotSession.class); ApiContext.register(Webhook.class, FakeWebhook.class); diff --git a/telegrambots-spring-boot-starter/pom.xml b/telegrambots-spring-boot-starter/pom.xml index f6903d70..1e352ec1 100644 --- a/telegrambots-spring-boot-starter/pom.xml +++ b/telegrambots-spring-boot-starter/pom.xml @@ -3,9 +3,15 @@ xmlns="http://maven.apache.org/POM/4.0.0" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> 4.0.0 - org.telegram + + + org.telegram + Bots + 4.3.1 + + telegrambots-spring-boot-starter - 4.3.1 + ${project.parent.version} jar Telegram Bots Spring Boot Starter @@ -57,9 +63,14 @@ + 11 + ${java.version} + ${java.version} + UTF-8 UTF-8 - 2.0.2.RELEASE + + 2.1.6.RELEASE @@ -92,23 +103,8 @@ org.assertj assertj-core test - 3.9.1 + 3.12.2 - - - org.mockito - mockito-all - 2.0.2-beta - test - - - - junit - junit - 4.11 - test - - @@ -121,7 +117,7 @@ org.apache.maven.plugins maven-gpg-plugin - 1.5 + 1.6 sign-artifacts @@ -135,7 +131,7 @@ org.sonatype.plugins nexus-staging-maven-plugin - 1.6.3 + 1.6.8 true ossrh @@ -145,7 +141,7 @@ maven-clean-plugin - 3.0.0 + 3.1.0 clean-project @@ -158,7 +154,7 @@ maven-assembly-plugin - 2.6 + 3.1.1 jar-with-dependencies @@ -177,7 +173,7 @@ org.apache.maven.plugins maven-source-plugin - 3.0.0 + 3.1.0 @@ -189,14 +185,14 @@ org.apache.maven.plugins maven-javadoc-plugin - 2.10.3 + 3.1.0 jar - -Xdoclint:none + none @@ -204,7 +200,7 @@ org.jacoco jacoco-maven-plugin - 0.7.7.201606060606 + 0.8.4 @@ -223,7 +219,7 @@ org.apache.maven.plugins maven-enforcer-plugin - 1.4.1 + 3.0.0-M2 enforce-versions @@ -241,7 +237,7 @@ org.apache.maven.plugins maven-dependency-plugin - 2.4 + 3.1.1 copy @@ -249,15 +245,21 @@ + + org.apache.maven.plugins + maven-surefire-plugin + 3.0.0-M3 + org.apache.maven.plugins maven-compiler-plugin + 3.8.1 - 1.8 - 1.8 + ${java.version} + ${java.version} UTF-8 diff --git a/telegrambots/pom.xml b/telegrambots/pom.xml index 9f85279e..daf0a5bd 100644 --- a/telegrambots/pom.xml +++ b/telegrambots/pom.xml @@ -3,9 +3,15 @@ xmlns="http://maven.apache.org/POM/4.0.0" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> 4.0.0 - org.telegram + + + org.telegram + Bots + 4.3.1 + + telegrambots - 4.3.1 + ${project.parent.version} jar Telegram Bots @@ -57,15 +63,20 @@ + 11 + ${java.version} + ${java.version} + UTF-8 UTF-8 - 2.25.1 + + 2.29 1.19.3 - 4.5.3 + 4.5.9 20180813 2.9.9 - 2.9.0 - 2.5 + 2.9.9 + 2.6 @@ -96,26 +107,21 @@ jackson-jaxrs-json-provider ${jackson.version} + + com.fasterxml.jackson.module + jackson-module-jaxb-annotations + 2.9.9 + com.fasterxml.jackson.core jackson-databind ${jackson.version} - - - com.fasterxml.jackson.core - jackson-annotations - - org.glassfish.jersey.media jersey-media-json-jackson ${glassfish.version} - - com.fasterxml.jackson.core - jackson-annotations - com.fasterxml.jackson.jaxrs jackson-jaxrs-json-provider @@ -169,12 +175,6 @@ ${glassfish.version} test - - org.mockito - mockito-all - 2.0.2-beta - test - @@ -184,10 +184,15 @@ ${project.build.directory}/test-classes ${project.basedir}/src/main/java + + org.apache.maven.plugins + maven-surefire-plugin + 3.0.0-M3 + org.apache.maven.plugins maven-gpg-plugin - 1.5 + 1.6 sign-artifacts @@ -201,7 +206,7 @@ org.sonatype.plugins nexus-staging-maven-plugin - 1.6.3 + 1.6.8 true ossrh @@ -211,7 +216,7 @@ maven-clean-plugin - 3.0.0 + 3.1.0 clean-project @@ -224,7 +229,7 @@ maven-assembly-plugin - 2.6 + 3.1.1 jar-with-dependencies @@ -243,7 +248,7 @@ org.apache.maven.plugins maven-source-plugin - 3.0.0 + 3.1.0 @@ -255,14 +260,14 @@ org.apache.maven.plugins maven-javadoc-plugin - 2.10.3 + 3.1.0 jar - -Xdoclint:none + none @@ -270,7 +275,7 @@ org.jacoco jacoco-maven-plugin - 0.7.7.201606060606 + 0.8.4 @@ -289,7 +294,7 @@ org.apache.maven.plugins maven-enforcer-plugin - 1.4.1 + 3.0.0-M2 enforce-versions @@ -307,7 +312,7 @@ org.apache.maven.plugins maven-dependency-plugin - 2.4 + 3.1.1 copy @@ -321,9 +326,10 @@ org.apache.maven.plugins maven-compiler-plugin + 3.8.1 - 1.8 - 1.8 + ${java.version} + ${java.version} UTF-8 diff --git a/telegrambots/src/main/java/org/telegram/telegrambots/facilities/proxysocketfactorys/SocksConnectionSocketFactory.java b/telegrambots/src/main/java/org/telegram/telegrambots/facilities/proxysocketfactorys/SocksConnectionSocketFactory.java index d2b29a5e..2ecd9aa0 100644 --- a/telegrambots/src/main/java/org/telegram/telegrambots/facilities/proxysocketfactorys/SocksConnectionSocketFactory.java +++ b/telegrambots/src/main/java/org/telegram/telegrambots/facilities/proxysocketfactorys/SocksConnectionSocketFactory.java @@ -4,7 +4,6 @@ package org.telegram.telegrambots.facilities.proxysocketfactorys; import org.apache.http.HttpHost; import org.apache.http.conn.socket.PlainConnectionSocketFactory; import org.apache.http.protocol.HttpContext; -import sun.net.SocksProxy; import java.io.IOException; import java.net.InetSocketAddress; @@ -14,10 +13,9 @@ import java.net.Socket; public class SocksConnectionSocketFactory extends PlainConnectionSocketFactory { @Override - public Socket createSocket(final HttpContext context) throws IOException { + public Socket createSocket(final HttpContext context) { InetSocketAddress socksaddr = (InetSocketAddress) context.getAttribute("socketAddress"); - int socksVersion = (Integer) context.getAttribute("socksVersion"); - Proxy proxy = SocksProxy.create(socksaddr, socksVersion); + Proxy proxy = new Proxy(Proxy.Type.SOCKS, socksaddr); return new Socket(proxy); } diff --git a/telegrambots/src/main/java/org/telegram/telegrambots/facilities/proxysocketfactorys/SocksSSLConnectionSocketFactory.java b/telegrambots/src/main/java/org/telegram/telegrambots/facilities/proxysocketfactorys/SocksSSLConnectionSocketFactory.java index cbd46b6a..80dc2adb 100644 --- a/telegrambots/src/main/java/org/telegram/telegrambots/facilities/proxysocketfactorys/SocksSSLConnectionSocketFactory.java +++ b/telegrambots/src/main/java/org/telegram/telegrambots/facilities/proxysocketfactorys/SocksSSLConnectionSocketFactory.java @@ -4,14 +4,14 @@ import org.apache.http.HttpHost; import org.apache.http.conn.ssl.NoopHostnameVerifier; import org.apache.http.conn.ssl.SSLConnectionSocketFactory; import org.apache.http.protocol.HttpContext; -import sun.net.SocksProxy; -import javax.net.ssl.SSLContext; import java.io.IOException; import java.net.InetSocketAddress; import java.net.Proxy; import java.net.Socket; +import javax.net.ssl.SSLContext; + public class SocksSSLConnectionSocketFactory extends SSLConnectionSocketFactory { @@ -20,10 +20,9 @@ public class SocksSSLConnectionSocketFactory extends SSLConnectionSocketFactory } @Override - public Socket createSocket(final HttpContext context) throws IOException { + public Socket createSocket(final HttpContext context) { InetSocketAddress socksaddr = (InetSocketAddress) context.getAttribute("socketAddress"); - int socksVersion = (Integer) context.getAttribute("socksVersion"); - Proxy proxy = SocksProxy.create(socksaddr, socksVersion); + Proxy proxy = new Proxy(Proxy.Type.SOCKS, socksaddr); return new Socket(proxy); }