Java源码示例:io.takari.maven.testing.TestResources

示例1
public AbstractTest(
    MavenRuntime.MavenRuntimeBuilder mavenBuilder, String projectRootDirectoryName)
    throws Exception {
  this.resources =
      new TestResources(
          "src/test/projects",
          Files.createTempDirectory(ARTIFACT_ID + "-test").toString());
  this.maven = mavenBuilder.withCliOptions("-B", "-U").build();
  this.projectRootDirectoryName = projectRootDirectoryName;
}
 
示例2
@Test
public void testBasic() throws Exception {
    File basedir = resources.getBasedir("basic");
    String goal = format("io.codearte.props2yaml:props2yaml-maven-plugin:%s:convert", properties.getPluginVersion());
    maven.forProject(basedir)
            .execute(goal, "-Dproperties=sample.properties")
            .assertErrorFreeLog();
    TestResources.assertFilesPresent(basedir, "sample.yml");
}
 
示例3
@Test
public void testCustomTestPropertiesFile() throws Exception {
  File basedir = resources.getBasedir("testproperties/custom-test-properties-file");
  MavenProject project = mojos.readMavenProject(basedir);
  MavenSession session = mojos.newMavenSession(project);

  mojos.executeMojo(session, project, newMojoExecution());
  Assert.assertEquals("value", readProperties(basedir).get("custom"));

  TestResources.cp(basedir, "src/test/modified-test.properties", "src/test/test.properties");
  mojos.executeMojo(session, project, newMojoExecution());
  Assert.assertEquals("modified-value", readProperties(basedir).get("custom"));
}
 
示例4
@Test
public void testWorkspaceStateIncludesThisProjectJarArtifact() throws Exception {
  File basedir = resources.getBasedir();
  MavenProject project = mojos.readMavenProject(basedir);
  MavenSession session = mojos.newMavenSession(project);

  mojos.executeMojo(session, project, newMojoExecution());
  Map<String, String> state = TestResources.readProperties(basedir, "target/workspacestate.properties");

  Assert.assertEquals(new File(basedir, "pom.xml").getCanonicalPath(), state.get("test:test:pom::1"));
  Assert.assertEquals(new File(basedir, "target/classes").getCanonicalPath(), state.get("test:test:jar::1"));
}
 
示例5
private void test(String compilerId) throws Exception {
  File basedir = resources.getBasedir("compile-proc");

  MavenExecutionResult result = verifier.forProject(basedir).withCliOption("-DcompilerId=" + compilerId).execute("package");
  result.assertErrorFreeLog();

  TestResources.assertFilesPresent(basedir, "project/target/classes/project/MyMyAnnotationClient.class");
}
 
示例6
private Map<String, String> readProperties(File basedir) throws IOException {
  return TestResources.readProperties(basedir, "target/test-classes/test.properties");
}