Chatroom extends AbstractActor { public List<Messages.PostToChatroom> joinChatroom(Messages.JoinChatroom msg) { joinedUsers.add(msg.userRef); return chatHistory; }  @Override PartialFunction<Object, BoxedUnit> receive(); List<Messages.PostToChatroom> joinChatroom(Messages.JoinChatroom msg);  }
@Test public void testShouldAddUserToJoinedUsersWhenJoiningUnitTest() { Props props = Props.create(Chatroom.class); TestActorRef<Chatroom> ref = TestActorRef.create(system, props); Chatroom chatroom = ref.underlyingActor(); UserRef userRef = new UserRef(system.deadLetters(), "user"); Messages.JoinChatroom request = new Messages.JoinChatroom(userRef); chatroom.joinChatroom(request); assertEquals(chatroom.joinedUsers.get(0), userRef); }
@Test public void testShouldSendUpdateWhenUserPosts() { Props props = Props.create(Chatroom.class); TestActorRef<Chatroom> ref = TestActorRef.create(system, props); Chatroom chatroom = ref.underlyingActor(); final TestProbe probe = new TestProbe(system); UserRef userRef = new UserRef(probe.ref(), "user"); chatroom.joinChatroom(new Messages.JoinChatroom(userRef)); Messages.PostToChatroom msg = new Messages.PostToChatroom("test", "user"); ref.tell(msg, probe.ref()); probe.expectMsg(msg); }