aboutsummaryrefslogtreecommitdiff
path: root/juick-server/src
diff options
context:
space:
mode:
authorGravatar Vitaly Takmazov2018-05-11 13:14:40 +0300
committerGravatar Vitaly Takmazov2018-05-11 13:14:40 +0300
commit6f85b661374ea0f3320dcff966fa7d76762ce742 (patch)
treec5d4757e8e82ba708211b3edc3d21943ce762552 /juick-server/src
parent007f78c1712e0dc1402c85914e40e9752deaae73 (diff)
AnonymousUser.INSTANCE where possible
Diffstat (limited to 'juick-server/src')
-rw-r--r--juick-server/src/main/java/com/juick/server/MessengerManager.java3
-rw-r--r--juick-server/src/main/java/com/juick/server/TelegramBotManager.java3
-rw-r--r--juick-server/src/test/java/com/juick/server/tests/ServerTests.java14
3 files changed, 11 insertions, 9 deletions
diff --git a/juick-server/src/main/java/com/juick/server/MessengerManager.java b/juick-server/src/main/java/com/juick/server/MessengerManager.java
index 303e08ce..8bfcafd0 100644
--- a/juick-server/src/main/java/com/juick/server/MessengerManager.java
+++ b/juick-server/src/main/java/com/juick/server/MessengerManager.java
@@ -15,6 +15,7 @@ import com.github.messenger4j.webhook.event.TextMessageEvent;
import com.juick.Message;
import com.juick.User;
import com.juick.server.component.MessageEvent;
+import com.juick.server.helpers.AnonymousUser;
import com.juick.service.MessagesService;
import com.juick.service.MessengerService;
import com.juick.service.SubscriptionService;
@@ -76,7 +77,7 @@ public class MessengerManager implements ApplicationListener<MessageEvent> {
final String senderId = event.senderId();
final Instant timestamp = event.timestamp();
- User user_from = userService.getUserByUID(messengerService.getUserId(senderId)).orElse(new User());
+ User user_from = userService.getUserByUID(messengerService.getUserId(senderId)).orElse(AnonymousUser.INSTANCE);
logger.info("Found juick user {}", user_from.getUid());
if (user_from.isAnonymous()) {
try {
diff --git a/juick-server/src/main/java/com/juick/server/TelegramBotManager.java b/juick-server/src/main/java/com/juick/server/TelegramBotManager.java
index c9097cb2..6e6198a8 100644
--- a/juick-server/src/main/java/com/juick/server/TelegramBotManager.java
+++ b/juick-server/src/main/java/com/juick/server/TelegramBotManager.java
@@ -19,6 +19,7 @@ package com.juick.server;
import com.juick.User;
import com.juick.server.component.*;
+import com.juick.server.helpers.AnonymousUser;
import com.juick.server.helpers.CommandResult;
import com.juick.server.util.HttpUtils;
import com.juick.service.MessagesService;
@@ -113,7 +114,7 @@ public class TelegramBotManager implements NotificationListener {
return;
}
}
- User user_from = userService.getUserByUID(telegramService.getUser(message.chat().id())).orElse(new User());
+ User user_from = userService.getUserByUID(telegramService.getUser(message.chat().id())).orElse(AnonymousUser.INSTANCE);
logger.info("Found juick user {}", user_from.getUid());
List<Long> chats = telegramService.getChats();
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 d3e7b7a5..abdabf4e 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
@@ -256,7 +256,7 @@ public class ServerTests {
@Test
public void messageTests() {
int user_id = userService.createUser("mmmme", "secret");
- User user = userService.getUserByUID(user_id).orElse(new User());
+ User user = userService.getUserByUID(user_id).orElse(AnonymousUser.INSTANCE);
assertEquals("it should be me", "mmmme", user.getName());
int mid = messagesService.createMessage(user_id, "yo", null, new ArrayList<>());
Message msg = messagesService.getMessage(mid);
@@ -273,7 +273,7 @@ public class ServerTests {
assertEquals(1, msg2.getTags().size());
assertEquals("we already have ugnich", -1, userService.createUser("ugnich", "x"));
int ugnich_id = userService.createUser("hugnich", "x");
- User ugnich = userService.getUserByUID(ugnich_id).orElse(new User());
+ User ugnich = userService.getUserByUID(ugnich_id).orElse(AnonymousUser.INSTANCE);
int rid = messagesService.createReply(msg2.getMid(), 0, ugnich, "bla-bla", null);
assertEquals(1, rid);
assertThat(msg2.getTo(), equalTo(null));
@@ -659,16 +659,16 @@ public class ServerTests {
@Test
public void botCommandsTests() throws Exception {
URI emptyUri = URI.create(StringUtils.EMPTY);
- assertThat(commandsManager.processCommand(new User(), "PING", emptyUri).getText(), is("PONG"));
+ assertThat(commandsManager.processCommand(AnonymousUser.INSTANCE, "PING", emptyUri).getText(), is("PONG"));
// subscription commands have two lines, others have 1
- assertThat(commandsManager.processCommand(new User(), "help", emptyUri).getText().split("\n").length, is(32));
+ assertThat(commandsManager.processCommand(AnonymousUser.INSTANCE, "help", emptyUri).getText().split("\n").length, is(32));
}
@Test
public void protocolTests() throws Exception {
URI emptyUri = URI.create(StringUtils.EMPTY);
int uid = userService.createUser("me", "secret");
- User user = userService.getUserByUID(uid).orElse(new User());
+ User user = userService.getUserByUID(uid).orElse(AnonymousUser.INSTANCE);
Tag yo = tagService.getTag("yo", true);
Message msg = commandsManager.processCommand(user, "*yo yoyo", URI.create("http://static.juick.com/settings/facebook.png")).getNewMessage().get();
assertThat(msg.getAttachmentType(), is("png"));
@@ -687,7 +687,7 @@ public class ServerTests {
assertEquals("should be message", true,
commandsManager.processCommand(user, String.format("#%d", mid), emptyUri).getText().startsWith("@me"));
int readerUid = userService.createUser("dummyReader", "dummySecret");
- User readerUser = userService.getUserByUID(readerUid).orElse(new User());
+ User readerUser = userService.getUserByUID(readerUid).orElse(AnonymousUser.INSTANCE);
assertThat(commandsManager.processCommand(readerUser, "s", emptyUri).getText().startsWith("You are subscribed to"), is(true));
assertThat(commandsManager.processCommand(readerUser, "S", emptyUri).getText().startsWith("You are subscribed to"), is(true));
assertEquals("should be subscribed", "Subscribed",
@@ -747,7 +747,7 @@ public class ServerTests {
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());
+ User taggerUser = userService.getUserByUID(taggerUid).orElse(AnonymousUser.INSTANCE);
assertEquals("should be subscribed", "Subscribed",
commandsManager.processCommand(taggerUser, "S *yo", emptyUri).getText());
assertEquals("number of subscribed users should match", 2,