hc-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ol...@apache.org
Subject svn commit: r159721 - in jakarta/httpclient/trunk/http-common/src: java/org/apache/http/util/EncodingUtil.java java/org/apache/http/util/HttpLineParser.java test/org/apache/http/util/TestEncodingUtils.java test/org/apache/http/util/TestHttpLineParser.java
Date Fri, 01 Apr 2005 19:21:15 GMT
Author: olegk
Date: Fri Apr  1 11:21:13 2005
New Revision: 159721

URL: http://svn.apache.org/viewcvs?view=rev&rev=159721
Log:
Extra test coverage

Modified:
    jakarta/httpclient/trunk/http-common/src/java/org/apache/http/util/EncodingUtil.java
    jakarta/httpclient/trunk/http-common/src/java/org/apache/http/util/HttpLineParser.java
    jakarta/httpclient/trunk/http-common/src/test/org/apache/http/util/TestEncodingUtils.java
    jakarta/httpclient/trunk/http-common/src/test/org/apache/http/util/TestHttpLineParser.java

Modified: jakarta/httpclient/trunk/http-common/src/java/org/apache/http/util/EncodingUtil.java
URL: http://svn.apache.org/viewcvs/jakarta/httpclient/trunk/http-common/src/java/org/apache/http/util/EncodingUtil.java?view=diff&r1=159720&r2=159721
==============================================================================
--- jakarta/httpclient/trunk/http-common/src/java/org/apache/http/util/EncodingUtil.java (original)
+++ jakarta/httpclient/trunk/http-common/src/java/org/apache/http/util/EncodingUtil.java Fri
Apr  1 11:21:13 2005
@@ -181,6 +181,9 @@
      * @since 3.0
      */
     public static String getAsciiString(final byte[] data) {
+        if (data == null) {
+            throw new IllegalArgumentException("Parameter may not be null");
+        }
         return getAsciiString(data, 0, data.length);
     }
 

Modified: jakarta/httpclient/trunk/http-common/src/java/org/apache/http/util/HttpLineParser.java
URL: http://svn.apache.org/viewcvs/jakarta/httpclient/trunk/http-common/src/java/org/apache/http/util/HttpLineParser.java?view=diff&r1=159720&r2=159721
==============================================================================
--- jakarta/httpclient/trunk/http-common/src/java/org/apache/http/util/HttpLineParser.java
(original)
+++ jakarta/httpclient/trunk/http-common/src/java/org/apache/http/util/HttpLineParser.java
Fri Apr  1 11:21:13 2005
@@ -112,23 +112,5 @@
         }
         return EncodingUtil.getString(rawdata, 0, len - offset, charset);
     }
-
-    /**
-     * Read up to <tt>"\n"</tt> from an (unchunked) input stream.
-     * If the stream ends before the line terminator is found,
-     * the last part of the string will still be returned.
-     * If no input data available, <code>null</code> is returned
-     *
-     * @param inputStream the stream to read from
-     *
-     * @throws IOException if an I/O problem occurs
-     * @return a line from the stream
-     * 
-     * @deprecated use #readLine(InputStream, String)
-     */
-
-    public static String readLine(final InputStream inputStream) throws IOException {
-        return readLine(inputStream, "US-ASCII");
-    }
     
 }

Modified: jakarta/httpclient/trunk/http-common/src/test/org/apache/http/util/TestEncodingUtils.java
URL: http://svn.apache.org/viewcvs/jakarta/httpclient/trunk/http-common/src/test/org/apache/http/util/TestEncodingUtils.java?view=diff&r1=159720&r2=159721
==============================================================================
--- jakarta/httpclient/trunk/http-common/src/test/org/apache/http/util/TestEncodingUtils.java
(original)
+++ jakarta/httpclient/trunk/http-common/src/test/org/apache/http/util/TestEncodingUtils.java
Fri Apr  1 11:21:13 2005
@@ -82,6 +82,12 @@
         assertEquals(s, s3);
         
         try {
+            EncodingUtil.getString(null, 0, 0, "UTF-8");
+            fail("IllegalArgumentException should have been thrown");
+        } catch (IllegalArgumentException ex) {
+            // expected
+        }
+        try {
             EncodingUtil.getString(null, "UTF-8");
             fail("IllegalArgumentException should have been thrown");
         } catch (IllegalArgumentException ex) {
@@ -150,6 +156,18 @@
     public void testAsciiBytesToString() throws Exception {
         String s = "ascii only, I mean it!";
         assertEquals(s, EncodingUtil.getAsciiString(s.getBytes("US-ASCII")));
+        try {
+            EncodingUtil.getAsciiString(null);
+            fail("IllegalArgumentException should have been thrown");
+        } catch (IllegalArgumentException ex) {
+            // expected
+        }
+        try {
+            EncodingUtil.getAsciiString(null, 0, 0);
+            fail("IllegalArgumentException should have been thrown");
+        } catch (IllegalArgumentException ex) {
+            // expected
+        }
     }
     
     public void testAsciiStringToBytes() throws Exception {
@@ -162,6 +180,16 @@
         for (int i = 0; i < ascii.length; i++) {
             assertEquals(ascii[i], data[i]);
         }
+        try {
+            EncodingUtil.getAsciiBytes(null);
+            fail("IllegalArgumentException should have been thrown");
+        } catch (IllegalArgumentException ex) {
+            // expected
+        }
+    }
+    
+    public void testAsciiNotSupportedError() {
+        new EncodingUtil.AsciiNotSupportedError("Fatal error");
     }
     
 }

Modified: jakarta/httpclient/trunk/http-common/src/test/org/apache/http/util/TestHttpLineParser.java
URL: http://svn.apache.org/viewcvs/jakarta/httpclient/trunk/http-common/src/test/org/apache/http/util/TestHttpLineParser.java?view=diff&r1=159720&r2=159721
==============================================================================
--- jakarta/httpclient/trunk/http-common/src/test/org/apache/http/util/TestHttpLineParser.java
(original)
+++ jakarta/httpclient/trunk/http-common/src/test/org/apache/http/util/TestHttpLineParser.java
Fri Apr  1 11:21:13 2005
@@ -69,10 +69,13 @@
         assertEquals(null, HttpLineParser.readLine(instream, ASCII));
 
         instream = new ByteArrayInputStream(
-            "\n\r\nstuff\r\n".getBytes(ASCII)); 
+            "\n\r\nstuff\r\nstuff\nstuff".getBytes(ASCII)); 
         assertEquals("", HttpLineParser.readLine(instream, ASCII));
         assertEquals("", HttpLineParser.readLine(instream, ASCII));
         assertEquals("stuff", HttpLineParser.readLine(instream, ASCII));
+        assertEquals("stuff", HttpLineParser.readLine(instream, ASCII));
+        assertEquals("stuff", HttpLineParser.readLine(instream, ASCII));
+        assertEquals(null, HttpLineParser.readLine(instream, ASCII));
         assertEquals(null, HttpLineParser.readLine(instream, ASCII));
     }
 
@@ -93,8 +96,10 @@
     public void testReadMultibyeHttpLine() throws Exception {
         String s = constructString(SWISS_GERMAN_HELLO);
         InputStream instream = new ByteArrayInputStream(
-            ("\r\r\n" + s + "\r\n").getBytes(UTF8)); 
+            ("\r\r\n" + s + "\r\n" + s + "\n" + s).getBytes(UTF8)); 
         assertEquals("\r", HttpLineParser.readLine(instream, UTF8));
+        assertEquals(s, HttpLineParser.readLine(instream, UTF8));
+        assertEquals(s, HttpLineParser.readLine(instream, UTF8));
         assertEquals(s, HttpLineParser.readLine(instream, UTF8));
         assertEquals(null, HttpLineParser.readLine(instream, UTF8));
 



Mime
View raw message