Author: stephenc
Date: Wed May 25 08:59:58 2011
New Revision: 1127440

URL: http://svn.apache.org/viewvc?rev=1127440&view=rev
Log:
full tck for PropertyUtils

Modified:
    
maven/sandbox/trunk/plexus-utils-commons-bridge/plexus-utils-tck/src/test/java/org/codehaus/plexus/util/PropertyUtilsTest.java

Modified: 
maven/sandbox/trunk/plexus-utils-commons-bridge/plexus-utils-tck/src/test/java/org/codehaus/plexus/util/PropertyUtilsTest.java
URL: 
http://svn.apache.org/viewvc/maven/sandbox/trunk/plexus-utils-commons-bridge/plexus-utils-tck/src/test/java/org/codehaus/plexus/util/PropertyUtilsTest.java?rev=1127440&r1=1127439&r2=1127440&view=diff
==============================================================================
--- 
maven/sandbox/trunk/plexus-utils-commons-bridge/plexus-utils-tck/src/test/java/org/codehaus/plexus/util/PropertyUtilsTest.java
 (original)
+++ 
maven/sandbox/trunk/plexus-utils-commons-bridge/plexus-utils-tck/src/test/java/org/codehaus/plexus/util/PropertyUtilsTest.java
 Wed May 25 08:59:58 2011
@@ -19,16 +19,50 @@ package org.codehaus.plexus.util;
  * under the License.
  */
 
+import org.junit.Rule;
 import org.junit.Test;
+import org.junit.rules.MethodRule;
+import org.junit.rules.TemporaryFolder;
+import org.junit.runners.model.FrameworkMethod;
+import org.junit.runners.model.Statement;
+
+import java.io.ByteArrayInputStream;
+import java.io.File;
+import java.io.FileOutputStream;
+import java.io.InputStream;
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+import java.net.URL;
+import java.util.Properties;
 
 import static org.apache.maven.tck.TckMatchers.hasDefaultConstructor;
 import static org.apache.maven.tck.TckMatchers.isFinalClass;
-import static org.hamcrest.CoreMatchers.allOf;
-import static org.hamcrest.CoreMatchers.not;
+import static org.hamcrest.CoreMatchers.*;
 import static org.junit.Assert.assertThat;
 
 public class PropertyUtilsTest
 {
+    @Retention( RetentionPolicy.RUNTIME )
+    @Target( ElementType.METHOD )
+    @interface NeedsTemporaryFolder
+    {
+    }
+
+    @Rule
+    public MethodRule folderProvider = new MethodRule()
+    {
+        // keep the tests fast and only interface with the filesystem if needed
+        public Statement apply( Statement base, FrameworkMethod method, Object 
target )
+        {
+            if (method.getAnnotation( NeedsTemporaryFolder.class ) == null) 
return base;
+            folder = new TemporaryFolder();
+            return folder.apply( base, method, target );
+        }
+    };
+
+    public TemporaryFolder folder;
 
     @Test
     public void isNotUtilityClass()
@@ -37,4 +71,83 @@ public class PropertyUtilsTest
         assertThat( PropertyUtils.class, allOf( hasDefaultConstructor(), not( 
isFinalClass() ) ) );
     }
 
+    @Test
+    public void loadNullInputStream()
+        throws Exception
+    {
+        assertThat( PropertyUtils.loadProperties( (InputStream) null ), is( 
new Properties() ) );
+    }
+
+    @Test
+    public void loadNullURL()
+        throws Exception
+    {
+        assertThat( PropertyUtils.loadProperties( (URL) null ), nullValue( 
Properties.class ) );
+    }
+
+    @Test
+    public void loadNullFile()
+        throws Exception
+    {
+        assertThat( PropertyUtils.loadProperties( (File) null ), nullValue( 
Properties.class ) );
+    }
+
+    @Test
+    public void loadEmptyInputStream()
+        throws Exception
+    {
+        assertThat( PropertyUtils.loadProperties( new ByteArrayInputStream( 
new byte[0] )), is( new Properties() ) );
+    }
+
+    @Test
+    @NeedsTemporaryFolder
+    public void loadEmptyFile()
+        throws Exception
+    {
+        assertThat( PropertyUtils.loadProperties( folder.newFile( "empty" )), 
is( new Properties() ) );
+    }
+
+    @Test
+    @NeedsTemporaryFolder
+    public void loadEmptyURL()
+        throws Exception
+    {
+        assertThat( PropertyUtils.loadProperties( folder.newFile( "empty" 
).toURI().toURL() ), is( new Properties() ) );
+    }
+
+    @Test
+    public void loadValidInputStream()
+        throws Exception
+    {
+        Properties value = new Properties();
+        value.setProperty( "a", "b" );
+        assertThat( PropertyUtils.loadProperties( new ByteArrayInputStream( 
"a=b".getBytes( "ISO-8859-1" ) ) ),
+                    is( value ) );
+    }
+
+    @Test
+    @NeedsTemporaryFolder
+    public void loadValidFile()
+        throws Exception
+    {
+        File valid = folder.newFile( "valid" );
+        Properties value = new Properties();
+        value.setProperty( "a", "b" );
+        value.store( new FileOutputStream( valid ), "a test" );
+        assertThat( PropertyUtils.loadProperties( valid ), is( value ) );
+    }
+
+    @Test
+    @NeedsTemporaryFolder
+    public void loadValidURL()
+        throws Exception
+    {
+        File valid = folder.newFile( "valid" );
+        Properties value = new Properties();
+        value.setProperty( "a", "b" );
+        value.store( new FileOutputStream( valid ), "a test" );
+        assertThat( PropertyUtils.loadProperties( valid.toURI().toURL() ), is( 
value ) );
+    }
+
+
 }


Reply via email to