LicenseIdFilter implements Filter { @Override public boolean filter(final Object datamodelObj) { if(datamodelObj instanceof DbLicense){ return licenseId.equals( ((DbLicense)datamodelObj).getName()); } if(datamodelObj instanceof DbArtifact){ return ((DbArtifact)datamodelObj).getLicenses().contains(licenseId); } return false; } LicenseIdFilter(final String licenseId); @Override boolean filter(final Object datamodelObj); @Override Map<String, Object> moduleFilterFields(); @Override Map<String, Object> artifactFilterFields();  }
@Test public void approveNull(){ LicenseIdFilter filter = new LicenseIdFilter("test"); assertFalse(filter.filter(null)); }
@Test public void approveArtifact(){ final DbArtifact artifactWithLicense = new DbArtifact(); final DbLicense license = new DbLicense(); license.setName("licenseName"); artifactWithLicense.addLicense(license); final DbArtifact artifactWithoutLicense = new DbArtifact(); LicenseIdFilter filter = new LicenseIdFilter(license.getName()); assertTrue(filter.filter(artifactWithLicense)); assertFalse(filter.filter(artifactWithoutLicense)); }
@Test public void approveLicense(){ final DbLicense license = new DbLicense(); license.setName("licenseName"); final DbLicense license2 = new DbLicense(); license.setName("licenseName2"); final DbArtifact artifactWithoutLicense = new DbArtifact(); LicenseIdFilter filter = new LicenseIdFilter(license.getName()); assertTrue(filter.filter(license)); assertFalse(filter.filter(license2)); }