Skip to content

Commit 78ad19e

Browse files
authored
Merge pull request #43 from VaryaGet/main
Use cactoos Proc interface instead of Bot
2 parents 5b962e3 + b971b49 commit 78ad19e

File tree

3 files changed

+9
-51
lines changed

3 files changed

+9
-51
lines changed

core/src/io/github/artemget/teleroute/bot/Bot.java

Lines changed: 0 additions & 43 deletions
This file was deleted.

core/src/io/github/artemget/teleroute/bot/BotEnvelope.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
import io.github.artemget.teleroute.route.Route;
2929
import io.github.artemget.teleroute.route.RouteDfs;
3030
import io.github.artemget.teleroute.update.Wrap;
31+
import org.cactoos.Proc;
3132
import org.cactoos.proc.CheckedProc;
3233
import org.cactoos.proc.UncheckedProc;
3334
import org.cactoos.scalar.Unchecked;
@@ -39,7 +40,7 @@
3940
* @param <C> Client
4041
* @since 2.0.0
4142
*/
42-
public final class BotEnvelope<U, C> implements Bot<U> {
43+
public final class BotEnvelope<U, C> implements Proc<Wrap<U>> {
4344
/**
4445
* Client.
4546
*/
@@ -73,11 +74,11 @@ public BotEnvelope(final C client, final Route<U, C> route) {
7374
}
7475

7576
@Override
76-
public void handle(final Wrap<U> update) throws Exception {
77+
public void exec(final Wrap<U> update) throws Exception {
7778
new CheckedProc<>(
78-
(Wrap<U> u) -> this.route.route(update)
79+
(Wrap<U> u) -> this.route.route(u)
7980
.map(
80-
cmd -> new Unchecked<>(() -> cmd.execute(update.src())).value()
81+
cmd -> new Unchecked<>(() -> cmd.execute(u.src())).value()
8182
).ifPresent(send -> new UncheckedProc<>(send::send).exec(this.client)),
8283
ex -> new Exception("Failed to handle update", ex)
8384
).exec(update);

core/test/io/github/artemget/teleroute/bot/BotEnvelopeTest.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ void handlesUpdateWhenRouteReturnsCommand() throws Exception {
5353
new FkSend("response")
5454
)
5555
)
56-
).handle(new FkWrap());
56+
).exec(new FkWrap());
5757
MatcherAssert.assertThat(
5858
"Did not send response",
5959
client.sent(),
@@ -67,7 +67,7 @@ void handlesUpdateWhenRouteReturnsEmpty() throws Exception {
6767
new BotEnvelope<>(client,
6868
new RouteEnd<>(
6969
new FkCmd()))
70-
.handle(new FkWrap());
70+
.exec(new FkWrap());
7171
MatcherAssert.assertThat(
7272
"Sent response when route returned empty",
7373
client.sent().isEmpty(),
@@ -84,7 +84,7 @@ void throwsExceptionWhenCommandExecutionFails() {
8484
));
8585
Assertions.assertThrows(
8686
Exception.class,
87-
() -> bot.handle(new FkWrap()),
87+
() -> bot.exec(new FkWrap()),
8888
"Expected Exception when command execution fails"
8989
);
9090
}
@@ -102,7 +102,7 @@ void throwsExceptionWhenSendFails() {
102102
);
103103
Assertions.assertThrows(
104104
Exception.class,
105-
() -> bot.handle(new FkWrap()),
105+
() -> bot.exec(new FkWrap()),
106106
"Expected Exception when send fails"
107107
);
108108
}

0 commit comments

Comments
 (0)