[maven-enforcer] branch MENFORCER-288 created (now 5efae6a)

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

[maven-enforcer] branch MENFORCER-288 created (now 5efae6a)

khmarbaise
This is an automated email from the ASF dual-hosted git repository.

khmarbaise pushed a change to branch MENFORCER-288
in repository https://gitbox.apache.org/repos/asf/maven-enforcer.git.


      at 5efae6a  Updated.

This branch includes the following new commits:

     new 5efae6a  Updated.

The 1 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


--
To stop receiving notification emails like this one, please contact
[hidden email].
Reply | Threaded
Open this post in threaded view
|

[maven-enforcer] 01/01: Updated.

khmarbaise
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 5efae6a32558e73b189abe79da68dbc75ba8e253
Author: Karl Heinz Marbaise <[hidden email]>
AuthorDate: Sat Feb 10 16:04:47 2018 +0100

    Updated.
---
 enforcer-rules/pom.xml                             |  14 ++-
 .../plugins/enforcer/RequireJavaVesionTest.java    | 119 +++++++++++++++++++++
 pom.xml                                            |  19 +++-
 3 files changed, 148 insertions(+), 4 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:[hidden email]">[hidden email]</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 1ab36dd..92f314f 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,6 +66,7 @@
   <properties>
     <maven.version>3.0</maven.version>
     <maven.site.path>enforcer-archives/enforcer-LATEST</maven.site.path>
+    <powermock.version>1.7.1</powermock.version>
   </properties>
 
   <dependencyManagement>
@@ -129,9 +131,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
[hidden email].