diff --git a/Bots.ipr b/Bots.ipr
index 1cd4fbbe..f704f2bc 100644
--- a/Bots.ipr
+++ b/Bots.ipr
@@ -22,10 +22,10 @@
-
-
-
+
+
+
@@ -1514,6 +1514,17 @@
+
+
+
+
+
+
+
+
+
+
+
@@ -1525,6 +1536,39 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
@@ -1624,6 +1668,17 @@
+
+
+
+
+
+
+
+
+
+
+
@@ -1679,6 +1734,17 @@
+
+
+
+
+
+
+
+
+
+
+
diff --git a/pom.xml b/pom.xml
index 2e8b8c12..89054d6f 100644
--- a/pom.xml
+++ b/pom.xml
@@ -55,6 +55,12 @@
${mockito.version}
test
+
+ org.mockito
+ mockito-junit-jupiter
+ ${mockito.version}
+ test
+
com.fasterxml.jackson.core
jackson-annotations
diff --git a/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/Chat.java b/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/Chat.java
index 5e02745b..b543e3a0 100644
--- a/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/Chat.java
+++ b/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/Chat.java
@@ -25,7 +25,7 @@ public class Chat implements BotApiObject {
private static final String PINNEDMESSAGE_FIELD = "pinned_message";
private static final String STICKERSETNAME_FIELD = "sticker_set_name";
private static final String CANSETSTICKERSET_FIELD = "can_set_sticker_set";
- private static final String PERMISSIONS_FIELD = "can_set_sticker_set";
+ private static final String PERMISSIONS_FIELD = "permissions";
private static final String USERCHATTYPE = "private";
private static final String GROUPCHATTYPE = "group";
diff --git a/telegrambots/pom.xml b/telegrambots/pom.xml
index 8d5709c7..1143fd5e 100644
--- a/telegrambots/pom.xml
+++ b/telegrambots/pom.xml
@@ -117,6 +117,11 @@
jackson-databind
${jackson.version}
+
+ org.glassfish.jersey.inject
+ jersey-hk2
+ ${glassfish.version}
+
org.glassfish.jersey.media
jersey-media-json-jackson
diff --git a/telegrambots/src/main/java/org/telegram/telegrambots/bots/DefaultAbsSender.java b/telegrambots/src/main/java/org/telegram/telegrambots/bots/DefaultAbsSender.java
index b84e012a..0372eeb9 100644
--- a/telegrambots/src/main/java/org/telegram/telegrambots/bots/DefaultAbsSender.java
+++ b/telegrambots/src/main/java/org/telegram/telegrambots/bots/DefaultAbsSender.java
@@ -51,7 +51,7 @@ import static org.telegram.telegrambots.Constants.SOCKET_TIMEOUT;
* @version 1.0
* Implementation of all the methods needed to interact with Telegram Servers
*/
-@SuppressWarnings({"unused", "WeakerAccess"})
+@SuppressWarnings({"unused"})
public abstract class DefaultAbsSender extends AbsSender {
private static final ContentType TEXT_PLAIN_CONTENT_TYPE = ContentType.create("text/plain", StandardCharsets.UTF_8);
diff --git a/telegrambots/src/main/java/org/telegram/telegrambots/facilities/filedownloader/DownloadFileException.java b/telegrambots/src/main/java/org/telegram/telegrambots/facilities/filedownloader/DownloadFileException.java
index b458b958..d26c3f72 100644
--- a/telegrambots/src/main/java/org/telegram/telegrambots/facilities/filedownloader/DownloadFileException.java
+++ b/telegrambots/src/main/java/org/telegram/telegrambots/facilities/filedownloader/DownloadFileException.java
@@ -3,6 +3,7 @@ package org.telegram.telegrambots.facilities.filedownloader;
/**
* Runtime Exception to wrap Exceptions thrown during file download
*/
+@SuppressWarnings("WeakerAccess")
public class DownloadFileException extends RuntimeException {
public DownloadFileException(final String message, final Throwable e) {
super(message, e);
diff --git a/telegrambots/src/test/java/org/telegram/telegrambots/test/TelegramFileDownloaderTest.java b/telegrambots/src/test/java/org/telegram/telegrambots/test/TelegramFileDownloaderTest.java
index d185f869..e6f9366e 100644
--- a/telegrambots/src/test/java/org/telegram/telegrambots/test/TelegramFileDownloaderTest.java
+++ b/telegrambots/src/test/java/org/telegram/telegrambots/test/TelegramFileDownloaderTest.java
@@ -5,12 +5,15 @@ import org.apache.http.HttpResponse;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpUriRequest;
import org.apache.http.message.BasicStatusLine;
-import org.junit.Before;
-import org.junit.Test;
-import org.junit.runner.RunWith;
+import org.junit.jupiter.api.Assertions;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.ArgumentCaptor;
import org.mockito.Mock;
-import org.mockito.runners.MockitoJUnitRunner;
+import org.mockito.junit.jupiter.MockitoExtension;
+import org.mockito.junit.jupiter.MockitoSettings;
+import org.mockito.quality.Strictness;
import org.telegram.telegrambots.facilities.filedownloader.TelegramFileDownloader;
import org.telegram.telegrambots.meta.exceptions.TelegramApiException;
import org.telegram.telegrambots.meta.updateshandlers.DownloadFileCallback;
@@ -26,11 +29,14 @@ import static org.apache.http.HttpVersion.HTTP_1_1;
import static org.hamcrest.core.IsInstanceOf.instanceOf;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertThat;
-import static org.mockito.Matchers.any;
-import static org.mockito.Mockito.*;
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.Mockito.timeout;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
-@RunWith(MockitoJUnitRunner.class)
-public class TelegramFileDownloaderTest {
+@ExtendWith(MockitoExtension.class)
+@MockitoSettings(strictness = Strictness.LENIENT)
+class TelegramFileDownloaderTest {
private TelegramFileDownloader telegramFileDownloader;
@@ -48,38 +54,35 @@ public class TelegramFileDownloaderTest {
private Supplier tokenSupplierMock = () -> "someToken";
-
- @Before
- public void setup() throws IOException {
-
-
+ @BeforeEach
+ void setup() throws IOException {
when(httpResponseMock.getStatusLine()).thenReturn(new BasicStatusLine(HTTP_1_1, 200, "emptyString"));
when(httpResponseMock.getEntity()).thenReturn(httpEntityMock);
when(httpEntityMock.getContent()).thenReturn(toInputStream("Some File Content", defaultCharset()));
-
when(httpClientMock.execute(any(HttpUriRequest.class))).thenReturn(httpResponseMock);
telegramFileDownloader = new TelegramFileDownloader(httpClientMock, tokenSupplierMock);
}
@Test
- public void testFileDownload() throws TelegramApiException, IOException {
+ void testFileDownload() throws TelegramApiException, IOException {
File returnFile = telegramFileDownloader.downloadFile("someFilePath");
String content = readFileToString(returnFile, defaultCharset());
assertEquals("Some File Content", content);
}
- @Test(expected = TelegramApiException.class)
- public void testDownloadException() throws TelegramApiException {
+ @Test
+ void testDownloadException() {
when(httpResponseMock.getStatusLine()).thenReturn(new BasicStatusLine(HTTP_1_1, 500, "emptyString"));
- telegramFileDownloader.downloadFile("someFilePath");
+ Assertions.assertThrows(TelegramApiException.class,
+ () -> telegramFileDownloader.downloadFile("someFilePath"));
}
@Test
- public void testAsyncDownload() throws TelegramApiException, IOException {
+ void testAsyncDownload() throws TelegramApiException, IOException {
final ArgumentCaptor fileArgumentCaptor = ArgumentCaptor.forClass(File.class);
telegramFileDownloader.downloadFileAsync("someFilePath", downloadFileCallbackMock);
@@ -93,7 +96,7 @@ public class TelegramFileDownloaderTest {
}
@Test
- public void testAsyncException() throws TelegramApiException {
+ void testAsyncException() throws TelegramApiException {
final ArgumentCaptor exceptionArgumentCaptor = ArgumentCaptor.forClass(Exception.class);
when(httpResponseMock.getStatusLine()).thenReturn(new BasicStatusLine(HTTP_1_1, 500, "emptyString"));
diff --git a/telegrambots/src/test/java/org/telegram/telegrambots/test/TelegramLongPollingBotTest.java b/telegrambots/src/test/java/org/telegram/telegrambots/test/TelegramLongPollingBotTest.java
index 21ea2f08..fdef3699 100644
--- a/telegrambots/src/test/java/org/telegram/telegrambots/test/TelegramLongPollingBotTest.java
+++ b/telegrambots/src/test/java/org/telegram/telegrambots/test/TelegramLongPollingBotTest.java
@@ -2,23 +2,23 @@ package org.telegram.telegrambots.test;
import org.junit.Test;
import org.mockito.Mockito;
-import org.telegram.telegrambots.meta.api.objects.Update;
import org.telegram.telegrambots.bots.DefaultBotOptions;
import org.telegram.telegrambots.bots.TelegramLongPollingBot;
+import org.telegram.telegrambots.meta.api.objects.Update;
import org.telegram.telegrambots.updatesreceivers.DefaultBotSession;
-import static java.util.Arrays.asList;
-import static org.hamcrest.CoreMatchers.is;
-import static org.junit.Assert.*;
-import static org.mockito.Matchers.any;
-
import java.util.concurrent.ExecutorService;
import java.util.concurrent.TimeUnit;
+import static java.util.Arrays.asList;
+import static org.hamcrest.CoreMatchers.is;
+import static org.junit.Assert.assertThat;
+import static org.mockito.ArgumentMatchers.any;
+
public class TelegramLongPollingBotTest {
@Test
- public void testOnUpdateReceived() throws Exception {
+ public void testOnUpdateReceived() {
TelegramLongPollingBot bot = Mockito.mock(TelegramLongPollingBot.class);
Mockito.doCallRealMethod().when(bot).onUpdatesReceived(any());
Update update1 = new Update();
diff --git a/telegrambots/src/test/java/org/telegram/telegrambots/test/TestDefaultBotSession.java b/telegrambots/src/test/java/org/telegram/telegrambots/test/TestDefaultBotSession.java
index 206ee35d..941b3508 100644
--- a/telegrambots/src/test/java/org/telegram/telegrambots/test/TestDefaultBotSession.java
+++ b/telegrambots/src/test/java/org/telegram/telegrambots/test/TestDefaultBotSession.java
@@ -11,10 +11,9 @@ import org.junit.After;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
-import org.mockito.Matchers;
import org.mockito.Mockito;
-import org.telegram.telegrambots.meta.api.objects.Update;
import org.telegram.telegrambots.bots.DefaultBotOptions;
+import org.telegram.telegrambots.meta.api.objects.Update;
import org.telegram.telegrambots.meta.generics.LongPollingBot;
import org.telegram.telegrambots.test.Fakes.FakeLongPollingBot;
import org.telegram.telegrambots.updatesreceivers.DefaultBotSession;
@@ -22,17 +21,18 @@ import org.telegram.telegrambots.updatesreceivers.DefaultBotSession;
import java.io.IOException;
import java.util.Arrays;
import java.util.Collections;
-import java.util.List;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.stream.IntStream;
+import static org.mockito.ArgumentMatchers.any;
+
/**
* @author Ruben Bermudez
* @version 1.0
- * @brief Test for DefaultBotSession
+ * Test for DefaultBotSession
*/
public class TestDefaultBotSession {
- DefaultBotSession session;
+ private DefaultBotSession session;
@Before
public void setUp() throws Exception {
@@ -40,14 +40,14 @@ public class TestDefaultBotSession {
}
@After
- public void tearDown() throws Exception {
+ public void tearDown() {
if (session != null && session.isRunning()) {
session.stop();
}
}
@Test
- public void TestDefaultBotSessionIsNotRunningWhenCreated() throws Exception {
+ public void TestDefaultBotSessionIsNotRunningWhenCreated() {
Assert.assertFalse(session.isRunning());
}
@@ -96,7 +96,7 @@ public class TestDefaultBotSession {
session.setUpdatesSupplier(createFakeUpdatesSupplier(flag, updates));
session.start();
Thread.sleep(1000);
- Mockito.verify(bot, Mockito.never()).onUpdateReceived(Matchers.any());
+ Mockito.verify(bot, Mockito.never()).onUpdateReceived(any());
flag.compareAndSet(0, 1);
Thread.sleep(1000);
Mockito.verify(bot).onUpdateReceived(updates[0]);
@@ -124,7 +124,7 @@ public class TestDefaultBotSession {
session.setUpdatesSupplier(createFakeUpdatesSupplier(flag, updates));
session.start();
Thread.sleep(1000);
- Mockito.verify(bot, Mockito.never()).onUpdateReceived(Matchers.any());
+ Mockito.verify(bot, Mockito.never()).onUpdateReceived(any());
flag.compareAndSet(0, 1);
Thread.sleep(1000);
Mockito.verify(bot).onUpdatesReceived(Arrays.asList(updates[0], updates[1]));
@@ -146,18 +146,15 @@ public class TestDefaultBotSession {
}
private DefaultBotSession.UpdatesSupplier createFakeUpdatesSupplier(AtomicInteger flag, Update[] updates) {
- return new DefaultBotSession.UpdatesSupplier() {
- @Override
- public List getUpdates() throws InterruptedException, Exception {
- if (flag.compareAndSet(1, 2)) {
- return Arrays.asList(updates[0], updates[1]);
- } else if (flag.compareAndSet(3, 4)) {
- return Arrays.asList(updates[2], updates[3], updates[4]);
- } else if (flag.compareAndSet(5, 6)) {
- return Arrays.asList(updates[5], updates[6], updates[7], updates[8]);
- }
- return Collections.emptyList();
+ return () -> {
+ if (flag.compareAndSet(1, 2)) {
+ return Arrays.asList(updates[0], updates[1]);
+ } else if (flag.compareAndSet(3, 4)) {
+ return Arrays.asList(updates[2], updates[3], updates[4]);
+ } else if (flag.compareAndSet(5, 6)) {
+ return Arrays.asList(updates[5], updates[6], updates[7], updates[8]);
}
+ return Collections.emptyList();
};
}
@@ -172,7 +169,7 @@ public class TestDefaultBotSession {
response.setEntity(new StringEntity("{}"));
HttpClient mockHttpClient = Mockito.mock(HttpClient.class);
- Mockito.when(mockHttpClient.execute(Mockito.any(HttpPost.class)))
+ Mockito.when(mockHttpClient.execute(any(HttpPost.class)))
.thenReturn(response);
DefaultBotSession session = new DefaultBotSession();
session.setCallback(bot);