RoomManager { public Set<UserParticipant> leaveRoom(String participantId) throws RoomException { log.debug("Request [LEAVE_ROOM] ({})", participantId); Participant participant = getParticipant(participantId); Room room = participant.getRoom(); String roomName = room.getName(); if (room.isClosed()) { log.warn("'{}' is trying to leave from room '{}' but it is closing", participant.getName(), roomName); throw new RoomException(Code.ROOM_CLOSED_ERROR_CODE, "'" + participant.getName() + "' is trying to leave from room '" + roomName + "' but it is closing"); } room.leave(participantId); Set<UserParticipant> remainingParticipants = null; try { remainingParticipants = getParticipants(roomName); } catch (RoomException e) { log.debug("Possible collision when closing the room '{}' (not found)"); remainingParticipants = Collections.emptySet(); } if (remainingParticipants.isEmpty()) { log.debug("No more participants in room '{}', removing it and closing it", roomName); room.close(); rooms.remove(roomName); log.warn("Room '{}' removed and closed", roomName); } return remainingParticipants; } RoomManager(RoomHandler roomHandler, KurentoClientProvider kcProvider); Set<UserParticipant> joinRoom(String userName, String roomName, boolean dataChannels,
      boolean webParticipant, KurentoClientSessionInfo kcSessionInfo, String participantId); Set<UserParticipant> leaveRoom(String participantId); String publishMedia(String participantId, boolean isOffer, String sdp,
      MediaElement loopbackAlternativeSrc, MediaType loopbackConnectionType, boolean doLoopback,
      MediaElement... mediaElements); String publishMedia(String participantId, String sdp, boolean doLoopback,
      MediaElement... mediaElements); String publishMedia(String participantId, boolean isOffer, String sdp, boolean doLoopback,
      MediaElement... mediaElements); String generatePublishOffer(String participantId); void unpublishMedia(String participantId); String subscribe(String remoteName, String sdpOffer, String participantId); void unsubscribe(String remoteName, String participantId); void onIceCandidate(String endpointName, String candidate, int sdpMLineIndex,
      String sdpMid, String participantId); void addMediaElement(String participantId, MediaElement element); void addMediaElement(String participantId, MediaElement element, MediaType type); void removeMediaElement(String participantId, MediaElement element); void mutePublishedMedia(MutedMediaType muteType, String participantId); void unmutePublishedMedia(String participantId); void muteSubscribedMedia(String remoteName, MutedMediaType muteType, String participantId); void unmuteSubscribedMedia(String remoteName, String participantId); @PreDestroy void close(); boolean isClosed(); Set<String> getRooms(); Set<UserParticipant> getParticipants(String roomName); Set<UserParticipant> getPublishers(String roomName); Set<UserParticipant> getSubscribers(String roomName); Set<UserParticipant> getPeerPublishers(String participantId); Set<UserParticipant> getPeerSubscribers(String participantId); boolean isPublisherStreaming(String participantId); void createRoom(KurentoClientSessionInfo kcSessionInfo); Set<UserParticipant> closeRoom(String roomName); MediaPipeline getPipeline(String participantId); String getRoomName(String participantId); String getParticipantName(String participantId); UserParticipant getParticipantInfo(String participantId); void updateFilter(String roomId, String filterId);  }
@Test public void leaveRoom() { joinManyUsersOneRoom(); assertTrue(!userJoinRoom(roomx, userx, pidx, false).isEmpty()); UserParticipant userxParticipant = new UserParticipant(pidx, userx); assertThat(manager.getParticipants(roomx), hasItem(userxParticipant)); Set<UserParticipant> remainingUsers = manager.leaveRoom(pidx); assertEquals(new HashSet<UserParticipant>(usersParticipants.values()), remainingUsers); assertEquals(manager.getParticipants(roomx), remainingUsers); assertThat(manager.getParticipants(roomx), not(hasItem(userxParticipant))); }