From a8f8539ce0dd2d18c300adcbe2587bbe7492f235 Mon Sep 17 00:00:00 2001 From: Davide Polonio Date: Sun, 26 Mar 2023 21:13:01 +0200 Subject: [PATCH] chore: little cleanup --- .../com/github/polpetta/mezzotre/App.java | 6 +-- .../polpetta/mezzotre/route/Telegram.java | 8 --- .../mezzotre/telegram/command/Start.java | 2 +- .../route/TelegramIntegrationTest.java | 53 ++++++++++--------- 4 files changed, 29 insertions(+), 40 deletions(-) diff --git a/src/main/java/com/github/polpetta/mezzotre/App.java b/src/main/java/com/github/polpetta/mezzotre/App.java index d0cf1ff..c11e464 100644 --- a/src/main/java/com/github/polpetta/mezzotre/App.java +++ b/src/main/java/com/github/polpetta/mezzotre/App.java @@ -34,10 +34,6 @@ public class App extends Jooby { } public App(Stage runningEnv, Collection modules) { - // FIXME change it in some configuration file! - setName("Mezzotre"); - setVersion("1.0-SNAPSHOT"); - // END FIXME Collection toInject = new ArrayList<>(Optional.ofNullable(modules).orElse(Collections.emptySet())); @@ -51,7 +47,7 @@ public class App extends Jooby { install(new GuiceModule(injector)); // We need to do it here install(new BannerModule("Mezzotre")); - install(new OpenAPIModule()); + install(new OpenAPIModule("/docs")); install(new GsonModule()); install(injector.getInstance(Key.get(Extension.class, Names.named("hikariPoolExtension")))); install( diff --git a/src/main/java/com/github/polpetta/mezzotre/route/Telegram.java b/src/main/java/com/github/polpetta/mezzotre/route/Telegram.java index c2b62aa..9fb87da 100644 --- a/src/main/java/com/github/polpetta/mezzotre/route/Telegram.java +++ b/src/main/java/com/github/polpetta/mezzotre/route/Telegram.java @@ -3,10 +3,8 @@ package com.github.polpetta.mezzotre.route; import com.github.polpetta.mezzotre.orm.model.TgChat; import com.github.polpetta.mezzotre.orm.model.query.QTgChat; import com.github.polpetta.mezzotre.telegram.command.Router; -import com.github.polpetta.mezzotre.util.UUIDGenerator; import com.github.polpetta.types.json.ChatContext; import com.google.gson.Gson; -import com.pengrad.telegrambot.TelegramBot; import com.pengrad.telegrambot.model.Message; import com.pengrad.telegrambot.model.Update; import com.pengrad.telegrambot.request.BaseRequest; @@ -29,25 +27,19 @@ public class Telegram { static final String ENDPOINT = "tg"; private final Logger log; - private final TelegramBot bot; private final Gson gson; private final Executor completableFutureThreadPool; - private final UUIDGenerator uuidGenerator; private final Router router; @Inject public Telegram( Logger log, - TelegramBot bot, Gson gson, @Named("eventThreadPool") Executor completableFutureThreadPool, - UUIDGenerator uuidGenerator, Router router) { this.log = log; - this.bot = bot; this.gson = gson; this.completableFutureThreadPool = completableFutureThreadPool; - this.uuidGenerator = uuidGenerator; this.router = router; } diff --git a/src/main/java/com/github/polpetta/mezzotre/telegram/command/Start.java b/src/main/java/com/github/polpetta/mezzotre/telegram/command/Start.java index 1534b1a..268a9e5 100644 --- a/src/main/java/com/github/polpetta/mezzotre/telegram/command/Start.java +++ b/src/main/java/com/github/polpetta/mezzotre/telegram/command/Start.java @@ -2,7 +2,7 @@ package com.github.polpetta.mezzotre.telegram.command; import com.github.polpetta.mezzotre.i18n.LocalizedMessageFactory; import com.github.polpetta.mezzotre.orm.model.TgChat; -import com.github.polpetta.mezzotre.util.Clock;import com.github.polpetta.types.json.ChatContext; +import com.github.polpetta.types.json.ChatContext; import com.google.inject.Singleton; import com.pengrad.telegrambot.model.Update; import com.pengrad.telegrambot.model.request.ParseMode; diff --git a/src/test/java/com/github/polpetta/mezzotre/route/TelegramIntegrationTest.java b/src/test/java/com/github/polpetta/mezzotre/route/TelegramIntegrationTest.java index 37e564b..6949e95 100644 --- a/src/test/java/com/github/polpetta/mezzotre/route/TelegramIntegrationTest.java +++ b/src/test/java/com/github/polpetta/mezzotre/route/TelegramIntegrationTest.java @@ -1,13 +1,13 @@ package com.github.polpetta.mezzotre.route; import static org.junit.jupiter.api.Assertions.*; -import static org.mockito.ArgumentMatchers.any;import static org.mockito.Mockito.*; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.Mockito.*; import com.github.polpetta.mezzotre.helper.Loader; import com.github.polpetta.mezzotre.helper.TestConfig; import com.github.polpetta.mezzotre.orm.model.TgChat; import com.github.polpetta.mezzotre.telegram.command.Router; -import com.github.polpetta.mezzotre.util.UUIDGenerator; import com.google.gson.Gson; import com.google.gson.GsonBuilder; import com.pengrad.telegrambot.TelegramBot; @@ -15,11 +15,13 @@ import com.pengrad.telegrambot.model.Update; import com.pengrad.telegrambot.request.SendMessage; import com.pengrad.telegrambot.response.SendResponse; import io.ebean.Database; +import io.jooby.Context; +import io.jooby.MediaType; import java.util.Optional; import java.util.concurrent.CompletableFuture; import java.util.concurrent.Executors; import java.util.concurrent.TimeUnit; -import io.jooby.Context;import io.jooby.MediaType;import org.junit.jupiter.api.*; +import org.junit.jupiter.api.*; import org.slf4j.LoggerFactory; import org.testcontainers.containers.PostgreSQLContainer; import org.testcontainers.junit.jupiter.Container; @@ -57,10 +59,8 @@ class TelegramIntegrationTest { telegram = new Telegram( LoggerFactory.getLogger(getClass()), - fakeTelegramBot, new GsonBuilder().setPrettyPrinting().create(), Executors.newSingleThreadExecutor(), - new UUIDGenerator(), fakeRouter); } @@ -78,27 +78,28 @@ class TelegramIntegrationTest { final Context fakeContext = mock(Context.class); final Update update = gson.fromJson( - "{\n" - + "\"update_id\":10000,\n" - + "\"message\":{\n" - + " \"date\":1441645532,\n" - + " \"chat\":{\n" - + " \"last_name\":\"Test Lastname\",\n" - + " \"id\":1111111,\n" - + " \"type\": \"private\",\n" - + " \"first_name\":\"Test Firstname\",\n" - + " \"username\":\"Testusername\"\n" - + " },\n" - + " \"message_id\":1365,\n" - + " \"from\":{\n" - + " \"last_name\":\"Test Lastname\",\n" - + " \"id\":1111111,\n" - + " \"first_name\":\"Test Firstname\",\n" - + " \"username\":\"Testusername\"\n" - + " },\n" - + " \"text\":\"/start\"\n" - + "}\n" - + "}", + """ +{ +"update_id":10000, +"message":{ + "date":1441645532, + "chat":{ + "last_name":"Test Lastname", + "id":1111111, + "type": "private", + "first_name":"Test Firstname", + "username":"Testusername" + }, + "message_id":1365, + "from":{ + "last_name":"Test Lastname", + "id":1111111, + "first_name":"Test Firstname", + "username":"Testusername" + }, + "text":"/start" +} +}""", Update.class); final CompletableFuture integerCompletableFuture = telegram.incomingUpdate(fakeContext, update); verify(fakeContext, times(1)).setResponseType(MediaType.JSON);