You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by kh...@apache.org on 2018/06/17 17:16:11 UTC
[maven-enforcer] 01/02: Updated.
This is an automated email from the ASF dual-hosted git repository.
khmarbaise pushed a commit to branch MENFORCER-288
in repository https://gitbox.apache.org/repos/asf/maven-enforcer.git
commit e5511e9bda47ad5ff3aaa66badca971f0ad88aca
Author: Karl Heinz Marbaise <kh...@apache.org>
AuthorDate: Sat Feb 10 16:04:47 2018 +0100
Updated.
---
enforcer-rules/pom.xml | 14 ++-
.../plugins/enforcer/RequireJavaVesionTest.java | 119 +++++++++++++++++++++
pom.xml | 21 +++-
3 files changed, 149 insertions(+), 5 deletions(-)
diff --git a/enforcer-rules/pom.xml b/enforcer-rules/pom.xml
index abfd146..7e92e2b 100644
--- a/enforcer-rules/pom.xml
+++ b/enforcer-rules/pom.xml
@@ -18,7 +18,8 @@
* 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">
+<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>
<parent>
@@ -98,7 +99,16 @@
<artifactId>assertj-core</artifactId>
<scope>test</scope>
</dependency>
-
+ <dependency>
+ <groupId>org.powermock</groupId>
+ <artifactId>powermock-module-junit4</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.powermock</groupId>
+ <artifactId>powermock-api-mockito2</artifactId>
+ <scope>test</scope>
+ </dependency>
</dependencies>
<build>
diff --git a/enforcer-rules/src/test/java/org/apache/maven/plugins/enforcer/RequireJavaVesionTest.java b/enforcer-rules/src/test/java/org/apache/maven/plugins/enforcer/RequireJavaVesionTest.java
new file mode 100644
index 0000000..4439744
--- /dev/null
+++ b/enforcer-rules/src/test/java/org/apache/maven/plugins/enforcer/RequireJavaVesionTest.java
@@ -0,0 +1,119 @@
+package org.apache.maven.plugins.enforcer;
+
+/*
+ * 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.
+ */
+
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+
+import org.apache.commons.lang3.SystemUtils;
+import org.apache.maven.enforcer.rule.api.EnforcerRuleException;
+import org.apache.maven.enforcer.rule.api.EnforcerRuleHelper;
+import org.apache.maven.plugin.logging.Log;
+import org.junit.Before;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.rules.ExpectedException;
+import org.junit.runner.RunWith;
+import org.powermock.core.classloader.annotations.PrepareForTest;
+import org.powermock.modules.junit4.PowerMockRunner;
+import org.powermock.reflect.Whitebox;
+
+/**
+ * The Class RequireJavaVersionTest
+ *
+ * @author Karl Heinz Marbaise <a href="mailto:khmarbaise@apache.org">khmarbaise@apache.org</a>
+ */
+@RunWith( PowerMockRunner.class )
+@PrepareForTest( { SystemUtils.class } )
+public class RequireJavaVesionTest
+{
+
+ private EnforcerRuleHelper helper;
+
+ private RequireJavaVersion rule;
+
+ @Before
+ public void before()
+ {
+
+ helper = mock( EnforcerRuleHelper.class );
+
+ Log log = mock( Log.class );
+ when( helper.getLog() ).thenReturn( log );
+
+ }
+
+ @Rule
+ public ExpectedException exception = ExpectedException.none();
+
+ @Test
+ public void first()
+ throws EnforcerRuleException
+ {
+ Whitebox.setInternalState( SystemUtils.class, "JAVA_VERSION", "1.4" );
+
+ rule = new RequireJavaVersion();
+ rule.setVersion( "1.5" );
+
+ exception.expect( EnforcerRuleException.class );
+ exception.expectMessage( "Detected JDK Version: 1.4 is not in the allowed range 1.5." );
+ rule.execute( helper );
+ }
+
+ @Test
+ public void second()
+ throws EnforcerRuleException
+ {
+ Whitebox.setInternalState( SystemUtils.class, "JAVA_VERSION", "1.8" );
+
+ rule = new RequireJavaVersion();
+ rule.setVersion( "1.9" );
+ exception.expect( EnforcerRuleException.class );
+ exception.expectMessage( "Detected JDK Version: 1.8 is not in the allowed range 1.9." );
+ rule.execute( helper );
+ }
+
+ @Test
+ public void third()
+ throws EnforcerRuleException
+ {
+ Whitebox.setInternalState( SystemUtils.class, "JAVA_VERSION", "9.0.4" );
+
+ rule = new RequireJavaVersion();
+ rule.setVersion( "9.0.5" );
+ exception.expect( EnforcerRuleException.class );
+ exception.expectMessage( "Detected JDK Version: 9.0.4 is not in the allowed range 9.0.5." );
+ rule.execute( helper );
+ }
+
+ @Test
+ public void forth()
+ throws EnforcerRuleException
+ {
+ Whitebox.setInternalState( SystemUtils.class, "JAVA_VERSION", "1.8.0_b192" );
+
+ rule = new RequireJavaVersion();
+ rule.setVersion( "8" );
+ exception.expect( EnforcerRuleException.class );
+ exception.expectMessage( "Detected JDK Version: 9.0.4 is not in the allowed range 9.0.5." );
+ rule.execute( helper );
+ }
+
+}
diff --git a/pom.xml b/pom.xml
index c9c17fe..07d7b65 100644
--- a/pom.xml
+++ b/pom.xml
@@ -17,7 +17,8 @@
~ 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">
+<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>
<parent>
@@ -65,7 +66,8 @@
<properties>
<maven.version>3.0</maven.version>
<maven.site.path>enforcer-archives/enforcer-LATEST</maven.site.path>
- <surefire.version>2.21.0</surefire.version>
+ <surefire.version>2.21.0</surefire.version>
+ <powermock.version>1.7.1</powermock.version>
</properties>
<dependencyManagement>
@@ -130,9 +132,22 @@
<scope>test</scope>
</dependency>
<dependency>
+ <groupId>org.powermock</groupId>
+ <artifactId>powermock-module-junit4</artifactId>
+ <version>${powermock.version}</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.powermock</groupId>
+ <artifactId>powermock-api-mockito2</artifactId>
+ <version>${powermock.version}</version>
+ <scope>test</scope>
+ </dependency>
+
+ <dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
- <version>3.5</version> <!-- commons-lang3 >= 3.6 require at least Java 7 -->
+ <version>3.7</version> <!-- commons-lang3 >= 3.6 require at least Java 7 -->
</dependency>
<dependency>
<groupId>commons-codec</groupId>
--
To stop receiving notification emails like this one, please contact
khmarbaise@apache.org.