SearchFilter implements Filter { @Override public boolean filter(Object datamodelObj) { if(datamodelObj instanceof DbSearch){ return includeModules.equals(((DbSearch)datamodelObj).getModules() == null || ((DbSearch)datamodelObj).getModules().isEmpty()) && includeArtifacts.equals(((DbSearch)datamodelObj).getArtifacts() == null || ((DbSearch) datamodelObj).getArtifacts().isEmpty()); } return false; } SearchFilter(final Boolean modules, final Boolean artifacts); @Override boolean filter(Object datamodelObj); @Override Map<String, Object> moduleFilterFields(); @Override Map<String, Object> artifactFilterFields();  }
@Test public void filter() throws Exception { SearchFilter filter = new SearchFilter(true, true); assertFalse(filter.filter(null)); filter = new SearchFilter(true, false); assertFalse(filter.filter(null)); filter = new SearchFilter(false, true); assertFalse(filter.filter(null)); filter = new SearchFilter(null, null); assertFalse(filter.filter(null)); }
@Test public void testModuleSearch() { List<String> moduleIds = new ArrayList<>(); moduleIds.add("test_id_1"); moduleIds.add("test_id_2"); List<String> artifactIds = new ArrayList<>(); artifactIds.add("test_artifact_id_1"); artifactIds.add("test_artifact_id_2"); DbSearch filterModules = new DbSearch(); filterModules.setModules(moduleIds); DbSearch filterArtifacts = new DbSearch(); filterArtifacts.setArtifacts(artifactIds); SearchFilter filter = new SearchFilter(false, true); assertTrue(filter.filter(filterModules)); assertFalse(filter.filter(filterArtifacts)); filter = new SearchFilter(true, false); assertTrue(filter.filter(filterArtifacts)); assertFalse(filter.filter(filterModules)); filter = new SearchFilter(false, false); assertFalse(filter.filter(filterArtifacts)); assertFalse(filter.filter(filterModules)); }