Author: ggregory
Date: Fri Nov 30 14:30:20 2012
New Revision: 1415656

URL: http://svn.apache.org/viewvc?rev=1415656&view=rev
Log:
Sort members.

Modified:
    
commons/proper/io/trunk/src/test/java/org/apache/commons/io/input/CharSequenceInputStreamTest.java

Modified: 
commons/proper/io/trunk/src/test/java/org/apache/commons/io/input/CharSequenceInputStreamTest.java
URL: 
http://svn.apache.org/viewvc/commons/proper/io/trunk/src/test/java/org/apache/commons/io/input/CharSequenceInputStreamTest.java?rev=1415656&r1=1415655&r2=1415656&view=diff
==============================================================================
--- 
commons/proper/io/trunk/src/test/java/org/apache/commons/io/input/CharSequenceInputStreamTest.java
 (original)
+++ 
commons/proper/io/trunk/src/test/java/org/apache/commons/io/input/CharSequenceInputStreamTest.java
 Fri Nov 30 14:30:20 2012
@@ -29,9 +29,11 @@ import org.junit.Test;
 
 public class CharSequenceInputStreamTest {
     
-    private static final String TEST_STRING = "\u00e0 peine arriv\u00e9s nous 
entr\u00e2mes dans sa chambre";
+    private static final String ALPHABET = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
     private static final String LARGE_TEST_STRING;
     
+    private static final String TEST_STRING = "\u00e0 peine arriv\u00e9s nous 
entr\u00e2mes dans sa chambre";
+    
     static {
         StringBuilder buffer = new StringBuilder();
         for (int i=0; i<100; i++) {
@@ -39,71 +41,83 @@ public class CharSequenceInputStreamTest
         }
         LARGE_TEST_STRING = buffer.toString();
     }
-    
-    private static final String ALPHABET = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
 
     private Random random = new Random();
     
-    private void testWithSingleByteRead(String testString, String charsetName) 
throws IOException {
-        byte[] bytes = testString.getBytes(charsetName);
-        InputStream in = new CharSequenceInputStream(testString, charsetName, 
512);
-        for (byte b : bytes) {
-            int read = in.read();
-            assertTrue("read "+read+" >=0 ", read >= 0);
-            assertTrue("read "+read+" <= 255", read <= 255);
-            assertEquals("Should agree with input", b, (byte)read);
+    @Test
+    public void testCharsetMismatchInfiniteLoop() throws IOException {
+        // Input is UTF-8 bytes: 0xE0 0xB2 0xA0
+        char[] inputChars = new char[] { (char) 0xE0, (char) 0xB2, (char) 0xA0 
};
+        // Charset charset = Charset.forName("UTF-8"); // works
+        Charset charset = Charset.forName("ASCII"); // infinite loop
+        InputStream stream = new CharSequenceInputStream(new 
String(inputChars), charset, 512);
+        try {
+            while (stream.read() != -1) {
+            }
+        } finally {
+            stream.close();
         }
-        assertEquals(-1, in.read());
     }
     
-    private void testWithBufferedRead(String testString, String charsetName) 
throws IOException {
-        byte[] expected = testString.getBytes(charsetName);
-        InputStream in = new CharSequenceInputStream(testString, charsetName, 
512);
-        byte[] buffer = new byte[128];
-        int offset = 0;
-        while (true) {
-            int bufferOffset = random.nextInt(64);
-            int bufferLength = random.nextInt(64);
-            int read = in.read(buffer, bufferOffset, bufferLength);
-            if (read == -1) {
-                assertEquals("EOF: offset should equal length", 
expected.length, offset);
-                break;
-            } else {
-                assertTrue("Read "+read+" <= "+bufferLength, read <= 
bufferLength);
-                while (read > 0) {
-                    assertTrue("offset "+offset+" < "+expected.length, offset 
< expected.length);
-                    assertEquals("bytes should agree", expected[offset], 
buffer[bufferOffset]);
-                    offset++;
-                    bufferOffset++;
-                    read--;
-                }
+    @Test
+    public void testIO_356() throws Exception {
+        testIO_356(10, 10); // OK
+        testIO_356(10, 20); // OK
+        testIO_356(10, 13); // fails
+        for(int bs = 1; bs <= 10; bs++) {
+            for(int ds = 1; ds <= 20; ds++) {
+                testIO_356(bs, ds);                
             }
         }
     }
     
-    @Test
-    public void testUTF8WithSingleByteRead() throws IOException {
-        testWithSingleByteRead(TEST_STRING, "UTF-8");
+    private void testIO_356(int bufferSize, int dataSize) throws Exception {
+        CharSequenceInputStream is = new CharSequenceInputStream(ALPHABET, 
"UTF-8", bufferSize);
+
+        is.mark(dataSize);
+
+        byte[] data1 = new byte[dataSize];
+        is.read(data1);
+
+        is.reset(); // should allow data to be re-read
+
+        byte[] data2 = new byte[dataSize];
+        is.read(data2);
+
+        is.close();
+        assertArrayEquals("bufferSize="+bufferSize+" dataSize="+dataSize, 
data1, data2); // data buffers should be identical
     }
     
     @Test
-    public void testLargeUTF8WithSingleByteRead() throws IOException {
-        testWithSingleByteRead(LARGE_TEST_STRING, "UTF-8");
+    public void testLargeUTF8WithBufferedRead() throws IOException {
+        testWithBufferedRead(LARGE_TEST_STRING, "UTF-8");
     }
     
     @Test
-    public void testUTF8WithBufferedRead() throws IOException {
-        testWithBufferedRead(TEST_STRING, "UTF-8");
+    public void testLargeUTF8WithSingleByteRead() throws IOException {
+        testWithSingleByteRead(LARGE_TEST_STRING, "UTF-8");
     }
     
     @Test
-    public void testLargeUTF8WithBufferedRead() throws IOException {
-        testWithBufferedRead(LARGE_TEST_STRING, "UTF-8");
+    public void testMarkReset() throws Exception {
+        InputStream r = new CharSequenceInputStream("test", "UTF-8");
+        r.skip(2);
+        r.mark(0);
+        assertEquals('s', r.read());
+        assertEquals('t', r.read());
+        assertEquals(-1, r.read());
+        r.reset();
+        assertEquals('s', r.read());
+        assertEquals('t', r.read());
+        assertEquals(-1, r.read());
+        r.reset();
+        r.reset();
     }
     
     @Test
-    public void testUTF16WithSingleByteRead() throws IOException {
-        testWithSingleByteRead(TEST_STRING, "UTF-16");
+    public void testMarkSupported() throws Exception {
+        InputStream r = new CharSequenceInputStream("test", "UTF-8");
+        assertTrue(r.markSupported());
     }
     
     @Test
@@ -121,21 +135,6 @@ public class CharSequenceInputStreamTest
     }
     
     @Test
-    public void testCharsetMismatchInfiniteLoop() throws IOException {
-        // Input is UTF-8 bytes: 0xE0 0xB2 0xA0
-        char[] inputChars = new char[] { (char) 0xE0, (char) 0xB2, (char) 0xA0 
};
-        // Charset charset = Charset.forName("UTF-8"); // works
-        Charset charset = Charset.forName("ASCII"); // infinite loop
-        InputStream stream = new CharSequenceInputStream(new 
String(inputChars), charset, 512);
-        try {
-            while (stream.read() != -1) {
-            }
-        } finally {
-            stream.close();
-        }
-    }
-
-    @Test
     public void testSkip() throws Exception {
         InputStream r = new CharSequenceInputStream("test", "UTF-8");
         r.skip(1);
@@ -146,53 +145,54 @@ public class CharSequenceInputStreamTest
     }
 
     @Test
-    public void testMarkReset() throws Exception {
-        InputStream r = new CharSequenceInputStream("test", "UTF-8");
-        r.skip(2);
-        r.mark(0);
-        assertEquals('s', r.read());
-        assertEquals('t', r.read());
-        assertEquals(-1, r.read());
-        r.reset();
-        assertEquals('s', r.read());
-        assertEquals('t', r.read());
-        assertEquals(-1, r.read());
-        r.reset();
-        r.reset();
+    public void testUTF16WithSingleByteRead() throws IOException {
+        testWithSingleByteRead(TEST_STRING, "UTF-16");
     }
 
     @Test
-    public void testMarkSupported() throws Exception {
-        InputStream r = new CharSequenceInputStream("test", "UTF-8");
-        assertTrue(r.markSupported());
+    public void testUTF8WithBufferedRead() throws IOException {
+        testWithBufferedRead(TEST_STRING, "UTF-8");
     }
 
-    private void testIO_356(int bufferSize, int dataSize) throws Exception {
-        CharSequenceInputStream is = new CharSequenceInputStream(ALPHABET, 
"UTF-8", bufferSize);
-
-        is.mark(dataSize);
-
-        byte[] data1 = new byte[dataSize];
-        is.read(data1);
-
-        is.reset(); // should allow data to be re-read
-
-        byte[] data2 = new byte[dataSize];
-        is.read(data2);
+    @Test
+    public void testUTF8WithSingleByteRead() throws IOException {
+        testWithSingleByteRead(TEST_STRING, "UTF-8");
+    }
 
-        is.close();
-        assertArrayEquals("bufferSize="+bufferSize+" dataSize="+dataSize, 
data1, data2); // data buffers should be identical
+    private void testWithBufferedRead(String testString, String charsetName) 
throws IOException {
+        byte[] expected = testString.getBytes(charsetName);
+        InputStream in = new CharSequenceInputStream(testString, charsetName, 
512);
+        byte[] buffer = new byte[128];
+        int offset = 0;
+        while (true) {
+            int bufferOffset = random.nextInt(64);
+            int bufferLength = random.nextInt(64);
+            int read = in.read(buffer, bufferOffset, bufferLength);
+            if (read == -1) {
+                assertEquals("EOF: offset should equal length", 
expected.length, offset);
+                break;
+            } else {
+                assertTrue("Read "+read+" <= "+bufferLength, read <= 
bufferLength);
+                while (read > 0) {
+                    assertTrue("offset "+offset+" < "+expected.length, offset 
< expected.length);
+                    assertEquals("bytes should agree", expected[offset], 
buffer[bufferOffset]);
+                    offset++;
+                    bufferOffset++;
+                    read--;
+                }
+            }
+        }
     }
     
-    @Test
-    public void testIO_356() throws Exception {
-        testIO_356(10, 10); // OK
-        testIO_356(10, 20); // OK
-        testIO_356(10, 13); // fails
-        for(int bs = 1; bs <= 10; bs++) {
-            for(int ds = 1; ds <= 20; ds++) {
-                testIO_356(bs, ds);                
-            }
+    private void testWithSingleByteRead(String testString, String charsetName) 
throws IOException {
+        byte[] bytes = testString.getBytes(charsetName);
+        InputStream in = new CharSequenceInputStream(testString, charsetName, 
512);
+        for (byte b : bytes) {
+            int read = in.read();
+            assertTrue("read "+read+" >=0 ", read >= 0);
+            assertTrue("read "+read+" <= 255", read <= 255);
+            assertEquals("Should agree with input", b, (byte)read);
         }
+        assertEquals(-1, in.read());
     }
 }


Reply via email to