Skip to content

Commit 44501d9

Browse files
committed
Add two types of downloadFileAsStream tests
1 parent 7dc3c33 commit 44501d9

2 files changed

Lines changed: 44 additions & 4 deletions

File tree

telegrambots-client-jetty-adapter/src/test/java/org/telegram/telegrambots/client/TestTelegramClientIntegration.java

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,14 @@
2121
import org.telegram.telegrambots.meta.exceptions.TelegramApiRequestException;
2222

2323
import java.io.File;
24+
import java.io.IOException;
2425
import java.io.InputStream;
2526
import java.io.Serializable;
2627
import java.nio.charset.StandardCharsets;
2728

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

30-
public class TestTelegramClientIntegration {
31+
class TestTelegramClientIntegration {
3132
private MockWebServer webServer;
3233

3334
private static final String TOKEN = "testToken";
@@ -171,6 +172,20 @@ void testDownloadFileAsStream() throws Exception {
171172
}
172173
}
173174

175+
@Test
176+
void testDownloadFileAsStreamFuture() {
177+
client.downloadFileAsStreamAsync("someFile").thenAccept(is -> {
178+
String text = null;
179+
try {
180+
text = new String(is.readAllBytes(), StandardCharsets.UTF_8);
181+
} catch (IOException e) {
182+
throw new RuntimeException(e);
183+
}
184+
assertNotNull(text);
185+
assertFalse(text.isEmpty());
186+
});
187+
}
188+
174189
@Test
175190
void testSendMessageException() {
176191
SendMessage method = new SendMessage("someChatId", "someText");

telegrambots-client/src/test/java/org/telegram/telegrambots/client/TestTelegramClientIntegration.java

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,13 @@
2929
import org.telegram.telegrambots.meta.exceptions.TelegramApiRequestException;
3030

3131
import java.io.File;
32+
import java.io.IOException;
33+
import java.io.InputStream;
3234
import java.io.Serializable;
35+
import java.nio.charset.StandardCharsets;
36+
import static org.junit.jupiter.api.Assertions.*;
3337

34-
import static org.junit.jupiter.api.Assertions.assertEquals;
35-
36-
public class TestTelegramClientIntegration {
38+
class TestTelegramClientIntegration {
3739
private MockWebServer webServer;
3840

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

173+
@Test
174+
void testDownloadFileAsStream() throws Exception {
175+
try (InputStream is = client.downloadFileAsStream("someFile")) {
176+
String text = new String(is.readAllBytes(), StandardCharsets.UTF_8);
177+
assertNotNull(text);
178+
assertFalse(text.isEmpty());
179+
}
180+
}
181+
182+
@Test
183+
void testDownloadFileAsStreamFuture() throws Exception {
184+
client.downloadFileAsStreamAsync("someFile").thenAccept(is -> {
185+
String text = null;
186+
try {
187+
text = new String(is.readAllBytes(), StandardCharsets.UTF_8);
188+
} catch (IOException e) {
189+
throw new RuntimeException(e);
190+
}
191+
assertNotNull(text);
192+
assertFalse(text.isEmpty());
193+
}).get();
194+
}
195+
171196
@Test
172197
void testSendMessageException() {
173198
SendMessage method = new SendMessage("someChatId", "someText");

0 commit comments

Comments
 (0)