maven-surefire-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From krosenv...@apache.org
Subject svn commit: r1076672 - in /maven/surefire/trunk: maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/booterclient/ maven-surefire-common/src/test/java/org/apache/maven/plugin/surefire/booterclient/ surefire-booter/src/main/java/org/apa...
Date Thu, 03 Mar 2011 16:36:32 GMT
Author: krosenvold
Date: Thu Mar  3 16:36:32 2011
New Revision: 1076672

URL: http://svn.apache.org/viewvc?rev=1076672&view=rev
Log:
[SUREFIRE-702] Improve transformation from properties->classpath

Based on patch by Stephan Birkner, modified by me.

Modified:
    maven/surefire/trunk/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/booterclient/BooterSerializer.java
    maven/surefire/trunk/maven-surefire-common/src/test/java/org/apache/maven/plugin/surefire/booterclient/BooterDeserializerStartupConfigurationTest.java
    maven/surefire/trunk/surefire-booter/src/main/java/org/apache/maven/surefire/booter/BooterConstants.java
    maven/surefire/trunk/surefire-booter/src/main/java/org/apache/maven/surefire/booter/BooterDeserializer.java
    maven/surefire/trunk/surefire-booter/src/main/java/org/apache/maven/surefire/booter/Classpath.java
    maven/surefire/trunk/surefire-booter/src/main/java/org/apache/maven/surefire/booter/ClasspathConfiguration.java
    maven/surefire/trunk/surefire-booter/src/main/java/org/apache/maven/surefire/booter/PropertiesWrapper.java
    maven/surefire/trunk/surefire-booter/src/test/java/org/apache/maven/surefire/booter/ClasspathTest.java
    maven/surefire/trunk/surefire-booter/src/test/java/org/apache/maven/surefire/booter/PropertiesWrapperTest.java

Modified: maven/surefire/trunk/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/booterclient/BooterSerializer.java
URL: http://svn.apache.org/viewvc/maven/surefire/trunk/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/booterclient/BooterSerializer.java?rev=1076672&r1=1076671&r2=1076672&view=diff
==============================================================================
--- maven/surefire/trunk/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/booterclient/BooterSerializer.java
(original)
+++ maven/surefire/trunk/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/booterclient/BooterSerializer.java
Thu Mar  3 16:36:32 2011
@@ -77,7 +77,7 @@ public class BooterSerializer
             new Object[]{ BooterConstants.DIRSCANNER_OPTIONS, booterConfiguration.getDirScannerParamsArray()
} );
         addPropertiesForTypeHolder( params, properties.getProperties(), BooterConstants.DIRSCANNER_PROPERTY_PREFIX
);
 
-        providerConfiguration.getClasspathConfiguration().setForkProperties( properties.getProperties()
);
+        providerConfiguration.getClasspathConfiguration().setForkProperties( properties);
 
         TestArtifactInfo testNg = booterConfiguration.getTestArtifact();
         if ( testNg != null )

Modified: maven/surefire/trunk/maven-surefire-common/src/test/java/org/apache/maven/plugin/surefire/booterclient/BooterDeserializerStartupConfigurationTest.java
URL: http://svn.apache.org/viewvc/maven/surefire/trunk/maven-surefire-common/src/test/java/org/apache/maven/plugin/surefire/booterclient/BooterDeserializerStartupConfigurationTest.java?rev=1076672&r1=1076671&r2=1076672&view=diff
==============================================================================
--- maven/surefire/trunk/maven-surefire-common/src/test/java/org/apache/maven/plugin/surefire/booterclient/BooterDeserializerStartupConfigurationTest.java
(original)
+++ maven/surefire/trunk/maven-surefire-common/src/test/java/org/apache/maven/plugin/surefire/booterclient/BooterDeserializerStartupConfigurationTest.java
Thu Mar  3 16:36:32 2011
@@ -24,15 +24,14 @@ import java.io.FileInputStream;
 import java.io.IOException;
 import java.util.ArrayList;
 import java.util.Arrays;
-import java.util.List;
 import java.util.Properties;
 
 import junit.framework.TestCase;
 
-import org.apache.maven.surefire.booter.BooterConstants;
 import org.apache.maven.surefire.booter.BooterDeserializer;
 import org.apache.maven.surefire.booter.ClassLoaderConfiguration;
 import org.apache.maven.surefire.booter.ClasspathConfiguration;
+import org.apache.maven.surefire.booter.PropertiesWrapper;
 import org.apache.maven.surefire.booter.ProviderConfiguration;
 import org.apache.maven.surefire.booter.StartupConfiguration;
 import org.apache.maven.surefire.booter.SystemPropertyManager;
@@ -49,13 +48,10 @@ import org.apache.maven.surefire.testset
 public class BooterDeserializerStartupConfigurationTest
     extends TestCase
 {
+    private final ClasspathConfiguration classpathConfiguration = createClasspathConfiguration();
 
     private final String aTest = "aTest";
 
-    private final String aUserRequestedTest = "aUserRequestedTest";
-    
-    private final String aUserRequestedTestMethod = "aUserRequestedTestMethod";
-
     public void testProvider()
         throws IOException
     {
@@ -65,18 +61,25 @@ public class BooterDeserializerStartupCo
     public void testClassPathConfiguration()
         throws IOException
     {
-        final ClasspathConfiguration classpathConfiguration =
+        ClasspathConfiguration reloadedClasspathConfiguration =
             getReloadedStartupConfiguration().getClasspathConfiguration();
-        Properties props = new Properties();
-        classpathConfiguration.setForkProperties( props );
-        List testClassPathUrls = classpathConfiguration.getTestClasspath().getClassPath();
-        assertEquals( "true", props.get( BooterConstants.ENABLE_ASSERTIONS ) );
-        assertEquals( "true", props.get( BooterConstants.CHILD_DELEGATION ) );
-        assertEquals( 2, testClassPathUrls.size() );
-        assertEquals( "CP1", testClassPathUrls.get( 0 ) );
-        assertEquals( "CP2", testClassPathUrls.get( 1 ) );
-        assertEquals( "SP1", props.get( BooterConstants.SUREFIRE_CLASSPATHURL + "0" ) );
-        assertEquals( "SP2", props.get( BooterConstants.SUREFIRE_CLASSPATHURL + "1" ) );
+        assertEquals( classpathConfiguration, reloadedClasspathConfiguration );
+    }
+
+    private void assertEquals( ClasspathConfiguration expectedConfiguration, ClasspathConfiguration
actualConfiguration )
+    {
+        assertEquals( expectedConfiguration.getTestClasspath().getClassPath(),
+                      actualConfiguration.getTestClasspath().getClassPath() );
+        Properties propertiesForExpectedConfiguration = getPropertiesForClasspathConfiguration(
expectedConfiguration );
+        Properties propertiesForActualConfiguration = getPropertiesForClasspathConfiguration(
actualConfiguration );
+        assertEquals( propertiesForExpectedConfiguration, propertiesForActualConfiguration
);
+    }
+
+    private Properties getPropertiesForClasspathConfiguration( ClasspathConfiguration configuration
)
+    {
+        Properties properties = new Properties();
+        configuration.setForkProperties( new PropertiesWrapper( properties ));
+        return properties;
     }
 
     public void testClassLoaderConfiguration()
@@ -94,6 +97,15 @@ public class BooterDeserializerStartupCo
         assertEquals( current, saveAndReload( testStartupConfiguration ).isManifestOnlyJarRequestedAndUsable()
);
     }
 
+    private ClasspathConfiguration createClasspathConfiguration()
+    {
+        ClasspathConfiguration classpathConfiguration = new ClasspathConfiguration( true,
true );
+        classpathConfiguration.addClasspathUrl( "CP1" );
+        classpathConfiguration.addClasspathUrl( "CP2" );
+        classpathConfiguration.addSurefireClasspathUrl( "SP1" );
+        classpathConfiguration.addSurefireClasspathUrl( "SP2" );
+        return classpathConfiguration;
+    }
 
     public static ClassLoaderConfiguration getSystemClassLoaderConfiguration()
         throws IOException
@@ -137,8 +149,11 @@ public class BooterDeserializerStartupCo
             new DirectoryScannerParameters( cwd, new ArrayList(), new ArrayList(), Boolean.TRUE,
"hourly" );
         ReporterConfiguration reporterConfiguration =
             new ReporterConfiguration( new ArrayList(), cwd, Boolean.TRUE, null );
+        String aUserRequestedTest = "aUserRequestedTest";
+        String aUserRequestedTestMethod = "aUserRequestedTestMethod";
         TestRequest testSuiteDefinition =
-            new TestRequest( Arrays.asList( getSuiteXmlFileStrings() ), getTestSourceDirectory(),
aUserRequestedTest, aUserRequestedTestMethod );
+            new TestRequest( Arrays.asList( getSuiteXmlFileStrings() ), getTestSourceDirectory(),
aUserRequestedTest,
+                             aUserRequestedTestMethod );
         return new ProviderConfiguration( directoryScannerParameters, true, reporterConfiguration,
                                           new TestArtifactInfo( "5.0", "ABC" ), testSuiteDefinition,
new Properties(),
                                           aTest );
@@ -146,11 +161,6 @@ public class BooterDeserializerStartupCo
 
     private StartupConfiguration getTestStartupConfiguration( ClassLoaderConfiguration classLoaderConfiguration
)
     {
-        ClasspathConfiguration classpathConfiguration = new ClasspathConfiguration( true,
true );
-        classpathConfiguration.addClasspathUrl( "CP1" );
-        classpathConfiguration.addClasspathUrl( "CP2" );
-        classpathConfiguration.addSurefireClasspathUrl( "SP1" );
-        classpathConfiguration.addSurefireClasspathUrl( "SP2" );
         return new StartupConfiguration( "com.provider", classpathConfiguration, classLoaderConfiguration,
false, false,
                                          false );
     }

Modified: maven/surefire/trunk/surefire-booter/src/main/java/org/apache/maven/surefire/booter/BooterConstants.java
URL: http://svn.apache.org/viewvc/maven/surefire/trunk/surefire-booter/src/main/java/org/apache/maven/surefire/booter/BooterConstants.java?rev=1076672&r1=1076671&r2=1076672&view=diff
==============================================================================
--- maven/surefire/trunk/surefire-booter/src/main/java/org/apache/maven/surefire/booter/BooterConstants.java
(original)
+++ maven/surefire/trunk/surefire-booter/src/main/java/org/apache/maven/surefire/booter/BooterConstants.java
Thu Mar  3 16:36:32 2011
@@ -34,10 +34,6 @@ public interface BooterConstants
     String REPORT_PROPERTY_PREFIX = "report.";
     String PARAMS_SUFIX = ".params";
     String TYPES_SUFIX = ".types";
-    String CLASSPATH_URL = "classPathUrl.";
-    String SUREFIRE_CLASSPATHURL = "surefireClassPathUrl.";
-    String CHILD_DELEGATION = "childDelegation";
-    String ENABLE_ASSERTIONS = "enableAssertions";
     String USESYSTEMCLASSLOADER = "useSystemClassLoader";
     String USEMANIFESTONLYJAR = "useManifestOnlyJar";
     String FAILIFNOTESTS = "failIfNoTests";

Modified: maven/surefire/trunk/surefire-booter/src/main/java/org/apache/maven/surefire/booter/BooterDeserializer.java
URL: http://svn.apache.org/viewvc/maven/surefire/trunk/surefire-booter/src/main/java/org/apache/maven/surefire/booter/BooterDeserializer.java?rev=1076672&r1=1076671&r2=1076672&view=diff
==============================================================================
--- maven/surefire/trunk/surefire-booter/src/main/java/org/apache/maven/surefire/booter/BooterDeserializer.java
(original)
+++ maven/surefire/trunk/surefire-booter/src/main/java/org/apache/maven/surefire/booter/BooterDeserializer.java
Thu Mar  3 16:36:32 2011
@@ -96,20 +96,14 @@ public class BooterDeserializer
     public StartupConfiguration getProviderConfiguration()
         throws IOException
     {
-        boolean enableAssertions = properties.getBooleanProperty( ENABLE_ASSERTIONS );
-        boolean childDelegation = properties.getBooleanProperty( CHILD_DELEGATION );
         boolean useSystemClassLoader = properties.getBooleanProperty( USESYSTEMCLASSLOADER
);
         boolean useManifestOnlyJar = properties.getBooleanProperty( USEMANIFESTONLYJAR );
         String providerConfiguration = properties.getProperty( PROVIDER_CONFIGURATION );
 
-        Classpath classpath = Classpath.readFromForkProperties( properties, CLASSPATH_URL
);
-        Classpath sureFireClasspath = Classpath.readFromForkProperties( properties, SUREFIRE_CLASSPATHURL
);
-
         ClassLoaderConfiguration classLoaderConfiguration =
             new ClassLoaderConfiguration( useSystemClassLoader, useManifestOnlyJar );
 
-        ClasspathConfiguration classpathConfiguration =
-            new ClasspathConfiguration( classpath, sureFireClasspath, enableAssertions, childDelegation
);
+        ClasspathConfiguration classpathConfiguration = new ClasspathConfiguration( properties
);
 
         return StartupConfiguration.inForkedVm( providerConfiguration, classpathConfiguration,
                                                 classLoaderConfiguration );

Modified: maven/surefire/trunk/surefire-booter/src/main/java/org/apache/maven/surefire/booter/Classpath.java
URL: http://svn.apache.org/viewvc/maven/surefire/trunk/surefire-booter/src/main/java/org/apache/maven/surefire/booter/Classpath.java?rev=1076672&r1=1076671&r2=1076672&view=diff
==============================================================================
--- maven/surefire/trunk/surefire-booter/src/main/java/org/apache/maven/surefire/booter/Classpath.java
(original)
+++ maven/surefire/trunk/surefire-booter/src/main/java/org/apache/maven/surefire/booter/Classpath.java
Thu Mar  3 16:36:32 2011
@@ -24,10 +24,8 @@ import org.apache.maven.surefire.util.Ur
 import java.io.File;
 import java.net.MalformedURLException;
 import java.util.ArrayList;
-import java.util.Collection;
 import java.util.Iterator;
 import java.util.List;
-import java.util.Properties;
 
 /**
  * An ordered set of classpath elements
@@ -36,12 +34,6 @@ import java.util.Properties;
  */
 public class Classpath
 {
-    static Classpath readFromForkProperties( PropertiesWrapper properties, String prefix
)
-    {
-        List elements = properties.getStringList( prefix );
-        return new Classpath( elements );
-    }
-
     public static Classpath join( Classpath firstClasspath, Classpath secondClasspath )
     {
         Classpath joinedClasspath = new Classpath();
@@ -74,7 +66,7 @@ public class Classpath
         }
     }
 
-    private void addElements( Collection additionalElements )
+    private void addElements( List additionalElements )
     {
         for ( Iterator it = additionalElements.iterator(); it.hasNext(); )
         {
@@ -109,15 +101,6 @@ public class Classpath
         return urls;
     }
 
-    void writeToForkProperties( Properties properties, String prefix )
-    {
-        for ( int i = 0; i < elements.size(); ++i )
-        {
-            String element = (String) elements.get( i );
-            properties.setProperty( prefix + i, element );
-        }
-    }
-
     public void writeToSystemProperty( String propertyName )
     {
         StringBuffer sb = new StringBuffer();
@@ -127,4 +110,26 @@ public class Classpath
         }
         System.setProperty( propertyName, sb.toString() );
     }
+
+    public boolean equals( Object o )
+    {
+        if ( this == o )
+        {
+            return true;
+        }
+        if ( o == null || getClass() != o.getClass() )
+        {
+            return false;
+        }
+
+        Classpath classpath = (Classpath) o;
+
+        return !( elements != null ? !elements.equals( classpath.elements ) : classpath.elements
!= null );
+
+    }
+
+    public int hashCode()
+    {
+        return elements != null ? elements.hashCode() : 0;
+    }
 }

Modified: maven/surefire/trunk/surefire-booter/src/main/java/org/apache/maven/surefire/booter/ClasspathConfiguration.java
URL: http://svn.apache.org/viewvc/maven/surefire/trunk/surefire-booter/src/main/java/org/apache/maven/surefire/booter/ClasspathConfiguration.java?rev=1076672&r1=1076671&r2=1076672&view=diff
==============================================================================
--- maven/surefire/trunk/surefire-booter/src/main/java/org/apache/maven/surefire/booter/ClasspathConfiguration.java
(original)
+++ maven/surefire/trunk/surefire-booter/src/main/java/org/apache/maven/surefire/booter/ClasspathConfiguration.java
Thu Mar  3 16:36:32 2011
@@ -27,7 +27,6 @@ import java.net.MalformedURLException;
 import java.net.URL;
 import java.util.Iterator;
 import java.util.List;
-import java.util.Properties;
 
 /**
  * Represents the classpaths for the BooterConfiguration.
@@ -40,6 +39,13 @@ import java.util.Properties;
  */
 public class ClasspathConfiguration
 {
+    private static final String CHILD_DELEGATION = "childDelegation";
+
+    private static final String ENABLE_ASSERTIONS = "enableAssertions";
+
+    private static final String CLASSPATH = "classPathUrl.";
+
+    private static final String SUREFIRE_CLASSPATH = "surefireClassPathUrl.";
 
     private final Classpath classpathUrls;
 
@@ -59,11 +65,15 @@ public class ClasspathConfiguration
         this( new Classpath(), new Classpath(), enableAssertions, childDelegation );
     }
 
-    /*
-    * Reads the config from the supplied stream. Closes the stream.
-    */
-    public ClasspathConfiguration( Classpath classPathUrls, Classpath surefireClassPathUrls,
boolean enableAssertions,
-                                   boolean childDelegation )
+    ClasspathConfiguration( PropertiesWrapper properties )
+    {
+        this( properties.getClasspath( CLASSPATH ),
+              properties.getClasspath( SUREFIRE_CLASSPATH ),
+              properties.getBooleanProperty( ENABLE_ASSERTIONS ), properties.getBooleanProperty(
CHILD_DELEGATION ) );
+    }
+
+    private ClasspathConfiguration( Classpath classPathUrls, Classpath surefireClassPathUrls,
boolean enableAssertions,
+                                    boolean childDelegation )
     {
         this.enableAssertions = enableAssertions;
         this.childDelegation = childDelegation;
@@ -71,12 +81,12 @@ public class ClasspathConfiguration
         this.surefireClasspathUrls = surefireClassPathUrls;
     }
 
-    public void setForkProperties( Properties properties )
+    public void setForkProperties( PropertiesWrapper properties )
     {
-        classpathUrls.writeToForkProperties( properties, BooterConstants.CLASSPATH_URL );
-        surefireClasspathUrls.writeToForkProperties( properties, BooterConstants.SUREFIRE_CLASSPATHURL
);
-        properties.setProperty( BooterConstants.ENABLE_ASSERTIONS, String.valueOf( enableAssertions
) );
-        properties.setProperty( BooterConstants.CHILD_DELEGATION, String.valueOf( childDelegation
) );
+        properties.setClasspath( CLASSPATH, classpathUrls );
+        properties.setClasspath( SUREFIRE_CLASSPATH, classpathUrls );
+        properties.setProperty( ENABLE_ASSERTIONS, String.valueOf( enableAssertions ) );
+        properties.setProperty( CHILD_DELEGATION, String.valueOf( childDelegation ) );
     }
 
     private static Method assertionStatusMethod;

Modified: maven/surefire/trunk/surefire-booter/src/main/java/org/apache/maven/surefire/booter/PropertiesWrapper.java
URL: http://svn.apache.org/viewvc/maven/surefire/trunk/surefire-booter/src/main/java/org/apache/maven/surefire/booter/PropertiesWrapper.java?rev=1076672&r1=1076671&r2=1076672&view=diff
==============================================================================
--- maven/surefire/trunk/surefire-booter/src/main/java/org/apache/maven/surefire/booter/PropertiesWrapper.java
(original)
+++ maven/surefire/trunk/surefire-booter/src/main/java/org/apache/maven/surefire/booter/PropertiesWrapper.java
Thu Mar  3 16:36:32 2011
@@ -234,6 +234,22 @@ public class PropertiesWrapper
         }
     }
 
+    Classpath getClasspath( String prefix  )
+    {
+        List elements = getStringList( prefix );
+        return new Classpath( elements );
+    }
+
+    public void setClasspath( String prefix, Classpath classpath )
+    {
+        List classpathElements = classpath.getClassPath();
+        for ( int i = 0; i < classpathElements.size(); ++i )
+        {
+            String element = (String) classpathElements.get( i );
+            setProperty( prefix + i, element );
+        }
+    }
+
     public void setProperty( String key, Integer integer )
     {
         if ( integer != null )

Modified: maven/surefire/trunk/surefire-booter/src/test/java/org/apache/maven/surefire/booter/ClasspathTest.java
URL: http://svn.apache.org/viewvc/maven/surefire/trunk/surefire-booter/src/test/java/org/apache/maven/surefire/booter/ClasspathTest.java?rev=1076672&r1=1076671&r2=1076672&view=diff
==============================================================================
--- maven/surefire/trunk/surefire-booter/src/test/java/org/apache/maven/surefire/booter/ClasspathTest.java
(original)
+++ maven/surefire/trunk/surefire-booter/src/test/java/org/apache/maven/surefire/booter/ClasspathTest.java
Thu Mar  3 16:36:32 2011
@@ -21,7 +21,6 @@ package org.apache.maven.surefire.booter
 
 import java.io.File;
 import java.util.List;
-import java.util.Properties;
 
 import junit.framework.TestCase;
 
@@ -73,17 +72,6 @@ public class ClasspathTest
         assertTrue( asUrlList.get( 1 ).toString().endsWith( DUMMY_URL_2 ) );
     }
 
-    public void testSetForkProperties()
-        throws Exception
-    {
-        Properties properties = new Properties();
-        createClasspathWithTwoElements().writeToForkProperties( properties, "test" );
-        assertEquals( DUMMY_URL_1, properties.get( "test0" ) );
-        assertEquals( DUMMY_URL_2, properties.get( "test1" ) );
-    }
-
-
-
     public void testShouldJoinTwoNullClasspaths()
     {
         Classpath joinedClasspath = Classpath.join( null, null );
@@ -111,21 +99,7 @@ public class ClasspathTest
         Classpath joinedClasspath = Classpath.join( firstClasspath, secondClasspath );
         assertClasspathConsistsOfElements( joinedClasspath, new String[] { DUMMY_URL_1 }
);
     }
-    
-    public void testShouldReadEmptyClasspathFromForkProperties() {
-        PropertiesWrapper properties = new PropertiesWrapper( new Properties() );
-        Classpath classpath = Classpath.readFromForkProperties( properties, "test" );
-        assertEmptyClasspath(classpath);
-    }
-    
-    public void testShouldReadClasspathWithToElementsFromForkProperties() {
-        PropertiesWrapper properties = new PropertiesWrapper( new Properties() );
-        properties.setProperty( "test0", DUMMY_URL_1 );
-        properties.setProperty( "test1", DUMMY_URL_2 );
-        Classpath classpath = Classpath.readFromForkProperties( properties, "test" );
-        assertClasspathConsistsOfElements( classpath, new String[] { DUMMY_URL_1, DUMMY_URL_2
} );
-    }
-    
+
     public void testShouldNotBeAbleToRemoveElement()
         throws Exception
     {

Modified: maven/surefire/trunk/surefire-booter/src/test/java/org/apache/maven/surefire/booter/PropertiesWrapperTest.java
URL: http://svn.apache.org/viewvc/maven/surefire/trunk/surefire-booter/src/test/java/org/apache/maven/surefire/booter/PropertiesWrapperTest.java?rev=1076672&r1=1076671&r2=1076672&view=diff
==============================================================================
--- maven/surefire/trunk/surefire-booter/src/test/java/org/apache/maven/surefire/booter/PropertiesWrapperTest.java
(original)
+++ maven/surefire/trunk/surefire-booter/src/test/java/org/apache/maven/surefire/booter/PropertiesWrapperTest.java
Thu Mar  3 16:36:32 2011
@@ -51,4 +51,61 @@ public class PropertiesWrapperTest
         assertEquals( "String2", test.get( 1 ) );
 
     }
+
+    private static final String DUMMY_PREFIX = "dummyPrefix";
+
+    private static final String FIRST_ELEMENT = "foo0";
+
+    private static final String SECOND_ELEMENT = "foo1";
+
+    private final Properties properties = new Properties();
+
+
+    private final PropertiesWrapper mapper = new PropertiesWrapper( properties );
+    private final Classpath classpathWithTwoElements = createClasspathWithTwoElements();
+
+    public void testReadFromProperties()
+        throws Exception
+    {
+        properties.put( DUMMY_PREFIX + "0", FIRST_ELEMENT );
+        properties.put( DUMMY_PREFIX + "1", SECOND_ELEMENT );
+        Classpath recreatedClasspath = readClasspathFromProperties();
+        assertEquals( classpathWithTwoElements, recreatedClasspath );
+    }
+
+    public void testReadFromPropertiesWithEmptyProperties()
+        throws Exception
+    {
+        Classpath recreatedClasspath = readClasspathFromProperties();
+        assertTrue( recreatedClasspath.getClassPath().isEmpty() );
+    }
+
+    public void testWriteToProperties()
+        throws Exception
+    {
+        mapper.setClasspath( DUMMY_PREFIX,  classpathWithTwoElements);
+        assertEquals( FIRST_ELEMENT, mapper.getProperty( DUMMY_PREFIX + "0" ) );
+        assertEquals( SECOND_ELEMENT, mapper.getProperty( DUMMY_PREFIX + "1" ) );
+    }
+
+    public void testRoundtrip()
+        throws Exception
+    {
+        mapper.setClasspath( DUMMY_PREFIX,  classpathWithTwoElements);
+        Classpath recreatedClasspath = readClasspathFromProperties();
+        assertEquals( classpathWithTwoElements, recreatedClasspath );
+    }
+
+    private Classpath createClasspathWithTwoElements()
+    {
+        Classpath classpath = new Classpath();
+        classpath.addClassPathElementUrl( FIRST_ELEMENT );
+        classpath.addClassPathElementUrl( SECOND_ELEMENT );
+        return classpath;
+    }
+
+    private Classpath readClasspathFromProperties()
+    {
+        return mapper.getClasspath( DUMMY_PREFIX);
+    }
 }



Mime
View raw message