From 16388e4721817c9e2138eb9470f6d64d2409c6db Mon Sep 17 00:00:00 2001 From: tastybento Date: Sat, 9 Mar 2019 16:42:46 -0800 Subject: [PATCH] Added Notifier test class --- .../bentobox/api/user/NotifierTest.java | 80 +++++++++++++++++++ 1 file changed, 80 insertions(+) create mode 100644 src/test/java/world/bentobox/bentobox/api/user/NotifierTest.java diff --git a/src/test/java/world/bentobox/bentobox/api/user/NotifierTest.java b/src/test/java/world/bentobox/bentobox/api/user/NotifierTest.java new file mode 100644 index 000000000..5ab7b20b7 --- /dev/null +++ b/src/test/java/world/bentobox/bentobox/api/user/NotifierTest.java @@ -0,0 +1,80 @@ +package world.bentobox.bentobox.api.user; + +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; +import static org.mockito.Mockito.mock; + +import org.junit.After; +import org.junit.Before; +import org.junit.Test; +import org.mockito.Mockito; + +/** + * @author tastybento + * + */ +public class NotifierTest { + + private Notifier n; + + /** + * @throws java.lang.Exception + */ + @Before + public void setUp() throws Exception { + n = new Notifier(); + } + + /** + * @throws java.lang.Exception + */ + @After + public void tearDown() throws Exception { + } + + /** + * Test method for {@link world.bentobox.bentobox.api.user.Notifier#notify(world.bentobox.bentobox.api.user.User, java.lang.String)}. + */ + @Test + public void testNotifyUserString() { + User user = mock(User.class); + String message = "a message"; + assertTrue(n.notify(user, message)); + Mockito.verify(user).sendRawMessage(message); + } + + /** + * Test method for {@link world.bentobox.bentobox.api.user.Notifier#notify(world.bentobox.bentobox.api.user.User, java.lang.String)}. + */ + @Test + public void testNotifyUserStringMultisend() { + User user = mock(User.class); + String message = "a message"; + assertTrue(n.notify(user, message)); + // Spam + for (int i = 0; i< 10; i++) { + assertFalse(n.notify(user, message)); + } + Mockito.verify(user).sendRawMessage(message); + } + + /** + * Test method for {@link world.bentobox.bentobox.api.user.Notifier#notify(world.bentobox.bentobox.api.user.User, java.lang.String)}. + * @throws InterruptedException + */ + @Test + public void testNotifyUserStringMultisendWaitSend() throws InterruptedException { + User user = mock(User.class); + String message = "a message"; + assertTrue(n.notify(user, message)); + for (int i = 0; i< 10; i++) { + assertFalse(n.notify(user, message)); + } + Thread.sleep(4100); + for (int i = 0; i< 10; i++) { + n.notify(user, message); + } + Mockito.verify(user, Mockito.times(2)).sendRawMessage(message); + } + +}