### Question:
FilterEvaluator { Optional<Boolean> isVisible(Link quickLink) { if (linkNameFilters.containsKey(quickLink.getName())) { return Optional.of(linkNameFilters.get(quickLink.getName())); } for (String attribute: DefaultQuickLinkVisibilityController.nullToEmptyList(quickLink.getAttributes())) { if (hideAttributes.contains(attribute)) return Optional.of(false); } for (String attribute: DefaultQuickLinkVisibilityController.nullToEmptyList(quickLink.getAttributes())) { if (showAttributes.contains(attribute)) return Optional.of(true); } return acceptAllFilter; } FilterEvaluator(List<Filter> filters);   }### Answer:
@Test public void testWithEmptyFilters() throws Exception { FilterEvaluator evaluator = new FilterEvaluator(new ArrayList<>()); assertEquals(Optional.empty(), evaluator.isVisible(namenodeUi)); FilterEvaluator evaluator2 = new FilterEvaluator(null); assertEquals(Optional.empty(), evaluator2.isVisible(namenodeUi)); }
@Test public void testNoMatchingFilter() throws Exception { List<Filter> filters = Lists.newArrayList( linkNameFilter(NAMENODE_JMX, true), linkAttributeFilter(SSO, false)); FilterEvaluator evaluator = new FilterEvaluator(filters); assertEquals(Optional.empty(), evaluator.isVisible(namenodeUi)); }
@Test public void testLinkNameFiltersEvaluatedFirst() throws Exception { List<Filter> filters = Lists.newArrayList( acceptAllFilter(false), linkNameFilter(NAMENODE_UI, true), linkNameFilter(NAMENODE_JMX, false), linkAttributeFilter(AUTHENTICATED, false), linkAttributeFilter(SSO, false)); FilterEvaluator evaluator = new FilterEvaluator(filters); assertEquals(Optional.of(true), evaluator.isVisible(namenodeUi)); }
@Test public void testLinkAttributeFiltersEvaluatedSecondly() throws Exception { List<Filter> filters = Lists.newArrayList( acceptAllFilter(false), linkNameFilter(NAMENODE_JMX, false), linkAttributeFilter(AUTHENTICATED, true), linkAttributeFilter(SSO, true)); FilterEvaluator evaluator = new FilterEvaluator(filters); assertEquals(Optional.of(true), evaluator.isVisible(namenodeUi)); }
@Test public void testLinkAttributeFiltersWorkWithNullAttributes() throws Exception { List<Filter> filters = Lists.newArrayList( acceptAllFilter(true), linkAttributeFilter(AUTHENTICATED, false), linkAttributeFilter(SSO, false)); FilterEvaluator evaluator = new FilterEvaluator(filters); assertEquals(Optional.of(true), evaluator.isVisible(nameNodeJmx)); }
@Test public void testHideFilterTakesPrecedence() throws Exception { List<Filter> filters = Lists.newArrayList( linkAttributeFilter(AUTHENTICATED, false), linkAttributeFilter(SSO, true)); FilterEvaluator evaluator = new FilterEvaluator(filters); namenodeUi.setAttributes(ImmutableList.of(AUTHENTICATED, SSO)); assertEquals(Optional.of(false), evaluator.isVisible(namenodeUi)); }
@Test public void acceptAllFilterEvaluatedLast() throws Exception { List<Filter> filters = Lists.newArrayList( acceptAllFilter(false), linkNameFilter(NAMENODE_JMX, true), linkAttributeFilter(SSO, true)); FilterEvaluator evaluator = new FilterEvaluator(filters); assertEquals(Optional.of(false), evaluator.isVisible(namenodeUi)); }
@Test public void duplicateFiltersAreOkIfDoNotContradict() throws Exception { List<Filter> filters = Lists.newArrayList( acceptAllFilter(true), acceptAllFilter(true), linkNameFilter(NAMENODE_JMX, false), linkNameFilter(NAMENODE_JMX, false), linkAttributeFilter(SSO, false), linkAttributeFilter(SSO, false)); FilterEvaluator evaluator = new FilterEvaluator(filters); assertEquals(Optional.of(true), evaluator.isVisible(namenodeUi)); }