### Question:
HostConfigMappingDAO { @RequiresSession public Set<HostConfigMapping> findSelected(final long clusterId, Long hostId) { populateCache(); if (!hostConfigMappingByHost.containsKey(hostId)) return Collections.emptySet(); Set<HostConfigMapping> set = new HashSet<>(hostConfigMappingByHost.get(hostId)); CollectionUtils.filter(set, new Predicate() { @Override public boolean evaluate(Object arg0) { return ((HostConfigMapping) arg0).getClusterId().equals(clusterId) && ((HostConfigMapping) arg0).getSelected() > 0; } }); return set; }  @Transactional void create(HostConfigMapping hostConfigMapping); @Transactional HostConfigMapping merge(HostConfigMapping hostConfigMapping); @RequiresSession Set<HostConfigMapping> findByType(final long clusterId, Long hostId, final String type); @RequiresSession HostConfigMapping findSelectedByType(final long clusterId,
      Long hostId, final String type); @RequiresSession Set<HostConfigMapping> findSelected(final long clusterId, Long hostId); @RequiresSession Set<HostConfigMapping> findSelectedByHosts(Collection<Long> hostIds); @RequiresSession Map<String, List<HostConfigMapping>> findSelectedHostsByTypes(final long clusterId,
                                                                             Collection<String> types); @RequiresSession List<HostConfigMappingEntity> findAll(); @Transactional void removeByHostId(Long hostId); @Transactional void removeByClusterAndHostName(final long clusterId, String hostName); HostConfigMappingEntity buildHostConfigMappingEntity(HostConfigMapping hostConfigMapping); HostConfigMapping buildHostConfigMapping(
      HostConfigMappingEntity hostConfigMappingEntity);  }### Answer:
@Test public void testFindSelected() throws Exception { createEntity(1L, "h1", "global", "version1"); HostConfigMapping coreSiteConfigV1 = createEntity(1L, "h1", "core-site", "version1"); HostEntity hostEntity = hostDAO.findByName("h1"); Set<HostConfigMapping> targets = hostConfigMappingDAO.findSelected(1L, hostEntity.getHostId()); Assert.assertEquals("Expected two entities", 2, targets.size()); coreSiteConfigV1.setSelected(0); hostConfigMappingDAO.merge(coreSiteConfigV1); createEntity(1L, "h1", "core-site", "version2"); targets = hostConfigMappingDAO.findSelected(1L, hostEntity.getHostId()); Assert.assertEquals("Expected two entities", 2, targets.size()); }