### Question:
TaskHelper { public static boolean isPotentialOwner(Task task, User user) { final boolean directlyAssigned = task.getPotentialOwners().stream() .filter(OrganizationalEntity::isUser) .anyMatch(entity -> Objects.equals(entity.getEntityId(), user.getEntityId())); if (directlyAssigned) { return true; } final Set<String> acceptedGroupIds = task.getPotentialOwners().stream() .filter(entity -> !entity.isUser()) .map(OrganizationalEntity::getEntityId).collect(Collectors.toSet()); return user.getGroups().stream() .anyMatch(group -> acceptedGroupIds.contains(group.getEntityId())); } private  TaskHelper(); static boolean isPotentialOwner(Task task, User user); static boolean hasAllLabels(Task task, User user, String labelName); static int countMatchingLabels(Task task, User user, String labelName); static List<Task> extractTasks(TaskOrUser taskOrUser); static List<Task> extractTasks(TaskOrUser taskOrUser, Predicate<Task> predicate); static boolean hasPinnedTasks(TaskOrUser user);  }### Answer:
@Test public void isPotentialOwnerDirectAssignmentTrue() { for (User user : availableUsers) { assertThat(isPotentialOwner(task, user)).isTrue(); } }
@Test public void isPotentialOwnerDirectAssignmentFalse() { for (User user : availableUsers) { task.getPotentialOwners().remove(user); assertThat(isPotentialOwner(task, user)).isFalse(); } }
@Test public void isPotentialOwnerInDirectAssignmentTrue() { for (User user : availableUsers) { task.getPotentialOwners().remove(user); for (Group group : availableGroups) { user.getGroups().add(group); assertThat(isPotentialOwner(task, user)).isTrue(); user.getGroups().remove(group); } } }
@Test public void isPotentialOwnerInDirectAssignmentFalse() { for (User user : availableUsers) { task.getPotentialOwners().remove(user); for (Group group : availableGroups) { user.getGroups().add(group); assertThat(isPotentialOwner(task, user)).isTrue(); user.getGroups().remove(group); assertThat(isPotentialOwner(task, user)).isFalse(); } } }
@Test public void isPotentialOwnerOfTaskWithNoGroupsAndUserNoGroups() { Task task = new Task(); User user = availableUsers.get(0); assertThat(isPotentialOwner(task, user)).isFalse(); }
@Test public void isPotentialOwnerOfTaskWithGroupsAndUserNoGroups() { Task task = new Task(); task.getPotentialOwners().add(availableGroups.get(0)); User user = availableUsers.get(0); assertThat(isPotentialOwner(task, user)).isFalse(); }
@Test public void isPotentialOwnerOfTaskWithNoGroupsAndUserWithGroups() { Task task = new Task(); User user = availableUsers.get(0); user.getGroups().add(availableGroups.get(0)); assertThat(isPotentialOwner(task, user)).isFalse(); }