Skip to content

Commit

Permalink
Make utility class static (#270)
Browse files Browse the repository at this point in the history
  • Loading branch information
elharo authored Dec 7, 2024
1 parent dccc59a commit 6fe729b
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -37,14 +37,14 @@
* @author Olivier Lamy
* @since 22 nov. 07
*/
class InterpolationTest extends AbstractTestUtil {
class InterpolationTest {

private MavenProject buildMavenProjectStub() {
MavenProject project = new MavenProject();
project.setVersion("1.0-SNAPSHOT");
project.setArtifactId("foo");
project.setGroupId("bar");
project.setFile(new File(getBasedir(), "pom.xml"));
project.setFile(new File(TestUtil.getBasedir(), "pom.xml"));
Properties properties = new Properties();
properties.put("fooOnProject", "barOnProject");
project.getModel().setProperties(properties);
Expand Down Expand Up @@ -72,16 +72,16 @@ void testCompositeMap() {
void testPomInterpolation() throws Exception {
File interpolatedPomFile;
InvokerMojo invokerMojo = new InvokerMojo();
setVariableValueToObject(invokerMojo, "project", buildMavenProjectStub());
setVariableValueToObject(invokerMojo, "settings", new Settings());
TestUtil.setVariableValueToObject(invokerMojo, "project", buildMavenProjectStub());
TestUtil.setVariableValueToObject(invokerMojo, "settings", new Settings());
Properties properties = new Properties();
properties.put("foo", "bar");
properties.put("version", "2.0-SNAPSHOT");
setVariableValueToObject(invokerMojo, "filterProperties", properties);
String dirPath = getBasedir() + File.separatorChar + "src" + File.separatorChar + "test" + File.separatorChar
+ "resources" + File.separatorChar + "unit" + File.separatorChar + "interpolation";
TestUtil.setVariableValueToObject(invokerMojo, "filterProperties", properties);
String dirPath = TestUtil.getBasedir() + File.separatorChar + "src" + File.separatorChar + "test"
+ File.separatorChar + "resources" + File.separatorChar + "unit" + File.separatorChar + "interpolation";

interpolatedPomFile = new File(getBasedir(), "target/interpolated-pom.xml");
interpolatedPomFile = new File(TestUtil.getBasedir(), "target/interpolated-pom.xml");
invokerMojo.buildInterpolatedFile(new File(dirPath, "pom.xml"), interpolatedPomFile);
try (Reader reader = new XmlStreamReader(interpolatedPomFile)) {
String content = IOUtil.toString(reader);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,15 @@
import org.apache.maven.settings.Settings;
import org.junit.jupiter.api.Test;

import static org.apache.maven.plugins.invoker.TestUtil.getBasedir;
import static org.apache.maven.plugins.invoker.TestUtil.setVariableValueToObject;
import static org.assertj.core.api.Assertions.assertThat;

/**
* @author Olivier Lamy
* @since 18 nov. 07
*/
class InvokerMojoTest extends AbstractTestUtil {
class InvokerMojoTest {

private static final String DUMMY_PROJECT = "dummy" + File.separator + "pom.xml";
private static final String WITH_POM_DIR_PROJECT = "with-pom-project-dir" + File.separator + "pom.xml";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,16 @@

import org.codehaus.plexus.util.ReflectionUtils;

abstract class AbstractTestUtil {
class TestUtil {

protected String getBasedir() {
private TestUtil() {}

static String getBasedir() {
String path = System.getProperty("basedir");
return path != null ? path : new File("").getAbsolutePath();
}

protected void setVariableValueToObject(Object object, String filed, Object value) throws IllegalAccessException {
ReflectionUtils.setVariableValueInObject(object, filed, value);
static void setVariableValueToObject(Object object, String field, Object value) throws IllegalAccessException {

This comment has been minimized.

Copy link
@gnodet

gnodet Dec 7, 2024

Contributor

Not that this method is static, it does bring absolutely nothing...

ReflectionUtils.setVariableValueInObject(object, field, value);
}
}

0 comments on commit 6fe729b

Please sign in to comment.