@Test public void filterCollectionByVisibilityWithNullInInputFiltersValidPrimaryEntities() { when(this.helper.getStringProperty(this.entityDoc1, VISIBILITY_CLASS_1, VISIBILITY)).thenReturn(PUBLIC); when(this.helper.getStringProperty(this.entityDoc2, VISIBILITY_CLASS_2, VISIBILITY)).thenReturn(HIDDEN); when(this.helper.getStringProperty(this.entityDoc3, VISIBILITY_CLASS_3, VISIBILITY)).thenReturn(PRIVATE); Collection<PrimaryEntity> input = Arrays.asList(this.entity1, this.entity2, this.entity3, null); Collection<? extends PrimaryEntity> result = this.component.filterByVisibility(input, PRIVATE_VISIBILITY); Assert.assertNotNull(result); Assert.assertEquals(2, result.size()); Iterator<? extends PrimaryEntity> it = result.iterator(); Assert.assertSame(this.entity1, it.next()); Assert.assertSame(this.entity3, it.next()); }
@Nonnull @Override public Collection<? extends PrimaryEntity> filterByVisibility( @Nullable final Collection<? extends PrimaryEntity> entities, @Nullable final Visibility requiredVisibility) { if (entities == null) { return Collections.emptyList(); } return requiredVisibility == null ? entities : entities.stream() .filter(Objects::nonNull) .filter(entity -> requiredVisibility.compareTo(getVisibility(entity)) <= 0) .collect(Collectors.toList()); }
DefaultEntityVisibilityManager implements EntityVisibilityManager { @Nonnull @Override public Collection<? extends PrimaryEntity> filterByVisibility( @Nullable final Collection<? extends PrimaryEntity> entities, @Nullable final Visibility requiredVisibility) { if (entities == null) { return Collections.emptyList(); } return requiredVisibility == null ? entities : entities.stream() .filter(Objects::nonNull) .filter(entity -> requiredVisibility.compareTo(getVisibility(entity)) <= 0) .collect(Collectors.toList()); } }
DefaultEntityVisibilityManager implements EntityVisibilityManager { @Nonnull @Override public Collection<? extends PrimaryEntity> filterByVisibility( @Nullable final Collection<? extends PrimaryEntity> entities, @Nullable final Visibility requiredVisibility) { if (entities == null) { return Collections.emptyList(); } return requiredVisibility == null ? entities : entities.stream() .filter(Objects::nonNull) .filter(entity -> requiredVisibility.compareTo(getVisibility(entity)) <= 0) .collect(Collectors.toList()); }  }
DefaultEntityVisibilityManager implements EntityVisibilityManager { @Nonnull @Override public Collection<? extends PrimaryEntity> filterByVisibility( @Nullable final Collection<? extends PrimaryEntity> entities, @Nullable final Visibility requiredVisibility) { if (entities == null) { return Collections.emptyList(); } return requiredVisibility == null ? entities : entities.stream() .filter(Objects::nonNull) .filter(entity -> requiredVisibility.compareTo(getVisibility(entity)) <= 0) .collect(Collectors.toList()); }  @Nonnull @Override Collection<Visibility> listVisibilityOptions(); @Nonnull @Override Collection<Visibility> listAllVisibilityOptions(); @Nonnull @Override Visibility getDefaultVisibility(); @Nonnull @Override Visibility resolveVisibility(@Nullable final String name); @Override boolean setVisibility(
        @Nullable final PrimaryEntity entity,
        @Nullable final Visibility visibility); @Nonnull @Override Visibility getVisibility(@Nullable final PrimaryEntity entity); @Nonnull @Override Collection<? extends PrimaryEntity> filterByVisibility(
        @Nullable final Collection<? extends PrimaryEntity> entities,
        @Nullable final Visibility requiredVisibility); @Nonnull @Override Iterator<? extends PrimaryEntity> filterByVisibility(
        @Nullable final Iterator<? extends PrimaryEntity> entities,
        @Nullable final Visibility requiredVisibility); }
DefaultEntityVisibilityManager implements EntityVisibilityManager { @Nonnull @Override public Collection<? extends PrimaryEntity> filterByVisibility( @Nullable final Collection<? extends PrimaryEntity> entities, @Nullable final Visibility requiredVisibility) { if (entities == null) { return Collections.emptyList(); } return requiredVisibility == null ? entities : entities.stream() .filter(Objects::nonNull) .filter(entity -> requiredVisibility.compareTo(getVisibility(entity)) <= 0) .collect(Collectors.toList()); }  @Nonnull @Override Collection<Visibility> listVisibilityOptions(); @Nonnull @Override Collection<Visibility> listAllVisibilityOptions(); @Nonnull @Override Visibility getDefaultVisibility(); @Nonnull @Override Visibility resolveVisibility(@Nullable final String name); @Override boolean setVisibility(
        @Nullable final PrimaryEntity entity,
        @Nullable final Visibility visibility); @Nonnull @Override Visibility getVisibility(@Nullable final PrimaryEntity entity); @Nonnull @Override Collection<? extends PrimaryEntity> filterByVisibility(
        @Nullable final Collection<? extends PrimaryEntity> entities,
        @Nullable final Visibility requiredVisibility); @Nonnull @Override Iterator<? extends PrimaryEntity> filterByVisibility(
        @Nullable final Iterator<? extends PrimaryEntity> entities,
        @Nullable final Visibility requiredVisibility);  }