Skip to content

Commit

Permalink
Add two types of downloadFileAsStream tests
Browse files Browse the repository at this point in the history
  • Loading branch information
aNNiMON committed Dec 31, 2024
1 parent 1d77e4d commit 0944005
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,14 @@
import org.telegram.telegrambots.meta.exceptions.TelegramApiRequestException;

import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.io.Serializable;
import java.nio.charset.StandardCharsets;

import static org.junit.jupiter.api.Assertions.*;

public class TestTelegramClientIntegration {
class TestTelegramClientIntegration {
private MockWebServer webServer;

private static final String TOKEN = "testToken";
Expand Down Expand Up @@ -171,6 +172,20 @@ void testDownloadFileAsStream() throws Exception {
}
}

@Test
void testDownloadFileAsStreamFuture() {
client.downloadFileAsStreamAsync("someFile").thenAccept(is -> {
String text = null;
try {
text = new String(is.readAllBytes(), StandardCharsets.UTF_8);
} catch (IOException e) {
throw new RuntimeException(e);
}
assertNotNull(text);
assertFalse(text.isEmpty());
});
}

@Test
void testSendMessageException() {
SendMessage method = new SendMessage("someChatId", "someText");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,13 @@
import org.telegram.telegrambots.meta.exceptions.TelegramApiRequestException;

import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.io.Serializable;
import java.nio.charset.StandardCharsets;
import static org.junit.jupiter.api.Assertions.*;

import static org.junit.jupiter.api.Assertions.assertEquals;

public class TestTelegramClientIntegration {
class TestTelegramClientIntegration {
private MockWebServer webServer;

private static final String TOKEN = "testToken";
Expand Down Expand Up @@ -168,6 +170,29 @@ void testSendAnimation() throws TelegramApiException {
assertEquals(responseMessage, parsedMessage);
}

@Test
void testDownloadFileAsStream() throws Exception {
try (InputStream is = client.downloadFileAsStream("someFile")) {
String text = new String(is.readAllBytes(), StandardCharsets.UTF_8);
assertNotNull(text);
assertFalse(text.isEmpty());
}
}

@Test
void testDownloadFileAsStreamFuture() throws Exception {
client.downloadFileAsStreamAsync("someFile").thenAccept(is -> {
String text = null;
try {
text = new String(is.readAllBytes(), StandardCharsets.UTF_8);
} catch (IOException e) {
throw new RuntimeException(e);
}
assertNotNull(text);
assertFalse(text.isEmpty());
}).get();
}

@Test
void testSendMessageException() {
SendMessage method = new SendMessage("someChatId", "someText");
Expand Down

0 comments on commit 0944005

Please sign in to comment.