DefaultCommunicationService implements CommunicationService { public Map<String, Direction> computeNewDirectionAfterAddingLink(String startGroupId, Direction startDirection, String endGroupId, Direction endDirection) { Map<String, Direction> resDirectionMap = new HashMap<>(); if (startDirection.equals(Direction.NONE)) { resDirectionMap.put(startGroupId, Direction.INCOMING); } else if (startDirection.equals(Direction.OUTGOING)) { resDirectionMap.put(startGroupId, Direction.BOTH); } if (endDirection.equals(Direction.NONE)) { resDirectionMap.put(endGroupId, Direction.OUTGOING); } else if (endDirection.equals(Direction.INCOMING)) { resDirectionMap.put(endGroupId, Direction.BOTH); } return resDirectionMap; }  @Override void addLink(String startGroupId, String endGroupId, Handler<Either<String, JsonObject>> handler); @Override void removeLink(String startGroupId, String endGroupId, Handler<Either<String, JsonObject>> handler); @Override void addLinkWithUsers(String groupId, Direction direction, Handler<Either<String, JsonObject>> handler); @Override void addLinkWithUsers(Map<String, Direction> params, Handler<Either<String, JsonObject>> handler); @Override void removeLinkWithUsers(String groupId, Direction direction, Handler<Either<String, JsonObject>> handler); @Override void communiqueWith(String groupId, Handler<Either<String, JsonObject>> handler); @Override void addLinkBetweenRelativeAndStudent(String groupId, Direction direction,
			Handler<Either<String, JsonObject>> handler); @Override void removeLinkBetweenRelativeAndStudent(String groupId, Direction direction,
			Handler<Either<String, JsonObject>> handler); @Override void initDefaultRules(JsonArray structureIds, JsonObject defaultRules,
			final Handler<Either<String, JsonObject>> handler); @Override void applyDefaultRules(JsonArray structureIds, Handler<Either<String, JsonObject>> handler); @Override void applyRules(String groupId, Handler<Either<String, JsonObject>> handler); @Override void removeRules(String structureId, Handler<Either<String, JsonObject>> handler); @Override void visibleUsers(String userId, String structureId, JsonArray expectedTypes, boolean itSelf,
							 boolean myGroup, boolean profile, String preFilter, String customReturn, JsonObject additionnalParams,
							 final Handler<Either<String, JsonArray>> handler); @Override void visibleUsers(String userId, String structureId, JsonArray expectedTypes, boolean itSelf,
			boolean myGroup, boolean profile, String preFilter, String customReturn, JsonObject additionnalParams, String userProfile,
			final Handler<Either<String, JsonArray>> handler); @Override void usersCanSeeMe(String userId, Handler<Either<String, JsonArray>> handler); @Override void visibleProfilsGroups(String userId, String customReturn, JsonObject additionnalParams,
			String preFilter, Handler<Either<String, JsonArray>> handler); @Override void visibleManualGroups(String userId, String customReturn, JsonObject additionnalParams,
			Handler<Either<String, JsonArray>> handler); @Override void getOutgoingRelations(String id, Handler<Either<String, JsonArray>> results); @Override void getIncomingRelations(String id, Handler<Either<String, JsonArray>> results); @Override void safelyRemoveLinkWithUsers(String groupId, Handler<Either<String, JsonObject>> handler); @Override void getDirections(String startGroupId, String endGroupId, Handler<Either<String, JsonObject>> handler); @Override void addLinkCheckOnly(String startGroupId, String endGroupId, UserInfos userInfos, Handler<Either<String, JsonObject>> handler); @Override void removeRelations(String sendingGroupId, String receivingGroupId, Handler<Either<String, JsonObject>> handler); @Override void processChangeDirectionAfterAddingLink(String startGroupId, String endGroupId, Handler<Either<String, JsonObject>> handler); Direction computeDirectionToRemove(boolean hasIncomingRelationship, boolean hasOutgoingRelationship); Direction computeNextDirection(Direction directionToRemove); String computeWarningMessageForAddLinkCheck(Direction startDirection, Direction endDirection); boolean isImpossibleToChangeDirectionGroupForAddLink(String filter, String subType, UserInfos userInfos); Map<String, Direction> computeNewDirectionAfterAddingLink(String startGroupId, Direction startDirection, String endGroupId, Direction endDirection);  }
@Test public void computeNewDirectionAfterAddingLink_shouldReturnSenderIncomingAndReceiverOutgoing_GivenSenderNoneAndReceiverNone() { Map<String, CommunicationService.Direction> expectedMap = new HashMap<>(); expectedMap.put("1", CommunicationService.Direction.INCOMING); expectedMap.put("2", CommunicationService.Direction.OUTGOING); Assert.assertEquals(expectedMap, this.service.computeNewDirectionAfterAddingLink("1" , CommunicationService.Direction.NONE , "2" , CommunicationService.Direction.NONE)); }
@Test public void computeNewDirectionAfterAddingLink_shouldReturnSenderIncomingAndReceiverBoth_GivenSenderNoneAndReceiverIncoming() { Map<String, CommunicationService.Direction> expectedMap = new HashMap<>(); expectedMap.put("1", CommunicationService.Direction.INCOMING); expectedMap.put("2", CommunicationService.Direction.BOTH); Assert.assertEquals(expectedMap, this.service.computeNewDirectionAfterAddingLink("1" , CommunicationService.Direction.NONE , "2" , CommunicationService.Direction.INCOMING)); }
@Test public void computeNewDirectionAfterAddingLink_shouldReturnSenderBothAndReceiverOutgoing_GivenSenderOutgoingAndReceiverNone() { Map<String, CommunicationService.Direction> expectedMap = new HashMap<>(); expectedMap.put("1", CommunicationService.Direction.BOTH); expectedMap.put("2", CommunicationService.Direction.OUTGOING); Assert.assertEquals(expectedMap, this.service.computeNewDirectionAfterAddingLink("1" , CommunicationService.Direction.OUTGOING , "2" , CommunicationService.Direction.NONE)); }
@Test public void computeNewDirectionAfterAddingLink_shouldReturnSenderBothAndReceiverBoth_GivenSenderOutgoingAndReceiverIncoming() { Map<String, CommunicationService.Direction> expectedMap = new HashMap<>(); expectedMap.put("1", CommunicationService.Direction.BOTH); expectedMap.put("2", CommunicationService.Direction.BOTH); Assert.assertEquals(expectedMap, this.service.computeNewDirectionAfterAddingLink("1" , CommunicationService.Direction.OUTGOING , "2" , CommunicationService.Direction.INCOMING)); }