From 7689a7bccaa497114f60b681d9c638b2f64a2413 Mon Sep 17 00:00:00 2001 From: Abbas Abou Daya Date: Mon, 30 Oct 2017 21:32:34 -0400 Subject: [PATCH] Proofreading --- TelegramBots.wiki/abilities/Bot-Testing.md | 27 ++++++++++++++++--- .../abilities/Database-Handling.md | 2 +- TelegramBots.wiki/abilities/Using-Replies.md | 2 +- 3 files changed, 26 insertions(+), 5 deletions(-) diff --git a/TelegramBots.wiki/abilities/Bot-Testing.md b/TelegramBots.wiki/abilities/Bot-Testing.md index a0b3d089..603ec281 100644 --- a/TelegramBots.wiki/abilities/Bot-Testing.md +++ b/TelegramBots.wiki/abilities/Bot-Testing.md @@ -18,7 +18,7 @@ public void sayHello() { } ``` -This is how you would define a method that says hello in the basic API. How do you go around testing it? If you do attempt to Junit test this method, what will you be testing? If change the method signature to return the string sent, then you can test the hello message content. However, can you test that you've actually `executed` the command? +This is how you would define a method that says hello in the basic API. How do you go around testing it? If you do attempt to Junit test this method, what will you be testing? If you change the method signature to return the string sent, then you can test the hello message content. However, can you test that you've actually `executed` the command? ## Mock Testing *This section assumes you're familiar with mock testing. Mock testing is basically replacing a real object X with a fake object Y (a mock) of the same type. By doing that, you're able to test whether certain functions were executed.* @@ -28,9 +28,11 @@ Obviously, you can't, but there's a twist to it. You can always mock the whole b ## MessageSender Interface All ability bots declare two utility objects. ### The Sender Object -The sender object is an implementation of the [MessageSender](../../telegrambots-abilities/src/main/java/org/telegram/abilitybots/api/sender/MessageSender.java) interface. The interface mirrors +The `sender` object is an implementation of the [MessageSender](../../telegrambots-abilities/src/main/java/org/telegram/abilitybots/api/sender/MessageSender.java) interface. The interface mirrors all the bot sending methods. A user can supply his own MessageSender, but the AbilityBot module specifies a [DefaultSender](../../telegrambots-abilities/src/main/java/org/telegram/abilitybots/api/sender/DefaultSender.java) As you might guess, the default sender is simply a proxy for the bot API methods. +### The Silent Object +The `silent` object is exactly like the sender object, but silent. Its methods return `Optional`. On exception, it will be an empty optional. The sender object is provided to reduce verboseness of the code (reducing try-catch blocks with something more elegant). ## AbilityBot Testing Let's suppose that you have an ability that says "Hello World!" declared as such: ```java @@ -169,4 +171,23 @@ public class ExampleBotTest { ``` ## Silent Testing -As mentioned before, we also have another object that is able to send messages silently called `silent`. If you're using this object, you will also need to mock it and use it in the test. It is handled in exactly the same way. \ No newline at end of file +As mentioned before, we also have another object that is able to send messages silently called `silent`. The constructor of the silent sender requires a MessageSender object. If your abilities use the `silent` object, be sure to: +```java +public class ExampleBotTest { + ... + private DBContext db; + private MessageSender sender; + +@Before + public void setUp() { + bot = new ExampleBot(db); + sender = mock(MessageSender.class); + bot.silent = new SilentSender(sender); + ... + } + + ... +} +``` + +Do note that in your test assertions, don't use the silent object. Mocked assertion require the mock object. If you recall, the silent object uses the sender object, so your tests will still be correct if you're asserting on the `sender` object rather than the silent one. \ No newline at end of file diff --git a/TelegramBots.wiki/abilities/Database-Handling.md b/TelegramBots.wiki/abilities/Database-Handling.md index 69a59a62..9681e739 100644 --- a/TelegramBots.wiki/abilities/Database-Handling.md +++ b/TelegramBots.wiki/abilities/Database-Handling.md @@ -3,7 +3,7 @@ AbilityBots come with an embedded DB. Users are free to implement their own data The abstraction has multiple constructors to accommodate user-defined implementations of [DBContext](../../telegrambots-abilities/src/main/java/org/telegram/abilitybots/api/db/DBContext.java) and [MessageSender](../../telegrambots-abilities/src/main/java/org/telegram/abilitybots/api/sender/MessageSender.java). We'll talk about the message sender interface in the [[Bot Testing|Bot-Testing]] section. ## Example -We'll be introducing an ability that maintains a special counter for every user. At every /increment, the user will receive a message with the previous number + 1. We'll initially start from zero and increment onwards. +We'll be introducing an ability that maintains a special counter for every user. At every /increment, the user will receive a message with the previous number + 1. We'll initially start from zero and increment upwards. ```java /** diff --git a/TelegramBots.wiki/abilities/Using-Replies.md b/TelegramBots.wiki/abilities/Using-Replies.md index d9b1c6ef..314dbeb7 100644 --- a/TelegramBots.wiki/abilities/Using-Replies.md +++ b/TelegramBots.wiki/abilities/Using-Replies.md @@ -73,5 +73,5 @@ public Ability playWithMe() { ``` In this example, we showcase how we can supply our own predicates. The two new predicates are `isReplyToMessage` and `isReplyToBot`. -The checks are made so that, once you execute your logic there is not need to check for the validity of the reply. +The checks are made so that, once you execute your logic there is no need to check for the validity of the reply. They were all made once the action logic is being executed. \ No newline at end of file