XCodeVerificationCheckMojo extends BuildContextAwareMojo { static Reader getChecksDescriptor(final String checkDefinitionFileLocation) throws XCodeException, IOException { if (checkDefinitionFileLocation == null || checkDefinitionFileLocation.trim().isEmpty()) { throw new XCodeException( "CheckDefinitionFile was not configured. Cannot perform verification checks. Define check definition file with paramater 'xcode.verification.checks.definitionFile'."); } final Location location = Location.getLocation(checkDefinitionFileLocation); try { Protocol protocol = Protocol.valueOf(location.protocol); return protocol.getCheckDefinitions(location.location); } catch (IllegalArgumentException ex) { throw new InvalidProtocolException(format("Invalid protocol provided: '%s'. Supported values are:'%s'.", location.protocol, Protocol.getProtocols()), ex); } catch (IOException ex) { throw new IOException(format("Cannot get check definitions from '%s'.", checkDefinitionFileLocation), ex); } }  @Override void execute();  }
@Test public void testGetCheckDescriptorWithFileProtocol() throws Exception, IOException { Reader r = null; try { r = XCodeVerificationCheckMojo.getChecksDescriptor("file:src/test/checks/checks.xml"); JAXBContext.newInstance(Checks.class).createUnmarshaller().unmarshal(r); } finally { IOUtils.closeQuietly(r); } }
@Test(expected = XCodeVerificationCheckMojo.InvalidProtocolException.class) public void testGetCheckDescriptorWithInvalidProtocol() throws Exception, IOException { XCodeVerificationCheckMojo.getChecksDescriptor("ftp: }
@Test(expected = NoProtocolException.class) public void testGetCheckDescriptorWithoutProtocol() throws Exception, IOException { XCodeVerificationCheckMojo.getChecksDescriptor("example.com"); }