### Question:
DiagnosticsFlowService { @VisibleForTesting boolean filterNodes(Node node, Set<String> hosts, Set<String> hostGroups) { boolean result = true; if (CollectionUtils.isNotEmpty(hosts)) { result = hosts.contains(node.getHostname()) || hosts.contains(node.getPrivateIp()) || hosts.contains(node.getPublicIp()); } if (result && CollectionUtils.isNotEmpty(hostGroups)) { result = hostGroups.contains(node.getHostGroup()); } return result; }  void init(Long stackId, Map<String, Object> parameters); void init(Long stackId, Map<String, Object> parameters, Set<String> hosts, Set<String> hostGroups); void collect(Long stackId, Map<String, Object> parameters, Set<String> hosts, Set<String> hostGroups); void upload(Long stackId, Map<String, Object> parameters); void upload(Long stackId, Map<String, Object> parameters, Set<String> hosts, Set<String> hostGroups); void cleanup(Long stackId, Map<String, Object> parameters); void cleanup(Long stackId, Map<String, Object> parameters, Set<String> hosts, Set<String> hostGroups);  }### Answer:
@Test public void testFilterNodesWithHostsFilter() { Set<String> hosts = new HashSet<>(); hosts.add("host1"); boolean result = underTest.filterNodes(createNode(), hosts, new HashSet<>()); assertTrue(result); }
@Test public void testFilterNodesWithWrongHostsFilter() { Set<String> hosts = new HashSet<>(); hosts.add("host2"); boolean result = underTest.filterNodes(createNode(), hosts, new HashSet<>()); assertFalse(result); }
@Test public void testFilterNodesWithHostGroupFilter() { Set<String> hostGroups = new HashSet<>(); hostGroups.add("master"); boolean result = underTest.filterNodes(createNode(), new HashSet<>(), hostGroups); assertTrue(result); }
@Test public void testFilterNodesWithWrongHostGroupFilter() { Set<String> hostGroups = new HashSet<>(); hostGroups.add("idbroker"); boolean result = underTest.filterNodes(createNode(), new HashSet<>(), hostGroups); assertFalse(result); }
@Test public void testFilterNodesWithHostAndHostGroupFilter() { Set<String> hostGroups = new HashSet<>(); hostGroups.add("master"); Set<String> hosts = new HashSet<>(); hosts.add("host1"); boolean result = underTest.filterNodes(createNode(), hosts, hostGroups); assertTrue(result); }
@Test public void testFilterNodesWithHostAndWrongHostGroupFilter() { Set<String> hostGroups = new HashSet<>(); hostGroups.add("idbroker"); Set<String> hosts = new HashSet<>(); hosts.add("host1"); boolean result = underTest.filterNodes(createNode(), hosts, hostGroups); assertFalse(result); }
@Test public void testFilterNodesWithWrongHostAndHostGroupFilter() { Set<String> hostGroups = new HashSet<>(); hostGroups.add("master"); Set<String> hosts = new HashSet<>(); hosts.add("host2"); boolean result = underTest.filterNodes(createNode(), hosts, hostGroups); assertFalse(result); }
@Test public void testFilterNodesWithEmptyFilters() { boolean result = underTest.filterNodes(createNode(), new HashSet<>(), new HashSet<>()); assertTrue(result); }