Пример #1
0
  @Override
  public void joinAs(String nickname, byte[] password) throws OperationFailedException {
    if (isJoined) throw new OperationFailedException("Alread joined the room", 0);

    isJoined = true;

    MockRoomMember member = new MockRoomMember(createAddressForName(nickname), this);

    // FIXME: for mock purposes we are always the owner on join()
    boolean isOwner = true; // = members.size() == 0;

    synchronized (members) {
      members.add(member);

      me = member;

      fireMemberPresenceEvent(me, me, ChatRoomMemberPresenceChangeEvent.MEMBER_JOINED, null);
    }

    ChatRoomMemberRole oldRole = me.getRole();
    if (isOwner) {
      me.setRole(ChatRoomMemberRole.OWNER);
    }

    fireLocalUserRoleEvent(me, oldRole, true);
  }
Пример #2
0
  private void mockLeave(MockRoomMember member) {
    synchronized (members) {
      if (!members.remove(member)) {
        throw new RuntimeException("Member is not in the room " + member);
      }

      fireMemberPresenceEvent(member, member, ChatRoomMemberPresenceChangeEvent.MEMBER_LEFT, null);
    }
  }
Пример #3
0
  public MockRoomMember mockJoin(MockRoomMember member) {
    synchronized (members) {
      members.add(member);

      fireMemberPresenceEvent(
          member, member, ChatRoomMemberPresenceChangeEvent.MEMBER_JOINED, null);

      return member;
    }
  }
Пример #4
0
  @Override
  public void leave() {
    if (!isJoined) return;

    isJoined = false;

    synchronized (members) {
      members.remove(me);

      fireMemberPresenceEvent(me, me, ChatRoomMemberPresenceChangeEvent.MEMBER_LEFT, null);
    }

    me = null;
  }
Пример #5
0
 @Override
 public int getMembersCount() {
   return members.size();
 }
Пример #6
0
 /**
  * Returns <tt>true</tt> if <tt>list1</tt> and <tt>list2</tt> contain the same elements where
  * items order is not relevant.
  *
  * @param list1 the first list of <tt>String</tt> to be compared against the second list.
  * @param list2 the second list of <tt>String</tt> to be compared against the first list.
  */
 public static boolean areTheSame(List<String> list1, List<String> list2) {
   return list1.size() == list2.size() && list2.containsAll(list1);
 }
Пример #7
0
 /**
  * Checks if all of the features given on <tt>reqFeatures</tt> array exist on declared list of
  * <tt>capabilities</tt>.
  *
  * @param reqFeatures array of required features to check.
  * @param capabilities the list of features supported by the client.
  * @return <tt>true</tt> if all features from <tt>reqFeatures</tt> array exist on
  *     <tt>capabilities</tt> list.
  */
 public static boolean checkFeatureSupport(String[] reqFeatures, List<String> capabilities) {
   for (String toCheck : reqFeatures) {
     if (!capabilities.contains(toCheck)) return false;
   }
   return true;
 }