### Question:
GenerateConnectorInspectionsMojo extends AbstractMojo { public JsonNode validateWithSchema(File jsonFile) throws MojoExecutionException { InputStream jsonStream = null; try { jsonStream = new FileInputStream(jsonFile); JsonNode jsonNode = JsonUtils.reader().readTree(jsonStream); ProcessingReport report = jsonSchema.validate(jsonNode, true); if (! report.isSuccess()) { for (final ProcessingMessage processingMessage : report) { getLog().warn(processingMessage.toString()); } throw new MojoExecutionException("Validation of json file " + jsonFile.getName() + " failed, see previous logs"); } return jsonNode; } catch (IOException | ProcessingException ex) { throw new MojoExecutionException("Failure to validate json file " + jsonFile.getName(), ex); } finally { if (jsonStream != null) { try { jsonStream.close(); } catch (IOException e) { getLog().error(e); } } } } GenerateConnectorInspectionsMojo(); @Override void execute(); JsonNode validateWithSchema(File jsonFile); static DataShape generateInspections(URL[] classpath, DataShape shape); static JavaClass inspect(URL[] classpath, DataShape shape);  }### Answer:
@Test public void validFileAgainstSchema() throws Exception { GenerateConnectorInspectionsMojo mojo = new GenerateConnectorInspectionsMojo(); JsonNode jsonNode = mojo.validateWithSchema(getFile("/my-test-connector.json")); assertNotNull(jsonNode); }
@Test public void unformedFileAgainstSchema() throws Exception { GenerateConnectorInspectionsMojo mojo = new GenerateConnectorInspectionsMojo(); String unformedConnectorFile = "my-unformed-connector.json"; assertThatExceptionOfType(MojoExecutionException.class) .isThrownBy(() -> { mojo.validateWithSchema(getFile("/" + unformedConnectorFile)); }) .withCauseInstanceOf(JsonParseException.class) .withStackTraceContaining("line: 9, column: 12"); }
@Test public void invalidFileAgainstSchema() throws Exception { GenerateConnectorInspectionsMojo mojo = new GenerateConnectorInspectionsMojo(); String invalidConnectorFile = "my-invalid-connector.json"; assertThatExceptionOfType(MojoExecutionException.class) .isThrownBy(() -> { mojo.validateWithSchema(getFile("/" + invalidConnectorFile)); }) .withMessageContaining("Validation of json file " + invalidConnectorFile + " failed, see previous logs"); }