From b971b49f68b07b0284742cab425a7922019ccfb4 Mon Sep 17 00:00:00 2001 From: Varya Date: Sat, 27 Dec 2025 12:38:15 +0300 Subject: [PATCH] use cactoos Proc interface --- .../io/github/artemget/teleroute/bot/Bot.java | 43 ------------------- .../artemget/teleroute/bot/BotEnvelope.java | 9 ++-- .../teleroute/bot/BotEnvelopeTest.java | 8 ++-- 3 files changed, 9 insertions(+), 51 deletions(-) delete mode 100644 core/src/io/github/artemget/teleroute/bot/Bot.java diff --git a/core/src/io/github/artemget/teleroute/bot/Bot.java b/core/src/io/github/artemget/teleroute/bot/Bot.java deleted file mode 100644 index a01b6a2..0000000 --- a/core/src/io/github/artemget/teleroute/bot/Bot.java +++ /dev/null @@ -1,43 +0,0 @@ -/* - * MIT License - * - * Copyright (c) 2024-2026. Artem Getmanskii - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - * - */ - -package io.github.artemget.teleroute.bot; - -import io.github.artemget.teleroute.update.Wrap; - -/** - * Bot. Entrance to your bot construction. - * - * @param Update - * @since 2.0.0 - */ -public interface Bot { - /** - * Start handle update. - * - * @param update Update wrap - */ - void handle(Wrap update) throws Exception; -} diff --git a/core/src/io/github/artemget/teleroute/bot/BotEnvelope.java b/core/src/io/github/artemget/teleroute/bot/BotEnvelope.java index 8cd37db..1cdfffa 100644 --- a/core/src/io/github/artemget/teleroute/bot/BotEnvelope.java +++ b/core/src/io/github/artemget/teleroute/bot/BotEnvelope.java @@ -28,6 +28,7 @@ import io.github.artemget.teleroute.route.Route; import io.github.artemget.teleroute.route.RouteDfs; import io.github.artemget.teleroute.update.Wrap; +import org.cactoos.Proc; import org.cactoos.proc.CheckedProc; import org.cactoos.proc.UncheckedProc; import org.cactoos.scalar.Unchecked; @@ -39,7 +40,7 @@ * @param Client * @since 2.0.0 */ -public final class BotEnvelope implements Bot { +public final class BotEnvelope implements Proc> { /** * Client. */ @@ -73,11 +74,11 @@ public BotEnvelope(final C client, final Route route) { } @Override - public void handle(final Wrap update) throws Exception { + public void exec(final Wrap update) throws Exception { new CheckedProc<>( - (Wrap u) -> this.route.route(update) + (Wrap u) -> this.route.route(u) .map( - cmd -> new Unchecked<>(() -> cmd.execute(update.src())).value() + cmd -> new Unchecked<>(() -> cmd.execute(u.src())).value() ).ifPresent(send -> new UncheckedProc<>(send::send).exec(this.client)), ex -> new Exception("Failed to handle update", ex) ).exec(update); diff --git a/core/test/io/github/artemget/teleroute/bot/BotEnvelopeTest.java b/core/test/io/github/artemget/teleroute/bot/BotEnvelopeTest.java index f350b27..fcc42df 100644 --- a/core/test/io/github/artemget/teleroute/bot/BotEnvelopeTest.java +++ b/core/test/io/github/artemget/teleroute/bot/BotEnvelopeTest.java @@ -53,7 +53,7 @@ void handlesUpdateWhenRouteReturnsCommand() throws Exception { new FkSend("response") ) ) - ).handle(new FkWrap()); + ).exec(new FkWrap()); MatcherAssert.assertThat( "Did not send response", client.sent(), @@ -67,7 +67,7 @@ void handlesUpdateWhenRouteReturnsEmpty() throws Exception { new BotEnvelope<>(client, new RouteEnd<>( new FkCmd())) - .handle(new FkWrap()); + .exec(new FkWrap()); MatcherAssert.assertThat( "Sent response when route returned empty", client.sent().isEmpty(), @@ -84,7 +84,7 @@ void throwsExceptionWhenCommandExecutionFails() { )); Assertions.assertThrows( Exception.class, - () -> bot.handle(new FkWrap()), + () -> bot.exec(new FkWrap()), "Expected Exception when command execution fails" ); } @@ -102,7 +102,7 @@ void throwsExceptionWhenSendFails() { ); Assertions.assertThrows( Exception.class, - () -> bot.handle(new FkWrap()), + () -> bot.exec(new FkWrap()), "Expected Exception when send fails" ); }