### Question:
JsonSchemaMojo extends AbstractMojo { @Override public void execute() throws MojoExecutionException { main.defineClasspath(toUrls(compileClasspathElements)); main.setIncludeAdditionalProperties(includeAdditionalProperties); main.setSupportObjectReferences(supportObjectReferences); addExternalSchemas(); if (rootClass == null) { throw new MojoExecutionException("No root class specified"); } URL classUrl = main.getResource(toClassFileName(rootClass)); if (classUrl == null) { throw new MojoExecutionException("Class " + rootClass + " not found"); } if (updateNeeded(new File(classUrl.getPath()), getSchemaFile())) { getLog().info("Changes detected -- generating schema for " + rootClass + "."); generate(); } else { getLog().info("Schema up-to-date. Skipping generation."); } }  @Override void execute();  }### Answer:
@Test public void whenKubernetesVersionSpecified_passToGenerator() throws Exception { setMojoParameter("kubernetesVersion", "1.9.0"); mojo.execute(); assertThat(main.getKubernetesVersion(), equalTo("1.9.0")); }
@Test public void whenKubernetesVersionNotSpecified_passToGenerator() throws Exception { setMojoParameter("kubernetesVersion", null); mojo.execute(); assertThat(main.getKubernetesVersion(), nullValue()); }
@Test public void whenExternalSchemaSpecified_passToGenerator() throws Exception { setMojoParameter( "externalSchemas", singletonList(new ExternalSchema("http: mojo.execute(); assertThat( main.getCacheFor(new URL("http: equalTo(toModuleUrl("src/cache/schema.json"))); }
@Test(expected = MojoExecutionException.class) public void whenUnableToUseDefineSchema_haltTheBuild() throws Exception { setMojoParameter( "externalSchemas", singletonList(new ExternalSchema("abcd: mojo.execute(); }
@Test(expected = MojoExecutionException.class) public void whenNoClassSpecified_haltTheBuild() throws Exception { setMojoParameter("rootClass", null); mojo.execute(); }
@Test public void whenLookingForClassFile_specifyRelativeFilePath() throws Exception { mojo.execute(); assertThat(main.getResourceName(), equalTo(classNameToPath(TEST_ROOT_CLASS) + ".class")); }
@Test(expected = MojoExecutionException.class) public void whenRootClassNotFound_haltTheBuild() throws Exception { main.setClasspathResource(null); mojo.execute(); }
@Test public void useSpecifiedClasspath() throws Exception { String[] classpathElements = new String[] {"a", "b", "c"}; setMojoParameter("compileClasspathElements", Arrays.asList(classpathElements)); URL[] classPathUrls = new URL[] {new URL("file:abc"), new URL("file:bcd"), new URL("file:cde")}; for (int i = 0; i < classpathElements.length; i++) { fileSystem.defineUrl(new File(classpathElements[i]), classPathUrls[i]); } mojo.execute(); assertThat(main.getClasspath(), arrayContaining(classPathUrls)); }
@Test public void whenGenerateMarkdownSpecified_useGeneratedSchemaForMarkdown() throws Exception { ImmutableMap<String, Object> generatedSchema = ImmutableMap.of(); main.setGeneratedSchema(generatedSchema); setMojoParameter("generateMarkdown", true); mojo.execute(); assertThat(main.getMarkdownSchema(), sameInstance(generatedSchema)); }
@Test public void whenIncludeAdditionalPropertiesSet_setOnMain() throws Exception { setMojoParameter("includeAdditionalProperties", true); mojo.execute(); assertThat(main.isIncludeAdditionalProperties(), is(true)); }
@Test public void whenSupportObjectReferencesSet_setOnMain() throws Exception { setMojoParameter("supportObjectReferences", true); mojo.execute(); assertThat(main.isSupportObjectReferences(), is(true)); }