You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by st...@apache.org on 2011/06/01 10:31:58 UTC

svn commit: r1130045 - in /maven/sandbox/trunk/plexus-utils-commons-bridge: plexus-utils-commons-bridge/src/main/java/org/codehaus/plexus/util/ plexus-utils-tck/src/test/java/org/apache/maven/tck/ plexus-utils-tck/src/test/java/org/codehaus/plexus/util/

Author: stephenc
Date: Wed Jun  1 08:31:57 2011
New Revision: 1130045

URL: http://svn.apache.org/viewvc?rev=1130045&view=rev
Log:
IOUtil.toByteArray(InputStream,int)
Added a matcher to help with testing infinite loops
Refactored existing infinite loop tests to use new matcher

Added:
    maven/sandbox/trunk/plexus-utils-commons-bridge/plexus-utils-tck/src/test/java/org/apache/maven/tck/Task.java
Modified:
    maven/sandbox/trunk/plexus-utils-commons-bridge/plexus-utils-commons-bridge/src/main/java/org/codehaus/plexus/util/IOUtil.java
    maven/sandbox/trunk/plexus-utils-commons-bridge/plexus-utils-tck/src/test/java/org/apache/maven/tck/TckMatchers.java
    maven/sandbox/trunk/plexus-utils-commons-bridge/plexus-utils-tck/src/test/java/org/codehaus/plexus/util/IOUtilTest.java

Modified: maven/sandbox/trunk/plexus-utils-commons-bridge/plexus-utils-commons-bridge/src/main/java/org/codehaus/plexus/util/IOUtil.java
URL: http://svn.apache.org/viewvc/maven/sandbox/trunk/plexus-utils-commons-bridge/plexus-utils-commons-bridge/src/main/java/org/codehaus/plexus/util/IOUtil.java?rev=1130045&r1=1130044&r2=1130045&view=diff
==============================================================================
--- maven/sandbox/trunk/plexus-utils-commons-bridge/plexus-utils-commons-bridge/src/main/java/org/codehaus/plexus/util/IOUtil.java (original)
+++ maven/sandbox/trunk/plexus-utils-commons-bridge/plexus-utils-commons-bridge/src/main/java/org/codehaus/plexus/util/IOUtil.java Wed Jun  1 08:31:57 2011
@@ -187,7 +187,8 @@ public final class IOUtil
     public static byte[] toByteArray( java.io.InputStream input, int bufferSize )
         throws java.io.IOException
     {
-        throw new UnsupportedOperationException( "Not implemented yet" );
+        fakeBufferSizeHandler( bufferSize );
+        return IOUtils.toByteArray( input );
     }
 
     public static void copy( java.io.Reader input, java.io.OutputStream output )

Added: maven/sandbox/trunk/plexus-utils-commons-bridge/plexus-utils-tck/src/test/java/org/apache/maven/tck/Task.java
URL: http://svn.apache.org/viewvc/maven/sandbox/trunk/plexus-utils-commons-bridge/plexus-utils-tck/src/test/java/org/apache/maven/tck/Task.java?rev=1130045&view=auto
==============================================================================
--- maven/sandbox/trunk/plexus-utils-commons-bridge/plexus-utils-tck/src/test/java/org/apache/maven/tck/Task.java (added)
+++ maven/sandbox/trunk/plexus-utils-commons-bridge/plexus-utils-tck/src/test/java/org/apache/maven/tck/Task.java Wed Jun  1 08:31:57 2011
@@ -0,0 +1,6 @@
+package org.apache.maven.tck;
+
+public interface Task
+{
+    void task() throws Exception;
+}

Modified: maven/sandbox/trunk/plexus-utils-commons-bridge/plexus-utils-tck/src/test/java/org/apache/maven/tck/TckMatchers.java
URL: http://svn.apache.org/viewvc/maven/sandbox/trunk/plexus-utils-commons-bridge/plexus-utils-tck/src/test/java/org/apache/maven/tck/TckMatchers.java?rev=1130045&r1=1130044&r2=1130045&view=diff
==============================================================================
--- maven/sandbox/trunk/plexus-utils-commons-bridge/plexus-utils-tck/src/test/java/org/apache/maven/tck/TckMatchers.java (original)
+++ maven/sandbox/trunk/plexus-utils-commons-bridge/plexus-utils-tck/src/test/java/org/apache/maven/tck/TckMatchers.java Wed Jun  1 08:31:57 2011
@@ -25,6 +25,7 @@ import org.hamcrest.Matcher;
 
 import java.lang.reflect.Constructor;
 import java.lang.reflect.Modifier;
+import java.util.concurrent.atomic.AtomicBoolean;
 
 import static org.hamcrest.CoreMatchers.allOf;
 
@@ -73,6 +74,18 @@ public class TckMatchers
         return new HasDefaultConstructor();
     }
 
+    /**
+     * A matcher which checks that a {@link Task} will take longer than the supplied number of ms to complete.
+     *
+     * @param ms the duration to complete within.
+     * @return A matcher which checks that a {@link Task} will take longer than the supplied number of ms to
+     *         complete.
+     */
+    public static Matcher<Task> runsForLongerThan( long ms )
+    {
+        return new RunsForLongerThan( ms );
+    }
+
     private static class HasDefaultConstructor
         extends BaseMatcher<Class<?>>
     {
@@ -132,4 +145,57 @@ public class TckMatchers
             description.appendText( "a final class" );
         }
     }
+
+    private static class RunsForLongerThan
+        extends BaseMatcher<Task>
+    {
+
+        private final long duration;
+
+        public RunsForLongerThan( long duration )
+        {
+            this.duration = duration;
+        }
+
+        public boolean matches( Object item )
+        {
+            final Task task = Task.class.cast( item );
+            final AtomicBoolean didNotFinish = new AtomicBoolean( true );
+            final Thread worker = new Thread()
+            {
+                @Override
+                public void run()
+                {
+                    try
+                    {
+                        task.task();
+                        didNotFinish.set( false );
+                    }
+                    catch ( Exception t )
+                    {
+                        // ignore
+                    }
+                }
+            };
+            try
+            {
+                worker.start();
+                worker.join( 100 );
+            }
+            catch ( InterruptedException e )
+            {
+                // ignore
+            }
+            finally
+            {
+                worker.interrupt();
+            }
+            return didNotFinish.get();
+        }
+
+        public void describeTo( Description description )
+        {
+            description.appendText( "takes longer than " ).appendValue( duration ).appendText( "ms to complete" );
+        }
+    }
 }

Modified: maven/sandbox/trunk/plexus-utils-commons-bridge/plexus-utils-tck/src/test/java/org/codehaus/plexus/util/IOUtilTest.java
URL: http://svn.apache.org/viewvc/maven/sandbox/trunk/plexus-utils-commons-bridge/plexus-utils-tck/src/test/java/org/codehaus/plexus/util/IOUtilTest.java?rev=1130045&r1=1130044&r2=1130045&view=diff
==============================================================================
--- maven/sandbox/trunk/plexus-utils-commons-bridge/plexus-utils-tck/src/test/java/org/codehaus/plexus/util/IOUtilTest.java (original)
+++ maven/sandbox/trunk/plexus-utils-commons-bridge/plexus-utils-tck/src/test/java/org/codehaus/plexus/util/IOUtilTest.java Wed Jun  1 08:31:57 2011
@@ -20,6 +20,7 @@ package org.codehaus.plexus.util;
  */
 
 import org.apache.maven.tck.ReproducesPlexusBug;
+import org.apache.maven.tck.Task;
 import org.junit.Test;
 
 import java.io.BufferedInputStream;
@@ -39,6 +40,7 @@ import java.io.Writer;
 import java.util.concurrent.atomic.AtomicBoolean;
 
 import static org.apache.maven.tck.TckMatchers.isUtilityClass;
+import static org.apache.maven.tck.TckMatchers.runsForLongerThan;
 import static org.hamcrest.CoreMatchers.is;
 import static org.junit.Assert.assertThat;
 
@@ -398,27 +400,14 @@ public class IOUtilTest
     public void toStringEmptyByteArrayZeroBufSz()
         throws Exception
     {
-        final AtomicBoolean finished = new AtomicBoolean( false );
-        Thread worker = new Thread()
-        {
-            @Override
-            public void run()
-            {
-                try
-                {
-                    IOUtil.toString( emptyByteArray(), 0 );
-                }
-                catch ( IOException e )
-                {
-                    // ignore
-                }
-                finished.set( true );
-            }
-        };
-        worker.start();
-        worker.join( 100 );
-        worker.interrupt();
-        assertThat( "We have an infinite loop", finished.get(), is( false ) );
+        assertThat( "We have an infinite loop", new Task()
+                    {
+                        public void task()
+                            throws Exception
+                        {
+                            IOUtil.toString( emptyByteArray(), 0 );
+                        }
+                    }, runsForLongerThan( 100 ) );
     }
 
     @Test( timeout = 150 )
@@ -426,28 +415,15 @@ public class IOUtilTest
     public void toStringByteArrayZeroBufSz()
         throws Exception
     {
-        final AtomicBoolean finished = new AtomicBoolean( false );
-        Thread worker = new Thread()
-        {
-            @Override
-            public void run()
-            {
-                try
-                {
-                    String probe = "A string \u2345\u00ef";
-                    IOUtil.toString( probe.getBytes(), 0 );
-                }
-                catch ( IOException e )
-                {
-                    // ignore
-                }
-                finished.set( true );
-            }
-        };
-        worker.start();
-        worker.join( 100 );
-        worker.interrupt();
-        assertThat( "We have an infinite loop", finished.get(), is( false ) );
+        assertThat( "We have an infinite loop", new Task()
+                    {
+                        public void task()
+                            throws Exception
+                        {
+                            String probe = "A string \u2345\u00ef";
+                            IOUtil.toString( probe.getBytes(), 0 );
+                        }
+                    }, runsForLongerThan( 100 ) );
     }
 
     @Test( expected = NullPointerException.class )
@@ -662,27 +638,14 @@ public class IOUtilTest
     public void toStringEmptyByteArrayValidEncodingZeroBufSz()
         throws Exception
     {
-        final AtomicBoolean finished = new AtomicBoolean( false );
-        Thread worker = new Thread()
-        {
-            @Override
-            public void run()
-            {
-                try
-                {
-                    IOUtil.toString( emptyByteArray(), "utf-16", 0 );
-                }
-                catch ( IOException e )
-                {
-                    // ignore
-                }
-                finished.set( true );
-            }
-        };
-        worker.start();
-        worker.join( 100 );
-        worker.interrupt();
-        assertThat( "We have an infinite loop", finished.get(), is( false ) );
+        assertThat( "We have an infinite loop", new Task()
+                    {
+                        public void task()
+                            throws Exception
+                        {
+                            IOUtil.toString( emptyByteArray(), "utf-16", 0 );
+                        }
+                    }, runsForLongerThan( 100 ) );
     }
 
     @Test( timeout = 150 )
@@ -690,28 +653,15 @@ public class IOUtilTest
     public void toStringByteArrayValidEncodingZeroBufSz()
         throws Exception
     {
-        final AtomicBoolean finished = new AtomicBoolean( false );
-        Thread worker = new Thread()
-        {
-            @Override
-            public void run()
-            {
-                try
-                {
-                    String probe = "A string \u2345\u00ef";
-                    IOUtil.toString( probe.getBytes(), "utf-16", 0 );
-                }
-                catch ( IOException e )
-                {
-                    // ignore
-                }
-                finished.set( true );
-            }
-        };
-        worker.start();
-        worker.join( 100 );
-        worker.interrupt();
-        assertThat( "We have an infinite loop", finished.get(), is( false ) );
+        assertThat( "We have an infinite loop", new Task()
+                    {
+                        public void task()
+                            throws Exception
+                        {
+                            String probe = "A string \u2345\u00ef";
+                            IOUtil.toString( probe.getBytes(), "utf-16", 0 );
+                        }
+                    }, runsForLongerThan( 100 ) );
     }
 
     @Test( expected = NullPointerException.class )
@@ -975,29 +925,16 @@ public class IOUtilTest
     public void copyInputStreamValidOutputStreamZeroBufSz()
         throws Exception
     {
-        final AtomicBoolean finished = new AtomicBoolean( false );
-        Thread worker = new Thread()
-        {
-            @Override
-            public void run()
-            {
-                try
-                {
-                    ByteArrayOutputStream outputStream = new DontCloseByteArrayOutputStream();
-                    byte[] input = { 1, 2, 3, 4, 5, 6 };
-                    IOUtil.copy( new DontCloseByteArrayInputStream( input ), outputStream, 0 );
-                }
-                catch ( IOException e )
-                {
-                    // ignore
-                }
-                finished.set( true );
-            }
-        };
-        worker.start();
-        worker.join( 100 );
-        worker.interrupt();
-        assertThat( "We have an infinite loop", finished.get(), is( false ) );
+        assertThat( "We have an infinite loop", new Task()
+                    {
+                        public void task()
+                            throws Exception
+                        {
+                            ByteArrayOutputStream outputStream = new DontCloseByteArrayOutputStream();
+                            byte[] input = { 1, 2, 3, 4, 5, 6 };
+                            IOUtil.copy( new DontCloseByteArrayInputStream( input ), outputStream, 0 );
+                        }
+                    }, runsForLongerThan( 100 ) );
     }
 
     @Test( expected = NullPointerException.class, timeout = 150 )
@@ -1095,27 +1032,14 @@ public class IOUtilTest
     public void toStringEmptyInputStreamZeroBufSz()
         throws Exception
     {
-        final AtomicBoolean finished = new AtomicBoolean( false );
-        Thread worker = new Thread()
-        {
-            @Override
-            public void run()
-            {
-                try
-                {
-                    IOUtil.toString( emptyInputStream(), 0 );
-                }
-                catch ( IOException e )
-                {
-                    // ignore
-                }
-                finished.set( true );
-            }
-        };
-        worker.start();
-        worker.join( 100 );
-        worker.interrupt();
-        assertThat( "We have an infinite loop", finished.get(), is( false ) );
+        assertThat( "We have an infinite loop", new Task()
+                    {
+                        public void task()
+                            throws Exception
+                        {
+                            IOUtil.toString( emptyInputStream(), 0 );
+                        }
+                    }, runsForLongerThan( 100 ) );
     }
 
     @Test( timeout = 150 )
@@ -1123,28 +1047,15 @@ public class IOUtilTest
     public void toStringInputStreamZeroBufSz()
         throws Exception
     {
-        final AtomicBoolean finished = new AtomicBoolean( false );
-        Thread worker = new Thread()
-        {
-            @Override
-            public void run()
-            {
-                try
-                {
-                    String probe = "A string \u2345\u00ef";
-                    IOUtil.toString( new ByteArrayInputStream( probe.getBytes() ), 0 );
-                }
-                catch ( IOException e )
-                {
-                    // ignore
-                }
-                finished.set( true );
-            }
-        };
-        worker.start();
-        worker.join( 100 );
-        worker.interrupt();
-        assertThat( "We have an infinite loop", finished.get(), is( false ) );
+        assertThat( "We have an infinite loop", new Task()
+                    {
+                        public void task()
+                            throws Exception
+                        {
+                            String probe = "A string \u2345\u00ef";
+                            IOUtil.toString( new ByteArrayInputStream( probe.getBytes() ), 0 );
+                        }
+                    }, runsForLongerThan( 100 ) );
     }
 
     @Test( expected = NullPointerException.class )
@@ -1368,27 +1279,14 @@ public class IOUtilTest
     public void toStringEmptyInputStreamValidEncodingZeroBufSz()
         throws Exception
     {
-        final AtomicBoolean finished = new AtomicBoolean( false );
-        Thread worker = new Thread()
-        {
-            @Override
-            public void run()
-            {
-                try
-                {
-                    IOUtil.toString( emptyInputStream(), "utf-16", 0 );
-                }
-                catch ( IOException e )
-                {
-                    // ignore
-                }
-                finished.set( true );
-            }
-        };
-        worker.start();
-        worker.join( 100 );
-        worker.interrupt();
-        assertThat( "We have an infinite loop", finished.get(), is( false ) );
+        assertThat( "We have an infinite loop", new Task()
+                    {
+                        public void task()
+                            throws Exception
+                        {
+                            IOUtil.toString( emptyInputStream(), "utf-16", 0 );
+                        }
+                    }, runsForLongerThan( 100 ) );
     }
 
     @Test( timeout = 150 )
@@ -1396,28 +1294,15 @@ public class IOUtilTest
     public void toStringInputStreamValidEncodingZeroBufSz()
         throws Exception
     {
-        final AtomicBoolean finished = new AtomicBoolean( false );
-        Thread worker = new Thread()
-        {
-            @Override
-            public void run()
-            {
-                try
-                {
-                    String probe = "A string \u2345\u00ef";
-                    IOUtil.toString( new ByteArrayInputStream( probe.getBytes() ), "utf-16", 0 );
-                }
-                catch ( IOException e )
-                {
-                    // ignore
-                }
-                finished.set( true );
-            }
-        };
-        worker.start();
-        worker.join( 100 );
-        worker.interrupt();
-        assertThat( "We have an infinite loop", finished.get(), is( false ) );
+        assertThat( "We have an infinite loop", new Task()
+                    {
+                        public void task()
+                            throws Exception
+                        {
+                            String probe = "A string \u2345\u00ef";
+                            IOUtil.toString( new ByteArrayInputStream( probe.getBytes() ), "utf-16", 0 );
+                        }
+                    }, runsForLongerThan( 100 ) );
     }
 
     @Test( expected = IOException.class )
@@ -1565,27 +1450,14 @@ public class IOUtilTest
     public void copyEmptyInputStreamValidWriterZeroBufSz()
         throws Exception
     {
-        final AtomicBoolean finished = new AtomicBoolean( false );
-        Thread worker = new Thread()
-        {
-            @Override
-            public void run()
-            {
-                try
-                {
-                    IOUtil.copy( emptyInputStream(), new DontCloseStringWriter(), 0 );
-                }
-                catch ( IOException e )
-                {
-                    // ignore
-                }
-                finished.set( true );
-            }
-        };
-        worker.start();
-        worker.join( 100 );
-        worker.interrupt();
-        assertThat( "We have an infinite loop", finished.get(), is( false ) );
+        assertThat( "We have an infinite loop", new Task()
+                    {
+                        public void task()
+                            throws Exception
+                        {
+                            IOUtil.copy( emptyInputStream(), new DontCloseStringWriter(), 0 );
+                        }
+                    }, runsForLongerThan( 100 ) );
     }
 
     @Test( timeout = 150 )
@@ -1593,29 +1465,16 @@ public class IOUtilTest
     public void copyInputStreamZeroBufSz()
         throws Exception
     {
-        final AtomicBoolean finished = new AtomicBoolean( false );
-        Thread worker = new Thread()
-        {
-            @Override
-            public void run()
-            {
-                try
-                {
-                    String probe = "A string \u2345\u00ef";
-                    StringWriter writer = new DontCloseStringWriter();
-                    IOUtil.copy( new ByteArrayInputStream( probe.getBytes() ), writer, 0 );
-                }
-                catch ( IOException e )
-                {
-                    // ignore
-                }
-                finished.set( true );
-            }
-        };
-        worker.start();
-        worker.join( 100 );
-        worker.interrupt();
-        assertThat( "We have an infinite loop", finished.get(), is( false ) );
+        assertThat( "We have an infinite loop", new Task()
+                    {
+                        public void task()
+                            throws Exception
+                        {
+                            String probe = "A string \u2345\u00ef";
+                            StringWriter writer = new DontCloseStringWriter();
+                            IOUtil.copy( new ByteArrayInputStream( probe.getBytes() ), writer, 0 );
+                        }
+                    }, runsForLongerThan( 100 ) );
     }
 
     @Test( expected = NullPointerException.class )
@@ -2049,27 +1908,14 @@ public class IOUtilTest
     public void copyEmptyInputStreamValidEncodingZeroBufSz()
         throws Exception
     {
-        final AtomicBoolean finished = new AtomicBoolean( false );
-        Thread worker = new Thread()
-        {
-            @Override
-            public void run()
-            {
-                try
-                {
-                    IOUtil.copy( emptyInputStream(), new DontCloseStringWriter(), "utf-16", 0 );
-                }
-                catch ( IOException e )
-                {
-                    // ignore
-                }
-                finished.set( true );
-            }
-        };
-        worker.start();
-        worker.join( 100 );
-        worker.interrupt();
-        assertThat( "We have an infinite loop", finished.get(), is( false ) );
+        assertThat( "We have an infinite loop", new Task()
+                    {
+                        public void task()
+                            throws Exception
+                        {
+                            IOUtil.copy( emptyInputStream(), new DontCloseStringWriter(), "utf-16", 0 );
+                        }
+                    }, runsForLongerThan( 100 ) );
     }
 
     @Test( timeout = 150 )
@@ -2077,29 +1923,16 @@ public class IOUtilTest
     public void copyInputStreamValidEncodingZeroBufSz()
         throws Exception
     {
-        final AtomicBoolean finished = new AtomicBoolean( false );
-        Thread worker = new Thread()
-        {
-            @Override
-            public void run()
-            {
-                try
-                {
-                    String probe = "A string \u2345\u00ef";
-                    IOUtil.copy( new ByteArrayInputStream( probe.getBytes() ), new DontCloseStringWriter(), "utf-16",
-                                 0 );
-                }
-                catch ( IOException e )
-                {
-                    // ignore
-                }
-                finished.set( true );
-            }
-        };
-        worker.start();
-        worker.join( 100 );
-        worker.interrupt();
-        assertThat( "We have an infinite loop", finished.get(), is( false ) );
+        assertThat( "We have an infinite loop", new Task()
+                    {
+                        public void task()
+                            throws Exception
+                        {
+                            String probe = "A string \u2345\u00ef";
+                            IOUtil.copy( new ByteArrayInputStream( probe.getBytes() ), new DontCloseStringWriter(), "utf-16",
+                                         0 );
+                        }
+                    }, runsForLongerThan( 100 ) );
     }
 
     @Test( expected = NullPointerException.class )
@@ -2272,29 +2105,16 @@ public class IOUtilTest
     public void copyEmptyStringValidOutputStreamZeroBufSz()
         throws Exception
     {
-        final AtomicBoolean finished = new AtomicBoolean( false );
-        Thread worker = new Thread()
-        {
-            @Override
-            public void run()
-            {
-                try
-                {
-                    ByteArrayOutputStream OutputStream = new DontCloseByteArrayOutputStream();
-                    IOUtil.copy( emptyString(), OutputStream, 0 );
-                    assertThat( OutputStream.toByteArray(), is( emptyString().getBytes() ) );
-                }
-                catch ( IOException e )
-                {
-                    // ignore
-                }
-                finished.set( true );
-            }
-        };
-        worker.start();
-        worker.join( 100 );
-        worker.interrupt();
-        assertThat( "We have an infinite loop", finished.get(), is( false ) );
+        assertThat( "We have an infinite loop", new Task()
+                    {
+                        public void task()
+                            throws Exception
+                        {
+                            ByteArrayOutputStream OutputStream = new DontCloseByteArrayOutputStream();
+                            IOUtil.copy( emptyString(), OutputStream, 0 );
+                            assertThat( OutputStream.toByteArray(), is( emptyString().getBytes() ) );
+                        }
+                    }, runsForLongerThan( 100 ) );
     }
 
     @Test( expected = NullPointerException.class, timeout = 150 )
@@ -2310,30 +2130,17 @@ public class IOUtilTest
     public void copyStringValidOutputStreamZeroBufSz()
         throws Exception
     {
-        final AtomicBoolean finished = new AtomicBoolean( false );
-        Thread worker = new Thread()
-        {
-            @Override
-            public void run()
-            {
-                try
-                {
-                    String probe = "A string \u2345\u00ef";
-                    ByteArrayOutputStream OutputStream = new DontCloseByteArrayOutputStream();
-                    IOUtil.copy( probe, OutputStream, 0 );
-                    assertThat( OutputStream.toByteArray(), is( probe.getBytes() ) );
-                }
-                catch ( IOException e )
-                {
-                    // ignore
-                }
-                finished.set( true );
-            }
-        };
-        worker.start();
-        worker.join( 100 );
-        worker.interrupt();
-        assertThat( "We have an infinite loop", finished.get(), is( false ) );
+        assertThat( "We have an infinite loop", new Task()
+                    {
+                        public void task()
+                            throws Exception
+                        {
+                            String probe = "A string \u2345\u00ef";
+                            ByteArrayOutputStream OutputStream = new DontCloseByteArrayOutputStream();
+                            IOUtil.copy( probe, OutputStream, 0 );
+                            assertThat( OutputStream.toByteArray(), is( probe.getBytes() ) );
+                        }
+                    }, runsForLongerThan( 100 ) );
     }
 
     @Test( expected = NullPointerException.class )
@@ -2474,7 +2281,7 @@ public class IOUtilTest
         IOUtil.copy( new StringReader( probe ), nullWriter(), -1 );
     }
 
-    @Test(expected = NegativeArraySizeException.class )
+    @Test( expected = NegativeArraySizeException.class )
     public void copyReaderValidWriterNegBufSz()
         throws Exception
     {
@@ -2484,7 +2291,7 @@ public class IOUtilTest
         assertThat( writer.toString(), is( probe ) );
     }
 
-    @Test( expected = NullPointerException.class, timeout = 150)
+    @Test( expected = NullPointerException.class, timeout = 150 )
     public void copyNullReaderNullWriterZeroBufSz()
         throws Exception
     {
@@ -2505,32 +2312,20 @@ public class IOUtilTest
         IOUtil.copy( nullReader(), new DontCloseStringWriter(), 0 );
     }
 
-    @Test(timeout = 150) // TODO
+    @Test( timeout = 150 )
+    @ReproducesPlexusBug( "Should not infinite loop" )
     public void copyEmptyReaderValidWriterZeroBufSz()
         throws Exception
     {
-        final AtomicBoolean finished = new AtomicBoolean( false );
-        Thread worker = new Thread()
-        {
-            @Override
-            public void run()
-            {
-                try
-                {
-                    StringWriter writer = new DontCloseStringWriter();
-                    IOUtil.copy( emptyReader(), writer, 0 );
-                }
-                catch ( IOException e )
-                {
-                    // ignore
-                }
-                finished.set( true );
-            }
-        };
-        worker.start();
-        worker.join( 100 );
-        worker.interrupt();
-        assertThat( "We have an infinite loop", finished.get(), is( false ) );
+        assertThat( "We have an infinite loop", new Task()
+                    {
+                        public void task()
+                            throws Exception
+                        {
+                            StringWriter writer = new DontCloseStringWriter();
+                            IOUtil.copy( emptyReader(), writer, 0 );
+                        }
+                    }, runsForLongerThan( 100 ) );
     }
 
     @Test( expected = NullPointerException.class, timeout = 150 )
@@ -2541,33 +2336,21 @@ public class IOUtilTest
         IOUtil.copy( new StringReader( probe ), nullWriter(), 0 );
     }
 
-    @Test(timeout = 150)  // TODO
+    @Test( timeout = 150 )
+    @ReproducesPlexusBug( "Should not infinite loop" )
     public void copyReaderValidWriterZeroBufSz()
         throws Exception
     {
-        final AtomicBoolean finished = new AtomicBoolean( false );
-        Thread worker = new Thread()
-        {
-            @Override
-            public void run()
-            {
-                try
-                {
-                    String probe = "A string \u2345\u00ef";
-                    StringWriter writer = new DontCloseStringWriter();
-                    IOUtil.copy( new StringReader( probe ), writer, 0 );
-                }
-                catch ( IOException e )
-                {
-                    // ignore
-                }
-                finished.set( true );
-            }
-        };
-        worker.start();
-        worker.join( 100 );
-        worker.interrupt();
-        assertThat( "We have an infinite loop", finished.get(), is( false ) );
+        assertThat( "We have an infinite loop", new Task()
+                    {
+                        public void task()
+                            throws Exception
+                        {
+                            String probe = "A string \u2345\u00ef";
+                            StringWriter writer = new DontCloseStringWriter();
+                            IOUtil.copy( new StringReader( probe ), writer, 0 );
+                        }
+                    }, runsForLongerThan( 100 ) );
     }
 
     @Test( expected = NullPointerException.class )
@@ -2618,6 +2401,74 @@ public class IOUtilTest
         assertThat( writer.toString(), is( probe ) );
     }
 
+    /*
+     * toByteArray(InputStream,int)
+     */
+
+    @Test( expected = NegativeArraySizeException.class )
+    public void toByteArrayFromInputStreamNegBufSz()
+        throws Exception
+    {
+        String probe = "A string \u2345\u00ef";
+        assertThat( IOUtil.toByteArray( new DontCloseByteArrayInputStream( IOUtil.toByteArray( probe ) ), -1 ),
+                    is( probe.getBytes() ) );
+    }
+
+    @Test( expected = NegativeArraySizeException.class )
+    public void toByteArrayNullInputStreamNegBufSz()
+        throws Exception
+    {
+        IOUtil.toByteArray( nullInputStream(), -1 );
+    }
+
+    @Test(timeout = 150)
+    @ReproducesPlexusBug( "Should not infinite loop" )
+    public void toByteArrayFromInputStreamZeroBufSz()
+        throws Exception
+    {
+        assertThat( "We have an infinite loop", new Task()
+                    {
+                        public void task()
+                            throws Exception
+                        {
+                            String probe = "A string \u2345\u00ef";
+                            IOUtil.toByteArray( new DontCloseByteArrayInputStream( IOUtil.toByteArray( probe ) ), 0 );
+                        }
+                    }, runsForLongerThan( 100 ) );
+
+    }
+
+    @Test( timeout = 150)
+    @ReproducesPlexusBug( "Should not infinite loop" )
+    public void toByteArrayNullInputStreamZeroBufSz()
+        throws Exception
+    {
+        assertThat( "We have an infinite loop", new Task()
+                    {
+                        public void task()
+                            throws Exception
+                        {
+                            IOUtil.toByteArray( nullInputStream(), 0 );
+                        }
+                    }, runsForLongerThan( 100 ) );
+    }
+
+    @Test
+    public void toByteArrayFromInputStreamPosBufSz()
+        throws Exception
+    {
+        String probe = "A string \u2345\u00ef";
+        assertThat( IOUtil.toByteArray( new DontCloseByteArrayInputStream( IOUtil.toByteArray( probe ) ), +1 ),
+                    is( probe.getBytes() ) );
+    }
+
+    @Test( expected = NullPointerException.class )
+    public void toByteArrayNullInputStreamPosBufSz()
+        throws Exception
+    {
+        IOUtil.toByteArray( nullInputStream(), +1 );
+    }
+
 
     /*
      * Utility methods