Author: brett
Date: Wed Feb  4 13:53:31 2009
New Revision: 740740

URL: http://svn.apache.org/viewvc?rev=740740&view=rev
Log:
[MNG-1957] added a test case for the JDK profile activator

Added:
    
maven/components/branches/maven-2.1.x/maven-project/src/test/java/org/apache/maven/profiles/activation/
    
maven/components/branches/maven-2.1.x/maven-project/src/test/java/org/apache/maven/profiles/activation/JdkPrefixProfileActivatorTest.java
   (with props)
Modified:
    
maven/components/branches/maven-2.1.x/maven-project/src/main/java/org/apache/maven/profiles/activation/JdkPrefixProfileActivator.java

Modified: 
maven/components/branches/maven-2.1.x/maven-project/src/main/java/org/apache/maven/profiles/activation/JdkPrefixProfileActivator.java
URL: 
http://svn.apache.org/viewvc/maven/components/branches/maven-2.1.x/maven-project/src/main/java/org/apache/maven/profiles/activation/JdkPrefixProfileActivator.java?rev=740740&r1=740739&r2=740740&view=diff
==============================================================================
--- 
maven/components/branches/maven-2.1.x/maven-project/src/main/java/org/apache/maven/profiles/activation/JdkPrefixProfileActivator.java
 (original)
+++ 
maven/components/branches/maven-2.1.x/maven-project/src/main/java/org/apache/maven/profiles/activation/JdkPrefixProfileActivator.java
 Wed Feb  4 13:53:31 2009
@@ -43,7 +43,7 @@
         }
 
         // null case is covered by canDetermineActivation(), so we can do a 
straight startsWith() here.
-        boolean result = JDK_VERSION.startsWith( jdk );
+        boolean result = getJdkVersion().startsWith( jdk );
         
         if ( reverse )
         {
@@ -55,6 +55,11 @@
         }
     }
 
+    protected String getJdkVersion()
+    {
+        return JDK_VERSION;
+    }
+
     protected boolean canDetectActivation( Profile profile )
     {
         return profile.getActivation() != null && StringUtils.isNotEmpty( 
profile.getActivation().getJdk() );

Added: 
maven/components/branches/maven-2.1.x/maven-project/src/test/java/org/apache/maven/profiles/activation/JdkPrefixProfileActivatorTest.java
URL: 
http://svn.apache.org/viewvc/maven/components/branches/maven-2.1.x/maven-project/src/test/java/org/apache/maven/profiles/activation/JdkPrefixProfileActivatorTest.java?rev=740740&view=auto
==============================================================================
--- 
maven/components/branches/maven-2.1.x/maven-project/src/test/java/org/apache/maven/profiles/activation/JdkPrefixProfileActivatorTest.java
 (added)
+++ 
maven/components/branches/maven-2.1.x/maven-project/src/test/java/org/apache/maven/profiles/activation/JdkPrefixProfileActivatorTest.java
 Wed Feb  4 13:53:31 2009
@@ -0,0 +1,117 @@
+package org.apache.maven.profiles.activation;
+
+/*
+ * 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 org.apache.maven.model.Activation;
+import org.apache.maven.model.Profile;
+
+import junit.framework.TestCase;
+
+public class JdkPrefixProfileActivatorTest
+    extends TestCase
+{
+    public void testDetectionWithoutActivationElement()
+    {
+        JdkPrefixProfileActivator activator = createActivator();
+
+        Profile profile = new Profile();
+
+        assertFalse( activator.canDetectActivation( profile ) );
+    }
+
+    public void testDetectionWithoutJdkElement()
+    {
+        JdkPrefixProfileActivator activator = createActivator();
+
+        Profile profile = createProfile( null );
+
+        assertFalse( activator.canDetectActivation( profile ) );
+    }
+
+    public void testDetectionWithJdkElement()
+    {
+        JdkPrefixProfileActivator activator = createActivator();
+
+        Profile profile = createProfile( "1.5" );
+
+        assertTrue( activator.canDetectActivation( profile ) );
+    }
+
+    public void testActivationWithMatchingJdkVersion()
+    {
+        JdkPrefixProfileActivator activator = createActivator( "1.5.0_15" );
+
+        Profile profile = createProfile( "1.5" );
+
+        assertTrue( activator.isActive( profile ) );
+    }
+
+    public void testActivationWithoutMatchingJdkVersion()
+    {
+        JdkPrefixProfileActivator activator = createActivator( "1.5.0_15" );
+
+        Profile profile = createProfile( "1.4" );
+
+        assertFalse( activator.isActive( profile ) );
+    }
+
+    public void testActivationWithMatchingNegatedJdkVersion()
+    {
+        JdkPrefixProfileActivator activator = createActivator( "1.5.0_15" );
+
+        Profile profile = createProfile( "!1.4" );
+
+        assertTrue( activator.isActive( profile ) );
+    }
+
+    public void testActivationWithoutMatchingNegatedJdkVersion()
+    {
+        JdkPrefixProfileActivator activator = createActivator( "1.5.0_15" );
+
+        Profile profile = createProfile( "!1.5" );
+
+        assertFalse( activator.isActive( profile ) );
+    }
+
+    private static JdkPrefixProfileActivator createActivator()
+    {
+        return new JdkPrefixProfileActivator();
+    }
+
+    private static JdkPrefixProfileActivator createActivator( final String 
testJdkVersion )
+    {
+        return new JdkPrefixProfileActivator()
+        {
+            protected String getJdkVersion()
+            {
+                return testJdkVersion;
+            }
+        };
+    }
+
+    private static Profile createProfile( String jdk )
+    {
+        Profile profile = new Profile();
+        Activation activation = new Activation();
+        activation.setJdk( jdk );
+        profile.setActivation( activation );
+        return profile;
+    }
+}

Propchange: 
maven/components/branches/maven-2.1.x/maven-project/src/test/java/org/apache/maven/profiles/activation/JdkPrefixProfileActivatorTest.java
------------------------------------------------------------------------------
    svn:eol-style = native


Reply via email to