### Question:
VisibilityFilter extends Filter implements OptionDescriber { public static void setAuthorizations(IteratorSetting setting, Authorizations auths) { setting.addOption(AUTHS, auths.serialize()); }  @Override void init(SortedKeyValueIterator<Key,Value> source, Map<String,String> options,
      IteratorEnvironment env); @Override boolean accept(Key k, Value v); @Override IteratorOptions describeOptions(); static void setAuthorizations(IteratorSetting setting, Authorizations auths); static void filterInvalidLabelsOnly(IteratorSetting setting, boolean featureEnabled);  }### Answer:
@Test public void testAllowAuthorizedLabelsOnly() throws IOException { IteratorSetting is = new IteratorSetting(1, VisibilityFilter.class); VisibilityFilter.setAuthorizations(is, new Authorizations("def")); TreeMap<Key,Value> source = createSourceWithHiddenData(1, 2); verify(source, 3, is.getOptions(), GOOD, GOOD, GOOD_VIS, 1); source = createSourceWithHiddenData(30, 500); verify(source, 530, is.getOptions(), GOOD, GOOD, GOOD_VIS, 30); source = createSourceWithHiddenData(1000, 500); verify(source, 1500, is.getOptions(), GOOD, GOOD, GOOD_VIS, 1000); }
@Test public void testAllowUnauthorizedLabelsOnly() throws IOException { IteratorSetting is = new IteratorSetting(1, VisibilityFilter.class); VisibilityFilter.setNegate(is, true); VisibilityFilter.setAuthorizations(is, new Authorizations("def")); TreeMap<Key,Value> source = createSourceWithHiddenData(1, 2); verify(source, 3, is.getOptions(), BAD, BAD, HIDDEN_VIS, 2); source = createSourceWithHiddenData(30, 500); verify(source, 530, is.getOptions(), BAD, BAD, HIDDEN_VIS, 500); source = createSourceWithHiddenData(1000, 500); verify(source, 1500, is.getOptions(), BAD, BAD, HIDDEN_VIS, 500); }
@Test public void testNoLabels() throws IOException { IteratorSetting is = new IteratorSetting(1, VisibilityFilter.class); VisibilityFilter.setNegate(is, false); VisibilityFilter.setAuthorizations(is, new Authorizations()); TreeMap<Key,Value> source = createUnprotectedSource(5, 2); verify(source, 7, is.getOptions(), GOOD, GOOD, EMPTY_VIS, 5); VisibilityFilter.setNegate(is, true); verify(source, 7, is.getOptions(), BAD, BAD, GOOD_VIS, 2); }
@Test public void testFilterUnauthorizedAndBad() throws IOException { IteratorSetting is = new IteratorSetting(1, VisibilityFilter.class); VisibilityFilter.setAuthorizations(is, new Authorizations("def")); TreeMap<Key,Value> source = createSourceWithHiddenData(1, 5); for (Entry<Key,Value> entry : createPollutedSource(0, 1).entrySet()) source.put(entry.getKey(), entry.getValue()); verify(source, 7, is.getOptions(), GOOD, GOOD, GOOD_VIS, 1); }