Skip to content

Commit 3c62b1d

Browse files
Fix rogue api requests that spammed the logs during tests
1 parent 3ed8921 commit 3c62b1d

File tree

4 files changed

+171
-148
lines changed

4 files changed

+171
-148
lines changed

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

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@
4848
*
4949
* @author Roberto Cella
5050
*/
51-
public record Stickerify(TelegramBot bot, Executor executor) implements UpdatesListener, ExceptionHandler {
51+
public record Stickerify(TelegramBot bot, Executor executor) implements UpdatesListener, ExceptionHandler, AutoCloseable {
5252

5353
private static final Logger LOGGER = LoggerFactory.getLogger(Stickerify.class);
5454
private static final String BOT_TOKEN = System.getenv("STICKERIFY_TOKEN");
@@ -91,6 +91,12 @@ public void onException(TelegramException e) {
9191
LOGGER.atError().log("There was an unexpected failure: {}", e.getMessage());
9292
}
9393

94+
@Override
95+
public void close() {
96+
bot.removeGetUpdatesListener();
97+
bot.shutdown();
98+
}
99+
94100
private void answer(TelegramRequest request) {
95101
var file = request.getFile();
96102

src/main/java/com/github/stickerifier/stickerify/runner/Main.java

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,15 @@
33
import com.github.stickerifier.stickerify.bot.Stickerify;
44

55
public class Main {
6+
static final Object LOCK = new Object();
7+
68
public static void main(String[] args) {
7-
new Stickerify();
9+
try (var _ = new Stickerify()) {
10+
synchronized (LOCK) {
11+
LOCK.wait();
12+
}
13+
} catch (InterruptedException e) {
14+
Thread.currentThread().interrupt();
15+
}
816
}
917
}

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,12 @@
88

99
public final class MockResponses {
1010

11+
static final MockResponse EMPTY_UPDATES = new MockResponse.Builder().body("""
12+
{
13+
ok: true
14+
}
15+
""").build();
16+
1117
static final MockResponse START_MESSAGE = new MockResponse.Builder().body("""
1218
{
1319
ok: true,

0 commit comments

Comments
 (0)