### Question:
BuildHelperMojo extends AbstractMojo { public void execute() throws MojoExecutionException { Path source = toPath(sourceFile); Path target = toPath(targetFile); try { getLog().info("Copying " + source + " to " + target); executor.copyFile(source, target); } catch (IOException e) { throw new MojoExecutionException("Unable to copy " + source + " to " + target, e); } }  void execute();  }### Answer:
@Test public void whenSourceAndTargetAbsolute_useAbsolutePaths() throws Exception { setMojoParameter("sourceFile", "/root/source"); setMojoParameter("targetFile", new File("/root/target")); mojo.execute(); assertThat(copyExecutorStub.sourcePath, equalTo("/root/source")); assertThat(copyExecutorStub.targetPath, equalTo("/root/target")); }
@Test public void whenSourcePathIsRelative_computeAbsoluteRelativeToUserDir() throws Exception { setMojoParameter("sourceFile", "source"); setMojoParameter("targetFile", new File("/root/target")); setMojoParameter("userDir", new File("/root/nested")); mojo.execute(); assertThat(copyExecutorStub.sourcePath, equalTo("/root/nested/source")); assertThat(copyExecutorStub.targetPath, equalTo("/root/target")); }
@Test public void whenSourcePathIsRelativeAndNoUserDir_useSystemProperty() throws Exception { System.setProperty("user.dir", "/user"); setMojoParameter("sourceFile", "source"); setMojoParameter("targetFile", new File("/root/target")); mojo.execute(); assertThat(copyExecutorStub.sourcePath, equalTo("/user/source")); assertThat(copyExecutorStub.targetPath, equalTo("/root/target")); }