diff options
Diffstat (limited to 'juick-server/src/test/java/com')
-rw-r--r-- | juick-server/src/test/java/com/juick/server/tests/ServerTests.java | 51 |
1 files changed, 27 insertions, 24 deletions
diff --git a/juick-server/src/test/java/com/juick/server/tests/ServerTests.java b/juick-server/src/test/java/com/juick/server/tests/ServerTests.java index f9776f2f..d6617cc1 100644 --- a/juick-server/src/test/java/com/juick/server/tests/ServerTests.java +++ b/juick-server/src/test/java/com/juick/server/tests/ServerTests.java @@ -72,8 +72,7 @@ import java.util.stream.IntStream; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.*; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotEquals; +import static org.junit.Assert.*; import static org.springframework.security.test.web.servlet.request.SecurityMockMvcRequestPostProcessors.httpBasic; import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.*; import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.*; @@ -539,11 +538,11 @@ public class ServerTests { assertThat(isActive, equalTo(false)); } @Test - public void botCommandsTests() throws IllegalAccessException, NoSuchMethodException, InvocationTargetException { + public void botCommandsTests() throws Exception { URI emptyUri = URI.create(StringUtils.EMPTY); - assertThat(commandsManager.processCommand(new User(), Jid.of("test@localhost"), "PING", emptyUri).get().getText(), is("PONG")); + assertThat(commandsManager.processCommand(new User(), Jid.of("test@localhost"), "PING", emptyUri).getText(), is("PONG")); // subscription commands have two lines, others have 1 - assertThat(commandsManager.processCommand(new User(), Jid.of("test@localhost"), "help", emptyUri).get().getText().split("\n").length, is(32)); + assertThat(commandsManager.processCommand(new User(), Jid.of("test@localhost"), "help", emptyUri).getText().split("\n").length, is(32)); } @Test @@ -558,7 +557,7 @@ public class ServerTests { assertThat(msgreply.getAttachmentType(), equalTo("png")); int mid = messagesService.createMessage(uid, "yoyo", null, Collections.singletonList(yo)); assertEquals("should be message", true, - commandsManager.processCommand(user, Jid.of("test@localhost"), String.format("#%d", mid), emptyUri).get().getText().startsWith("@me")); + commandsManager.processCommand(user, Jid.of("test@localhost"), String.format("#%d", mid), emptyUri).getText().startsWith("@me")); assertEquals("text should match", "yoyo", messagesService.getMessage(mid).getText()); assertEquals("tag should match", "yo", @@ -567,9 +566,9 @@ public class ServerTests { User readerUser = userService.getUserByUID(readerUid).orElse(new User()); Jid dummyJid = Jid.of("dummy@localhost"); assertEquals("should be subscribed", "Subscribed", - commandsManager.processCommand(readerUser, dummyJid, "S #" + mid, emptyUri).get().getText()); + commandsManager.processCommand(readerUser, dummyJid, "S #" + mid, emptyUri).getText()); assertEquals("should be favorited", "Message is added to your recommendations", - commandsManager.processCommand(readerUser, dummyJid, "! #" + mid, emptyUri).get().getText()); + commandsManager.processCommand(readerUser, dummyJid, "! #" + mid, emptyUri).getText()); int rid = messagesService.createReply(mid, 0, uid, "comment", null); assertEquals("number of subscribed users should match", 1, subscriptionService.getUsersSubscribedToComments( @@ -581,7 +580,8 @@ public class ServerTests { messagesService.getMessage(mid), messagesService.getReply(mid, rid)).size()); assertEquals("should be subscribed", "Subscribed to @" + user.getName(), - commandsManager.processCommand(readerUser, Jid.of("dummy@localhost"), "S @" + user.getName(), emptyUri).get().getText()); + commandsManager.processCommand(readerUser, Jid.of("dummy@localhost"), "S @" + user.getName(), emptyUri) + .getText()); List<User> friends = userService.getUserFriends(readerUid); assertEquals("number of friend users should match", 2, friends.size()); @@ -592,57 +592,60 @@ public class ServerTests { String expectedThirdReply = "Reply posted.\n#" + mid + "/3 " + "https://juick.com/" + mid + "#3"; assertEquals("should be second reply", expectedSecondReply, - commandsManager.processCommand(user, Jid.of("test@localhost"), "#" + mid + " yoyo", URI.create("http://static.juick.com/settings/facebook.png")).get().getText()); + commandsManager.processCommand(user, Jid.of("test@localhost"), "#" + mid + " yoyo", URI.create("http://static.juick.com/settings/facebook.png")).getText()); assertEquals("should be third reply", expectedThirdReply, - commandsManager.processCommand(user, Jid.of("test@localhost"), "#" + mid + "/2 ", URI.create("http://static.juick.com/settings/facebook.png")).get().getText()); + commandsManager.processCommand(user, Jid.of("test@localhost"), "#" + mid + "/2 ", + URI.create("http://static.juick.com/settings/facebook.png")).getText()); Message reply = messagesService.getReplies(mid).stream().filter(m -> m.getRid() == 3).findFirst() .orElse(new Message()); assertEquals("should be reply to second comment", 2, reply.getReplyto()); assertEquals("tags should NOT be updated", "It is not your message", - commandsManager.processCommand(readerUser, Jid.of("dummy@localhost"), "#" + mid + " *yo *there", emptyUri).get().getText()); + commandsManager.processCommand(readerUser, Jid.of("dummy@localhost"), "#" + mid + " *yo *there", emptyUri) + .getText()); assertEquals("tags should be updated", "Tags are updated", - commandsManager.processCommand(user, Jid.of("test@localhost"), "#" + mid + " *there", emptyUri).get().getText()); + commandsManager.processCommand(user, Jid.of("test@localhost"), "#" + mid + " *there", emptyUri).getText()); assertEquals("number of tags should match", 2, tagService.getMessageTags(mid).size()); assertEquals("should be blacklisted", "Tag added to your blacklist", - commandsManager.processCommand(readerUser, Jid.of("dummy@localhost"), "BL *there", emptyUri).get().getText()); + commandsManager.processCommand(readerUser, Jid.of("dummy@localhost"), "BL *there", emptyUri).getText()); assertEquals("number of subscribed users should match", 0, subscriptionService.getSubscribedUsers(uid, mid).size()); assertEquals("tags should be updated", "Tags are updated", - commandsManager.processCommand(user, Jid.of("test@localhost"), "#" + mid + " *there", emptyUri).get().getText()); + commandsManager.processCommand(user, Jid.of("test@localhost"), "#" + mid + " *there", emptyUri).getText()); assertEquals("number of tags should match", 1, tagService.getMessageTags(mid).size()); int taggerUid = userService.createUser("dummyTagger", "dummySecret"); User taggerUser = userService.getUserByUID(taggerUid).orElse(new User()); assertEquals("should be subscribed", "Subscribed", - commandsManager.processCommand(taggerUser, Jid.of("tagger@localhost"), "S *yo", emptyUri).get().getText()); + commandsManager.processCommand(taggerUser, Jid.of("tagger@localhost"), "S *yo", emptyUri).getText()); assertEquals("number of subscribed users should match", 2, subscriptionService.getSubscribedUsers(uid, mid).size()); assertEquals("should be unsubscribed", "Unsubscribed from yo", - commandsManager.processCommand(taggerUser, Jid.of("tagger@localhost"), "U *yo", emptyUri).get().getText()); + commandsManager.processCommand(taggerUser, Jid.of("tagger@localhost"), "U *yo", emptyUri).getText()); assertEquals("number of subscribed users should match", 1, subscriptionService.getSubscribedUsers(uid, mid).size()); assertEquals("number of readers should match", 1, userService.getUserReaders(uid).size()); - String readerFeed = commandsManager.processCommand(readerUser, Jid.of("dummy@localhost"), "#", emptyUri).get().getText(); - assertEquals("description should match", true, readerFeed.startsWith("Your feed")); + String readerFeed = commandsManager.processCommand(readerUser, Jid.of("dummy@localhost"), "#", emptyUri).getText(); + assertTrue("description should match", readerFeed.startsWith("Your feed")); assertEquals("should be unsubscribed", "Unsubscribed from @" + user.getName(), - commandsManager.processCommand(readerUser, Jid.of("dummy@localhost"), "U @" + user.getName(), emptyUri).get().getText()); + commandsManager.processCommand(readerUser, Jid.of("dummy@localhost"), "U @" + user.getName(), emptyUri) + .getText()); assertEquals("number of readers should match", 0, userService.getUserReaders(uid).size()); assertEquals("number of friends should match", 1, userService.getUserFriends(uid).size()); assertEquals("should be unsubscribed", "Unsubscribed from #" + mid, - commandsManager.processCommand(readerUser, Jid.of("dummy@localhost"), "u #" + mid, emptyUri).get().getText()); + commandsManager.processCommand(readerUser, Jid.of("dummy@localhost"), "u #" + mid, emptyUri).getText()); assertEquals("number of subscribed users should match", 0, subscriptionService.getUsersSubscribedToComments(messagesService.getMessage(mid), messagesService.getReply(mid, rid)).size()); assertNotEquals("should NOT be deleted", String.format("Message %s deleted", mid), - commandsManager.processCommand(readerUser, Jid.of("dummy@localhost"), "D #" + mid, emptyUri).get().getText()); + commandsManager.processCommand(readerUser, Jid.of("dummy@localhost"), "D #" + mid, emptyUri).getText()); assertEquals("should be deleted", "Message deleted", - commandsManager.processCommand(user, Jid.of("test@localhost"), "D #" + mid, emptyUri).get().getText()); + commandsManager.processCommand(user, Jid.of("test@localhost"), "D #" + mid, emptyUri).getText()); assertEquals("should be not found", "Message not found", - commandsManager.processCommand(user, Jid.of("test@localhost"), "#" + mid, emptyUri).get().getText()); + commandsManager.processCommand(user, Jid.of("test@localhost"), "#" + mid, emptyUri).getText()); } @Test public void mailParserTest() throws Exception { |