elharo commented on code in PR #414:
URL: https://github.com/apache/maven-help-plugin/pull/414#discussion_r3804833343
##########
src/main/java/org/apache/maven/plugins/help/EffectivePomMojo.java:
##########
@@ -178,7 +178,7 @@ private boolean shouldWriteAllEffectivePOMsInReactor() {
* @throws MojoExecutionException if any
*/
private void writeEffectivePom(MavenProject project, XMLWriter writer)
throws MojoExecutionException {
- Model pom = project.getModel();
+ Model pom = project.getModel().clone();
Review Comment:
how sure are we that clone works here?
##########
src/test/java/org/apache/maven/plugins/help/EffectivePomMojoTest.java:
##########
@@ -0,0 +1,122 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.maven.plugins.help;
+
+import javax.inject.Inject;
+
+import java.io.IOException;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.util.Collections;
+import java.util.Properties;
+
+import org.apache.maven.api.plugin.testing.InjectMojo;
+import org.apache.maven.api.plugin.testing.MojoParameter;
+import org.apache.maven.api.plugin.testing.MojoTest;
+import org.apache.maven.execution.MavenSession;
+import org.apache.maven.model.Model;
+import org.apache.maven.plugin.MojoExecution;
+import org.apache.maven.plugin.logging.Log;
+import org.apache.maven.project.MavenProject;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.ExtendWith;
+import org.junit.jupiter.api.io.TempDir;
+import org.mockito.Mock;
+import org.mockito.junit.jupiter.MockitoExtension;
+
+import static
org.apache.maven.api.plugin.testing.MojoExtension.setVariableValueToObject;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertSame;
+import static org.mockito.Mockito.when;
+
+/**
+ * Test class for the effective-pom mojo of the Help Plugin.
+ */
+@ExtendWith(MockitoExtension.class)
+@MojoTest
+class EffectivePomMojoTest {
+
+ @Inject
+ private MavenProject project;
+
+ @Inject
+ private MavenSession mavenSession;
+
+ @Mock
+ private Log log;
+
+ @Mock
+ private MojoExecution mojoExecution;
+
+ @TempDir
+ private Path tempDir;
+
+ private Path outputPath;
+
+ private Model model;
+
+ private Properties originalProperties;
+
+ private Properties expectedProperties;
+
+ @BeforeEach
+ void setup() throws IOException {
+ originalProperties = new Properties();
+ originalProperties.setProperty("b.property", "b-value");
+ originalProperties.setProperty("a.property", "a-value");
+
+ model = new Model();
+ model.setProperties(originalProperties);
+
+ when(project.getModel()).thenReturn(model);
+
+ outputPath = Files.createTempFile(tempDir, "maven-help-plugin-test-",
".xml");
+ mavenSession.getUserProperties().setProperty("outputPath",
outputPath.toString());
+ }
+
+ /**
+ * The effective-pom goal only displays the model, so it must not modify
the project it reads from.
+ *
+ * @throws Exception in case of errors.
+ */
+ @Test
+ @InjectMojo(goal = "effective-pom")
+ @MojoParameter(name = "output", value = "${outputPath}")
+ void testExecuteDoesNotModifyProjectModel(EffectivePomMojo mojo) throws
Exception {
+ // snapshot of the contents before the mojo runs, to detect in-place
modification
+ expectedProperties = new Properties();
Review Comment:
maybe this should be a local variable?
##########
src/test/java/org/apache/maven/plugins/help/EffectivePomMojoTest.java:
##########
@@ -0,0 +1,122 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.maven.plugins.help;
+
+import javax.inject.Inject;
+
+import java.io.IOException;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.util.Collections;
+import java.util.Properties;
+
+import org.apache.maven.api.plugin.testing.InjectMojo;
+import org.apache.maven.api.plugin.testing.MojoParameter;
+import org.apache.maven.api.plugin.testing.MojoTest;
+import org.apache.maven.execution.MavenSession;
+import org.apache.maven.model.Model;
+import org.apache.maven.plugin.MojoExecution;
+import org.apache.maven.plugin.logging.Log;
+import org.apache.maven.project.MavenProject;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.ExtendWith;
+import org.junit.jupiter.api.io.TempDir;
+import org.mockito.Mock;
+import org.mockito.junit.jupiter.MockitoExtension;
+
+import static
org.apache.maven.api.plugin.testing.MojoExtension.setVariableValueToObject;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertSame;
+import static org.mockito.Mockito.when;
+
+/**
+ * Test class for the effective-pom mojo of the Help Plugin.
+ */
+@ExtendWith(MockitoExtension.class)
+@MojoTest
+class EffectivePomMojoTest {
+
+ @Inject
+ private MavenProject project;
+
+ @Inject
+ private MavenSession mavenSession;
+
+ @Mock
+ private Log log;
+
+ @Mock
+ private MojoExecution mojoExecution;
+
+ @TempDir
+ private Path tempDir;
+
+ private Path outputPath;
+
+ private Model model;
+
+ private Properties originalProperties;
+
+ private Properties expectedProperties;
+
+ @BeforeEach
+ void setup() throws IOException {
+ originalProperties = new Properties();
Review Comment:
the field can be initialized directly
##########
src/test/java/org/apache/maven/plugins/help/EffectivePomMojoTest.java:
##########
@@ -0,0 +1,122 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.maven.plugins.help;
+
+import javax.inject.Inject;
+
+import java.io.IOException;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.util.Collections;
+import java.util.Properties;
+
+import org.apache.maven.api.plugin.testing.InjectMojo;
+import org.apache.maven.api.plugin.testing.MojoParameter;
+import org.apache.maven.api.plugin.testing.MojoTest;
+import org.apache.maven.execution.MavenSession;
+import org.apache.maven.model.Model;
+import org.apache.maven.plugin.MojoExecution;
+import org.apache.maven.plugin.logging.Log;
+import org.apache.maven.project.MavenProject;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.ExtendWith;
+import org.junit.jupiter.api.io.TempDir;
+import org.mockito.Mock;
+import org.mockito.junit.jupiter.MockitoExtension;
+
+import static
org.apache.maven.api.plugin.testing.MojoExtension.setVariableValueToObject;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertSame;
+import static org.mockito.Mockito.when;
+
+/**
+ * Test class for the effective-pom mojo of the Help Plugin.
+ */
+@ExtendWith(MockitoExtension.class)
+@MojoTest
+class EffectivePomMojoTest {
+
+ @Inject
+ private MavenProject project;
+
+ @Inject
+ private MavenSession mavenSession;
+
+ @Mock
+ private Log log;
+
+ @Mock
+ private MojoExecution mojoExecution;
+
+ @TempDir
+ private Path tempDir;
+
+ private Path outputPath;
+
+ private Model model;
+
+ private Properties originalProperties;
+
+ private Properties expectedProperties;
+
+ @BeforeEach
+ void setup() throws IOException {
+ originalProperties = new Properties();
+ originalProperties.setProperty("b.property", "b-value");
+ originalProperties.setProperty("a.property", "a-value");
+
+ model = new Model();
Review Comment:
the field can be initialized directly
##########
src/test/java/org/apache/maven/plugins/help/EffectivePomMojoTest.java:
##########
@@ -0,0 +1,122 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.maven.plugins.help;
+
+import javax.inject.Inject;
+
+import java.io.IOException;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.util.Collections;
+import java.util.Properties;
+
+import org.apache.maven.api.plugin.testing.InjectMojo;
+import org.apache.maven.api.plugin.testing.MojoParameter;
+import org.apache.maven.api.plugin.testing.MojoTest;
+import org.apache.maven.execution.MavenSession;
+import org.apache.maven.model.Model;
+import org.apache.maven.plugin.MojoExecution;
+import org.apache.maven.plugin.logging.Log;
+import org.apache.maven.project.MavenProject;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.ExtendWith;
+import org.junit.jupiter.api.io.TempDir;
+import org.mockito.Mock;
+import org.mockito.junit.jupiter.MockitoExtension;
+
+import static
org.apache.maven.api.plugin.testing.MojoExtension.setVariableValueToObject;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertSame;
+import static org.mockito.Mockito.when;
+
+/**
+ * Test class for the effective-pom mojo of the Help Plugin.
+ */
+@ExtendWith(MockitoExtension.class)
+@MojoTest
+class EffectivePomMojoTest {
+
+ @Inject
+ private MavenProject project;
+
+ @Inject
+ private MavenSession mavenSession;
+
+ @Mock
+ private Log log;
Review Comment:
can probably use a real Log
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]