Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 0 additions & 43 deletions core/src/io/github/artemget/teleroute/bot/Bot.java

This file was deleted.

9 changes: 5 additions & 4 deletions core/src/io/github/artemget/teleroute/bot/BotEnvelope.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -39,7 +40,7 @@
* @param <C> Client
* @since 2.0.0
*/
public final class BotEnvelope<U, C> implements Bot<U> {
public final class BotEnvelope<U, C> implements Proc<Wrap<U>> {
/**
* Client.
*/
Expand Down Expand Up @@ -73,11 +74,11 @@ public BotEnvelope(final C client, final Route<U, C> route) {
}

@Override
public void handle(final Wrap<U> update) throws Exception {
public void exec(final Wrap<U> update) throws Exception {
new CheckedProc<>(
(Wrap<U> u) -> this.route.route(update)
(Wrap<U> 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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand All @@ -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(),
Expand All @@ -84,7 +84,7 @@ void throwsExceptionWhenCommandExecutionFails() {
));
Assertions.assertThrows(
Exception.class,
() -> bot.handle(new FkWrap()),
() -> bot.exec(new FkWrap()),
"Expected Exception when command execution fails"
);
}
Expand All @@ -102,7 +102,7 @@ void throwsExceptionWhenSendFails() {
);
Assertions.assertThrows(
Exception.class,
() -> bot.handle(new FkWrap()),
() -> bot.exec(new FkWrap()),
"Expected Exception when send fails"
);
}
Expand Down