maven git commit: [MNG-6275] Defang the tests when their core assumption is invalid.

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

maven git commit: [MNG-6275] Defang the tests when their core assumption is invalid.

stephenc
Repository: maven
Updated Branches:
  refs/heads/master 312eb5350 -> 542a7a891


[MNG-6275] Defang the tests when their core assumption is invalid.

- The tests assume that the JRE has a ScriptEngineFactory
- Not all JREs have a ScriptEngineFactory (I'm looking at Azul's Zulu Open JDK 7 builds)
- Ideally we'd skip these tests using Assume.assumeThat(...) but PlexusTestCase doesn't support
  AssumptionViolatedException for marking tests as skipped.

Issue identified during testing of the 3.5.1 release candidate


Project: http://git-wip-us.apache.org/repos/asf/maven/repo
Commit: http://git-wip-us.apache.org/repos/asf/maven/commit/542a7a89
Tree: http://git-wip-us.apache.org/repos/asf/maven/tree/542a7a89
Diff: http://git-wip-us.apache.org/repos/asf/maven/diff/542a7a89

Branch: refs/heads/master
Commit: 542a7a89156263b34d1472e9d9c1a2795afccd2d
Parents: 312eb53
Author: Stephen Connolly <[hidden email]>
Authored: Mon Sep 11 10:25:11 2017 +0100
Committer: Stephen Connolly <[hidden email]>
Committed: Mon Sep 11 10:25:11 2017 +0100

----------------------------------------------------------------------
 .../classrealm/DefaultClassRealmManagerTest.java    | 16 +++++++++++-----
 1 file changed, 11 insertions(+), 5 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/maven/blob/542a7a89/maven-core/src/test/java/org/apache/maven/classrealm/DefaultClassRealmManagerTest.java
----------------------------------------------------------------------
diff --git a/maven-core/src/test/java/org/apache/maven/classrealm/DefaultClassRealmManagerTest.java b/maven-core/src/test/java/org/apache/maven/classrealm/DefaultClassRealmManagerTest.java
index 726199f..6d074b9 100644
--- a/maven-core/src/test/java/org/apache/maven/classrealm/DefaultClassRealmManagerTest.java
+++ b/maven-core/src/test/java/org/apache/maven/classrealm/DefaultClassRealmManagerTest.java
@@ -34,6 +34,7 @@ import org.junit.Test;
 public class DefaultClassRealmManagerTest extends PlexusTestCase
 {
     private ClassRealmManager classRealmManager;
+    private boolean haveScriptEngineFactory;
 
     @Override
     protected void setUp()
@@ -41,6 +42,11 @@ public class DefaultClassRealmManagerTest extends PlexusTestCase
     {
         super.setUp();
         this.classRealmManager = lookup( ClassRealmManager.class );
+        ClassLoader testRealm = getClass().getClassLoader();
+        ServiceLoader<ScriptEngineFactory> sef = ServiceLoader.load( ScriptEngineFactory.class, testRealm );
+        // TODO switch to Assume.assumeTrue( sef.iterator().hasNext() ) when PlexusTestCase
+        // supports assumptions. Not every Java 7 JRE has a ScriptEngineFactory.
+        this.haveScriptEngineFactory = sef.iterator().hasNext();
     }
 
     @Override
@@ -59,7 +65,7 @@ public class DefaultClassRealmManagerTest extends PlexusTestCase
         
         ClassRealm pluginRealm = classRealmManager.createPluginRealm( plugin, parent, null, null, null );
         ServiceLoader<ScriptEngineFactory> sef = ServiceLoader.load( ScriptEngineFactory.class, pluginRealm );
-        assertTrue( sef.iterator().hasNext() );
+        assertEquals( haveScriptEngineFactory, sef.iterator().hasNext() );
     }
 
     @Test
@@ -70,7 +76,7 @@ public class DefaultClassRealmManagerTest extends PlexusTestCase
         
         ClassRealm extensionRealm = classRealmManager.createExtensionRealm( extension, null );
         ServiceLoader<ScriptEngineFactory> sef = ServiceLoader.load( ScriptEngineFactory.class, extensionRealm );
-        assertTrue( sef.iterator().hasNext() );
+        assertEquals( haveScriptEngineFactory, sef.iterator().hasNext() );
     }
 
     @Test
@@ -80,7 +86,7 @@ public class DefaultClassRealmManagerTest extends PlexusTestCase
         
         ClassRealm projectRealm = classRealmManager.createProjectRealm( model, null );
         ServiceLoader<ScriptEngineFactory> sef = ServiceLoader.load( ScriptEngineFactory.class, projectRealm );
-        assertTrue( sef.iterator().hasNext() );
+        assertEquals( haveScriptEngineFactory, sef.iterator().hasNext() );
     }
 
     @Test
@@ -88,7 +94,7 @@ public class DefaultClassRealmManagerTest extends PlexusTestCase
     {
         ClassRealm mavenApiRealm = classRealmManager.getMavenApiRealm();
         ServiceLoader<ScriptEngineFactory> sef = ServiceLoader.load( ScriptEngineFactory.class, mavenApiRealm );
-        assertTrue( sef.iterator().hasNext() );
+        assertEquals( haveScriptEngineFactory, sef.iterator().hasNext() );
     }
 
     @Test
@@ -96,6 +102,6 @@ public class DefaultClassRealmManagerTest extends PlexusTestCase
     {
         ClassRealm coreRealm = classRealmManager.getCoreRealm();
         ServiceLoader<ScriptEngineFactory> sef = ServiceLoader.load( ScriptEngineFactory.class, coreRealm );
-        assertTrue( sef.iterator().hasNext() );
+        assertEquals( haveScriptEngineFactory, sef.iterator().hasNext() );
     }
 }