Fix text to Junit5
This commit is contained in:
parent
d7875bba34
commit
b19ae64899
72
Bots.ipr
72
Bots.ipr
@ -22,10 +22,10 @@
|
||||
<sourceOutputDir name="target/generated-sources/annotations" />
|
||||
<sourceTestOutputDir name="target/generated-test-sources/test-annotations" />
|
||||
<outputRelativeToContentRoot value="true" />
|
||||
<module name="telegrambots-meta" />
|
||||
<module name="telegrambots-extensions" />
|
||||
<module name="telegrambots" />
|
||||
<module name="telegrambots-abilities" />
|
||||
<module name="telegrambots-extensions" />
|
||||
<module name="telegrambots-meta" />
|
||||
<module name="telegrambots" />
|
||||
<module name="telegrambots-chat-session-bot" />
|
||||
<module name="telegrambots-spring-boot-starter" />
|
||||
</profile>
|
||||
@ -1514,6 +1514,17 @@
|
||||
<root url="jar://$MAVEN_REPOSITORY$/org/glassfish/grizzly/grizzly-http/2.4.4/grizzly-http-2.4.4-sources.jar!/" />
|
||||
</SOURCES>
|
||||
</library>
|
||||
<library name="Maven: org.glassfish.hk2.external:aopalliance-repackaged:2.5.0">
|
||||
<CLASSES>
|
||||
<root url="jar://$MAVEN_REPOSITORY$/org/glassfish/hk2/external/aopalliance-repackaged/2.5.0/aopalliance-repackaged-2.5.0.jar!/" />
|
||||
</CLASSES>
|
||||
<JAVADOC>
|
||||
<root url="jar://$MAVEN_REPOSITORY$/org/glassfish/hk2/external/aopalliance-repackaged/2.5.0/aopalliance-repackaged-2.5.0-javadoc.jar!/" />
|
||||
</JAVADOC>
|
||||
<SOURCES>
|
||||
<root url="jar://$MAVEN_REPOSITORY$/org/glassfish/hk2/external/aopalliance-repackaged/2.5.0/aopalliance-repackaged-2.5.0-sources.jar!/" />
|
||||
</SOURCES>
|
||||
</library>
|
||||
<library name="Maven: org.glassfish.hk2.external:jakarta.inject:2.5.0">
|
||||
<CLASSES>
|
||||
<root url="jar://$MAVEN_REPOSITORY$/org/glassfish/hk2/external/jakarta.inject/2.5.0/jakarta.inject-2.5.0.jar!/" />
|
||||
@ -1525,6 +1536,39 @@
|
||||
<root url="jar://$MAVEN_REPOSITORY$/org/glassfish/hk2/external/jakarta.inject/2.5.0/jakarta.inject-2.5.0-sources.jar!/" />
|
||||
</SOURCES>
|
||||
</library>
|
||||
<library name="Maven: org.glassfish.hk2:hk2-api:2.5.0">
|
||||
<CLASSES>
|
||||
<root url="jar://$MAVEN_REPOSITORY$/org/glassfish/hk2/hk2-api/2.5.0/hk2-api-2.5.0.jar!/" />
|
||||
</CLASSES>
|
||||
<JAVADOC>
|
||||
<root url="jar://$MAVEN_REPOSITORY$/org/glassfish/hk2/hk2-api/2.5.0/hk2-api-2.5.0-javadoc.jar!/" />
|
||||
</JAVADOC>
|
||||
<SOURCES>
|
||||
<root url="jar://$MAVEN_REPOSITORY$/org/glassfish/hk2/hk2-api/2.5.0/hk2-api-2.5.0-sources.jar!/" />
|
||||
</SOURCES>
|
||||
</library>
|
||||
<library name="Maven: org.glassfish.hk2:hk2-locator:2.5.0">
|
||||
<CLASSES>
|
||||
<root url="jar://$MAVEN_REPOSITORY$/org/glassfish/hk2/hk2-locator/2.5.0/hk2-locator-2.5.0.jar!/" />
|
||||
</CLASSES>
|
||||
<JAVADOC>
|
||||
<root url="jar://$MAVEN_REPOSITORY$/org/glassfish/hk2/hk2-locator/2.5.0/hk2-locator-2.5.0-javadoc.jar!/" />
|
||||
</JAVADOC>
|
||||
<SOURCES>
|
||||
<root url="jar://$MAVEN_REPOSITORY$/org/glassfish/hk2/hk2-locator/2.5.0/hk2-locator-2.5.0-sources.jar!/" />
|
||||
</SOURCES>
|
||||
</library>
|
||||
<library name="Maven: org.glassfish.hk2:hk2-utils:2.5.0">
|
||||
<CLASSES>
|
||||
<root url="jar://$MAVEN_REPOSITORY$/org/glassfish/hk2/hk2-utils/2.5.0/hk2-utils-2.5.0.jar!/" />
|
||||
</CLASSES>
|
||||
<JAVADOC>
|
||||
<root url="jar://$MAVEN_REPOSITORY$/org/glassfish/hk2/hk2-utils/2.5.0/hk2-utils-2.5.0-javadoc.jar!/" />
|
||||
</JAVADOC>
|
||||
<SOURCES>
|
||||
<root url="jar://$MAVEN_REPOSITORY$/org/glassfish/hk2/hk2-utils/2.5.0/hk2-utils-2.5.0-sources.jar!/" />
|
||||
</SOURCES>
|
||||
</library>
|
||||
<library name="Maven: org.glassfish.hk2:osgi-resource-locator:1.0.3">
|
||||
<CLASSES>
|
||||
<root url="jar://$MAVEN_REPOSITORY$/org/glassfish/hk2/osgi-resource-locator/1.0.3/osgi-resource-locator-1.0.3.jar!/" />
|
||||
@ -1624,6 +1668,17 @@
|
||||
<root url="jar://$MAVEN_REPOSITORY$/org/glassfish/jersey/ext/jersey-entity-filtering/2.29/jersey-entity-filtering-2.29-sources.jar!/" />
|
||||
</SOURCES>
|
||||
</library>
|
||||
<library name="Maven: org.glassfish.jersey.inject:jersey-hk2:2.29">
|
||||
<CLASSES>
|
||||
<root url="jar://$MAVEN_REPOSITORY$/org/glassfish/jersey/inject/jersey-hk2/2.29/jersey-hk2-2.29.jar!/" />
|
||||
</CLASSES>
|
||||
<JAVADOC>
|
||||
<root url="jar://$MAVEN_REPOSITORY$/org/glassfish/jersey/inject/jersey-hk2/2.29/jersey-hk2-2.29-javadoc.jar!/" />
|
||||
</JAVADOC>
|
||||
<SOURCES>
|
||||
<root url="jar://$MAVEN_REPOSITORY$/org/glassfish/jersey/inject/jersey-hk2/2.29/jersey-hk2-2.29-sources.jar!/" />
|
||||
</SOURCES>
|
||||
</library>
|
||||
<library name="Maven: org.glassfish.jersey.media:jersey-media-jaxb:2.29">
|
||||
<CLASSES>
|
||||
<root url="jar://$MAVEN_REPOSITORY$/org/glassfish/jersey/media/jersey-media-jaxb/2.29/jersey-media-jaxb-2.29.jar!/" />
|
||||
@ -1679,6 +1734,17 @@
|
||||
<root url="jar://$MAVEN_REPOSITORY$/org/hamcrest/hamcrest-core/1.3/hamcrest-core-1.3-sources.jar!/" />
|
||||
</SOURCES>
|
||||
</library>
|
||||
<library name="Maven: org.javassist:javassist:3.22.0-CR2">
|
||||
<CLASSES>
|
||||
<root url="jar://$MAVEN_REPOSITORY$/org/javassist/javassist/3.22.0-CR2/javassist-3.22.0-CR2.jar!/" />
|
||||
</CLASSES>
|
||||
<JAVADOC>
|
||||
<root url="jar://$MAVEN_REPOSITORY$/org/javassist/javassist/3.22.0-CR2/javassist-3.22.0-CR2-javadoc.jar!/" />
|
||||
</JAVADOC>
|
||||
<SOURCES>
|
||||
<root url="jar://$MAVEN_REPOSITORY$/org/javassist/javassist/3.22.0-CR2/javassist-3.22.0-CR2-sources.jar!/" />
|
||||
</SOURCES>
|
||||
</library>
|
||||
<library name="Maven: org.jetbrains.kotlin:kotlin-stdlib-common:1.2.71">
|
||||
<CLASSES>
|
||||
<root url="jar://$MAVEN_REPOSITORY$/org/jetbrains/kotlin/kotlin-stdlib-common/1.2.71/kotlin-stdlib-common-1.2.71.jar!/" />
|
||||
|
6
pom.xml
6
pom.xml
@ -55,6 +55,12 @@
|
||||
<version>${mockito.version}</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.mockito</groupId>
|
||||
<artifactId>mockito-junit-jupiter</artifactId>
|
||||
<version>${mockito.version}</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.fasterxml.jackson.core</groupId>
|
||||
<artifactId>jackson-annotations</artifactId>
|
||||
|
@ -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";
|
||||
|
@ -117,6 +117,11 @@
|
||||
<artifactId>jackson-databind</artifactId>
|
||||
<version>${jackson.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.glassfish.jersey.inject</groupId>
|
||||
<artifactId>jersey-hk2</artifactId>
|
||||
<version>${glassfish.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.glassfish.jersey.media</groupId>
|
||||
<artifactId>jersey-media-json-jackson</artifactId>
|
||||
|
@ -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);
|
||||
|
||||
|
@ -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);
|
||||
|
@ -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<String> 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<File> 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<Exception> exceptionArgumentCaptor = ArgumentCaptor.forClass(Exception.class);
|
||||
|
||||
when(httpResponseMock.getStatusLine()).thenReturn(new BasicStatusLine(HTTP_1_1, 500, "emptyString"));
|
||||
|
@ -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();
|
||||
|
@ -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<Update> 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);
|
||||
|
Loading…
Reference in New Issue
Block a user