Skip to content

Commit 5a25e1e

Browse files
Implement suggestions
1 parent 19da780 commit 5a25e1e

File tree

6 files changed

+75
-54
lines changed

6 files changed

+75
-54
lines changed

src/main/java/com/github/stickerifier/stickerify/bot/Stickerify.java

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
import com.github.stickerifier.stickerify.telegram.model.TelegramRequest;
2121
import com.pengrad.telegrambot.ExceptionHandler;
2222
import com.pengrad.telegrambot.TelegramBot;
23+
import com.pengrad.telegrambot.TelegramException;
2324
import com.pengrad.telegrambot.UpdatesListener;
2425
import com.pengrad.telegrambot.model.LinkPreviewOptions;
2526
import com.pengrad.telegrambot.model.Update;
@@ -47,7 +48,7 @@
4748
*
4849
* @author Roberto Cella
4950
*/
50-
public record Stickerify(TelegramBot bot, Executor executor) {
51+
public record Stickerify(TelegramBot bot, Executor executor) implements ExceptionHandler {
5152

5253
private static final Logger LOGGER = LoggerFactory.getLogger(Stickerify.class);
5354
private static final String BOT_TOKEN = System.getenv("STICKERIFY_TOKEN");
@@ -67,13 +68,13 @@ public Stickerify() {
6768
*
6869
* @see Stickerify
6970
*/
70-
public Stickerify(TelegramBot bot, Executor executor) {
71-
this.bot = bot;
72-
this.executor = executor;
73-
74-
ExceptionHandler exceptionHandler = e -> LOGGER.atError().log("There was an unexpected failure: {}", e.getMessage());
71+
public Stickerify {
72+
bot.setUpdatesListener(this::handleUpdates, this, new GetUpdates().timeout(50));
73+
}
7574

76-
bot.setUpdatesListener(this::handleUpdates, exceptionHandler, new GetUpdates().timeout(50));
75+
@Override
76+
public void onException(TelegramException e) {
77+
LOGGER.atError().log("There was an unexpected failure: {}", e.getMessage());
7778
}
7879

7980
private int handleUpdates(List<Update> updates) {

src/test/java/com/github/stickerifier/stickerify/bot/StickerifyTest.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import static org.junit.jupiter.api.Assertions.assertNotNull;
99

1010
import com.github.stickerifier.stickerify.junit.ClearTempFiles;
11+
import com.github.stickerifier.stickerify.junit.Tags;
1112
import com.github.stickerifier.stickerify.telegram.Answer;
1213
import com.pengrad.telegrambot.TelegramBot;
1314
import mockwebserver3.MockWebServer;
@@ -18,7 +19,7 @@
1819

1920
import java.net.URLEncoder;
2021

21-
@Tag("telegramApi")
22+
@Tag(Tags.TELEGRAM_API)
2223
@ClearTempFiles
2324
class StickerifyTest {
2425

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
package com.github.stickerifier.stickerify.junit;
2+
3+
public interface Tags {
4+
String ANIMATED_STICKER = "AnimatedSticker";
5+
String CONCURRENT = "concurrent";
6+
String IMAGE = "Image";
7+
String LOG = "Log";
8+
String MEDIA = "Media";
9+
String TELEGRAM_API = "TelegramApi";
10+
String UNSUPPORTED_FILE = "unsupportedFile";
11+
String VIDEO = "video";
12+
}

src/test/java/com/github/stickerifier/stickerify/logger/ExceptionHighlighterTest.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,13 @@
99
import static org.hamcrest.Matchers.equalTo;
1010
import static org.hamcrest.Matchers.is;
1111

12+
import com.github.stickerifier.stickerify.junit.Tags;
1213
import org.junit.jupiter.api.BeforeEach;
1314
import org.junit.jupiter.api.DisplayName;
1415
import org.junit.jupiter.api.Tag;
1516
import org.junit.jupiter.api.Test;
1617

17-
@Tag("log")
18+
@Tag(Tags.LOG)
1819
class ExceptionHighlighterTest {
1920

2021
private static final String LOG_MESSAGE = "Received request";

src/test/java/com/github/stickerifier/stickerify/logger/MessageHighlighterTest.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,13 @@
88
import static org.hamcrest.Matchers.equalTo;
99
import static org.hamcrest.Matchers.is;
1010

11+
import com.github.stickerifier.stickerify.junit.Tags;
1112
import org.junit.jupiter.api.BeforeEach;
1213
import org.junit.jupiter.api.DisplayName;
1314
import org.junit.jupiter.api.Tag;
1415
import org.junit.jupiter.api.Test;
1516

16-
@Tag("log")
17+
@Tag(Tags.LOG)
1718
class MessageHighlighterTest {
1819

1920
private static final String LOG_MESSAGE = "Received request";

0 commit comments

Comments
 (0)