-
Notifications
You must be signed in to change notification settings - Fork 267
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Resolves #990: Check prerequisites if required enforcer Maven version…
… is empty
- Loading branch information
Showing
8 changed files
with
425 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
160 changes: 160 additions & 0 deletions
160
...s-maven-plugin/src/test/java/org/codehaus/mojo/versions/DisplayPluginUpdatesMojoTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,160 @@ | ||
package org.codehaus.mojo.versions; | ||
|
||
/* | ||
* Copyright MojoHaus and Contributors | ||
* Licensed 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 | ||
* | ||
* https://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. | ||
*/ | ||
|
||
import java.nio.file.Files; | ||
import java.nio.file.Path; | ||
import java.nio.file.Paths; | ||
import java.util.HashMap; | ||
import java.util.List; | ||
|
||
import org.apache.maven.artifact.Artifact; | ||
import org.apache.maven.model.Prerequisites; | ||
import org.apache.maven.plugin.testing.AbstractMojoTestCase; | ||
import org.apache.maven.plugin.testing.MojoRule; | ||
import org.apache.maven.project.*; | ||
import org.codehaus.mojo.versions.utils.TestUtils; | ||
import org.junit.After; | ||
import org.junit.Before; | ||
import org.junit.Rule; | ||
import org.junit.Test; | ||
|
||
import static org.apache.commons.codec.CharEncoding.UTF_8; | ||
import static org.codehaus.mojo.versions.utils.MockUtils.mockAetherRepositorySystem; | ||
import static org.hamcrest.MatcherAssert.assertThat; | ||
import static org.hamcrest.Matchers.*; | ||
import static org.mockito.ArgumentMatchers.any; | ||
import static org.mockito.ArgumentMatchers.anyBoolean; | ||
import static org.mockito.Mockito.mock; | ||
import static org.mockito.Mockito.when; | ||
|
||
/** | ||
* Contains unit tests for {@link DisplayPluginUpdatesMojo}. | ||
* | ||
* @author Andrzej Jarmoniuk | ||
*/ | ||
public class DisplayPluginUpdatesMojoTest extends AbstractMojoTestCase { | ||
|
||
@Rule | ||
public MojoRule mojoRule = new MojoRule(this); | ||
|
||
private Path tempDir; | ||
|
||
private Path outputPath; | ||
|
||
@Before | ||
public void setUp() throws Exception { | ||
super.setUp(); | ||
tempDir = TestUtils.createTempDir("display-plugin-updates"); | ||
outputPath = Files.createTempFile(tempDir, "output", ""); | ||
} | ||
|
||
@After | ||
public void tearDown() throws Exception { | ||
try { | ||
TestUtils.tearDownTempDir(tempDir); | ||
} finally { | ||
super.tearDown(); | ||
} | ||
} | ||
|
||
private static ProjectBuilder mockupProjectBuilder() { | ||
Prerequisites prerequisites = new Prerequisites(); | ||
prerequisites.setMaven("3.6.3"); | ||
MavenProject mavenProject = mock(MavenProject.class); | ||
when(mavenProject.getPrerequisites()).thenReturn(prerequisites); | ||
ProjectBuildingResult projectBuildingResult = mock(ProjectBuildingResult.class); | ||
when(projectBuildingResult.getProject()).thenReturn(mavenProject); | ||
ProjectBuilder projectBuilder = mock(ProjectBuilder.class); | ||
try { | ||
when(projectBuilder.build(any(Artifact.class), anyBoolean(), any(ProjectBuildingRequest.class))) | ||
.thenReturn(projectBuildingResult); | ||
} catch (ProjectBuildingException e) { | ||
throw new RuntimeException(e); | ||
} | ||
return projectBuilder; | ||
} | ||
|
||
private DisplayPluginUpdatesMojo createMojo() throws Exception { | ||
DisplayPluginUpdatesMojo mojo = | ||
(DisplayPluginUpdatesMojo) mojoRule.lookupConfiguredMojo(tempDir.toFile(), "display-plugin-updates"); | ||
mojo.outputEncoding = UTF_8; | ||
mojo.outputFile = outputPath.toFile(); | ||
mojo.setPluginContext(new HashMap<>()); | ||
mojo.aetherRepositorySystem = mockAetherRepositorySystem(new HashMap<String, String[]>() { | ||
{ | ||
put("default-plugin", new String[] {"1.0.0"}); | ||
put("maven-enforcer-plugin", new String[] {"3.0.0"}); | ||
} | ||
}); | ||
setVariableValueToObject(mojo, "projectBuilder", mockupProjectBuilder()); | ||
return mojo; | ||
} | ||
|
||
@Test | ||
public void testNoEnforcer() throws Exception { | ||
Files.copy( | ||
Paths.get("src/test/resources/org/codehaus/mojo/display-plugin-updates/issue-990/no-enforcer.xml"), | ||
tempDir.resolve("pom.xml")); | ||
|
||
DisplayPluginUpdatesMojo mojo = createMojo(); | ||
mojo.execute(); | ||
|
||
List<String> output = Files.readAllLines(outputPath); | ||
assertThat(output, hasItem(containsString("Using the minimum version of Maven: 3.3.9"))); | ||
} | ||
|
||
@Test | ||
public void testNoPrerequisites() throws Exception { | ||
Files.copy( | ||
Paths.get("src/test/resources/org/codehaus/mojo/display-plugin-updates/issue-990/no-prerequisites.xml"), | ||
tempDir.resolve("pom.xml")); | ||
|
||
DisplayPluginUpdatesMojo mojo = createMojo(); | ||
mojo.execute(); | ||
|
||
List<String> output = Files.readAllLines(outputPath); | ||
assertThat(output, hasItem(containsString("Using the minimum version of Maven: 3.3.9"))); | ||
} | ||
|
||
@Test | ||
public void testPrerequisitesGreaterThanEnforcer() throws Exception { | ||
Files.copy( | ||
Paths.get( | ||
"src/test/resources/org/codehaus/mojo/display-plugin-updates/issue-990/prerequisites-greater.xml"), | ||
tempDir.resolve("pom.xml")); | ||
|
||
DisplayPluginUpdatesMojo mojo = createMojo(); | ||
mojo.execute(); | ||
|
||
List<String> output = Files.readAllLines(outputPath); | ||
assertThat(output, hasItem(containsString("Using the minimum version of Maven: 3.3.9"))); | ||
} | ||
|
||
@Test | ||
public void testPrerequisitesLesserThanEnforcer() throws Exception { | ||
Files.copy( | ||
Paths.get( | ||
"src/test/resources/org/codehaus/mojo/display-plugin-updates/issue-990/prerequisites-lesser.xml"), | ||
tempDir.resolve("pom.xml")); | ||
|
||
DisplayPluginUpdatesMojo mojo = createMojo(); | ||
mojo.execute(); | ||
|
||
List<String> output = Files.readAllLines(outputPath); | ||
assertThat(output, hasItem(containsString("Using the minimum version of Maven: 3.3.9"))); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
39 changes: 39 additions & 0 deletions
39
...gin/src/test/resources/org/codehaus/mojo/display-plugin-updates/issue-990/no-enforcer.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<!-- | ||
~ Copyright MojoHaus and Contributors | ||
~ Licensed 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 | ||
~ | ||
~ https://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. | ||
--> | ||
|
||
<project xmlns="http://maven.apache.org/POM/4.0.0" | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
<modelVersion>4.0.0</modelVersion> | ||
|
||
<groupId>default-group</groupId> | ||
<artifactId>default-artifact</artifactId> | ||
<version>1.0.0</version> | ||
|
||
<prerequisites> | ||
<maven>3.3.9</maven> | ||
</prerequisites> | ||
|
||
<build> | ||
<plugins> | ||
<plugin> | ||
<groupId>default-group</groupId> | ||
<artifactId>default-plugin</artifactId> | ||
<version>1.0.0</version> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
</project> |
55 changes: 55 additions & 0 deletions
55
...rc/test/resources/org/codehaus/mojo/display-plugin-updates/issue-990/no-prerequisites.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<!-- | ||
~ Copyright MojoHaus and Contributors | ||
~ Licensed 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 | ||
~ | ||
~ https://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. | ||
--> | ||
|
||
<project xmlns="http://maven.apache.org/POM/4.0.0" | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
<modelVersion>4.0.0</modelVersion> | ||
|
||
<groupId>default-group</groupId> | ||
<artifactId>default-artifact</artifactId> | ||
<version>1.0.0</version> | ||
|
||
<build> | ||
<plugins> | ||
<plugin> | ||
<groupId>default-group</groupId> | ||
<artifactId>default-plugin</artifactId> | ||
<version>1.0.0</version> | ||
</plugin> | ||
|
||
<plugin> | ||
<artifactId>maven-enforcer-plugin</artifactId> | ||
<version>3.0.0</version> | ||
<executions> | ||
<execution> | ||
<id>enforce-maven</id> | ||
<goals> | ||
<goal>enforce</goal> | ||
</goals> | ||
<configuration> | ||
<rules> | ||
<requireMavenVersion> | ||
<version>3.3.9</version> | ||
</requireMavenVersion> | ||
</rules> | ||
</configuration> | ||
</execution> | ||
</executions> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
</project> |
Oops, something went wrong.