You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@commons.apache.org by gg...@apache.org on 2003/11/03 08:23:33 UTC

cvs commit: jakarta-commons/codec/src/test/org/apache/commons/codec/binary Base64Test.java

ggregory    2003/11/02 23:23:33

  Modified:    codec/src/test/org/apache/commons/codec/binary
                        Base64Test.java
  Log:
  Improve test coverage (See clover report).
  
  Revision  Changes    Path
  1.9       +49 -3     jakarta-commons/codec/src/test/org/apache/commons/codec/binary/Base64Test.java
  
  Index: Base64Test.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/codec/src/test/org/apache/commons/codec/binary/Base64Test.java,v
  retrieving revision 1.8
  retrieving revision 1.9
  diff -u -r1.8 -r1.9
  --- Base64Test.java	5 Oct 2003 21:45:49 -0000	1.8
  +++ Base64Test.java	3 Nov 2003 07:23:33 -0000	1.9
  @@ -92,6 +92,26 @@
           assertTrue("encoding hello world", encodedContent.equals("SGVsbG8gV29ybGQ="));
       }
   
  +    /**
  +     * Tests conditional true branch for "marker0" test.
  +     */
  +    public void testDecodePadMarkerIndex2() {
  +        assertEquals("A", new String(Base64.decodeBase64("QQ==".getBytes())));
  +    }
  +    
  +    /**
  +     * Tests conditional branches for "marker1" test.
  +     */
  +    public void testDecodePadMarkerIndex3() {
  +        assertEquals("AA", new String(Base64.decodeBase64("QUE=".getBytes())));
  +        assertEquals("AAA", new String(Base64.decodeBase64("QUFB".getBytes())));
  +    }
  +    
  +    public void testDecodePadOnly() {
  +        assertTrue(Base64.decodeBase64("====".getBytes()).length == 0);
  +        assertEquals("", new String(Base64.decodeBase64("====".getBytes())));
  +    }
  +    
       // encode/decode random arrays from size 0 to size 11
       public void testEncodeDecodeSmall() {
           for(int i=0;i<12;i++) {
  @@ -100,7 +120,7 @@
               byte[] enc =  Base64.encodeBase64(data);
               assertTrue("\"" + (new String(enc)) + "\" is Base64 data.",Base64.isArrayByteBase64(enc) );
               byte[] data2 = Base64.decodeBase64(enc);
  -            assertTrue(toString(data) + " equals " + toString(data2),Arrays.equals(data,data2));
  +            assertTrue(toString(data) + " equals " + toString(data2), Arrays.equals(data,data2));
           }
       }
   
  @@ -407,7 +427,7 @@
                       dest.equals( original ) );
       }
   
  -    public void testDiscardingOfWhiteSpace() throws Exception {
  +    public void testDecodeWithWhitespace() throws Exception {
   
           String orig = "I am a late night coder.";
   
  @@ -429,6 +449,32 @@
                       dest.equals( orig ) );
       }
   
  +    public void testDiscardWhitespace() throws Exception {
  +
  +        String orig = "I am a late night coder.";
  +
  +        byte[] encodedArray = Base64.encodeBase64( orig.getBytes() );
  +        StringBuffer intermediate = 
  +            new StringBuffer( new String(encodedArray) );
  +
  +        intermediate.insert( 2, ' ' );
  +        intermediate.insert( 5, '\t' );
  +        intermediate.insert( 10, '\r' );
  +        intermediate.insert( 15, '\n' );
  +
  +        byte[] encodedWithWS = intermediate.toString().getBytes();
  +        byte[] encodedNoWS = Base64.discardWhitespace( encodedWithWS );
  +        byte[] decodedWithWS = Base64.decodeBase64( encodedWithWS );
  +        byte[] decodedNoWS = Base64.decodeBase64( encodedNoWS );
  +
  +        String destFromWS = new String( decodedWithWS );
  +        String destFromNoWS = new String( decodedNoWS );
  +
  +        assertTrue( "Dest string doesn't eausl original", 
  +                destFromWS.equals( orig ) );
  +        assertTrue( "Dest string doesn't eausl original", 
  +                destFromNoWS.equals( orig ) );
  +    }
   
       // -------------------------------------------------------- Private Methods
   
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org