XCodeVerificationCheckMojo extends BuildContextAwareMojo { static org.sonatype.aether.artifact.Artifact parseDependency(final Check check) throws XCodeException { final String groupId = check.getGroupId(); final String artifactId = check.getArtifactId(); final String version = check.getVersion(); if (StringUtils.isEmpty(groupId) && StringUtils.isEmpty(artifactId) && StringUtils.isEmpty(version)) { log.info( "No coordinates maintained for check represented by class '" + check.getClazz() + "'. Assuming this check is already contained in the classpath."); return null; } if (StringUtils.isEmpty(groupId)) throw new XCodeException(String.format("groupId for check %s is null or emtpy", check.getClazz())); if (StringUtils.isEmpty(artifactId)) throw new XCodeException(String.format("artifactId for check %s is null or emtpy", check.getClazz())); if (StringUtils.isEmpty(version)) throw new XCodeException(String.format("version for check %s is null or emtpy", check.getClazz())); return new DefaultArtifact(groupId, artifactId, "jar", version); }  @Override void execute();  }
@Test public void testNoGav() throws Exception { Checks checks = loadChecks("src/test/checks/noGAV.xml"); Set<Artifact> dependencies = new HashSet<Artifact>(); for (Check check : checks.getCheck()) { Artifact dep = XCodeVerificationCheckMojo.parseDependency(check); if (dep != null) { dependencies.add(dep); } } assertEquals("Check dependencies number unexpected", 0, dependencies.size()); }
@Test public void testEmptyGav() throws Exception { Checks checks = loadChecks("src/test/checks/emptyGAV.xml"); Set<Artifact> dependencies = new HashSet<Artifact>(); for (Check check : checks.getCheck()) { Artifact dep = XCodeVerificationCheckMojo.parseDependency(check); if (dep != null) { dependencies.add(dep); } } assertEquals("Check dependencies number unexpected", 1, dependencies.size()); }