Skip to content

Commit b872234

Browse files
committed
Improve test coverage (See clover report).
git-svn-id: https://svn.apache.org/repos/asf/jakarta/commons/proper/codec/trunk@130222 13f79535-47bb-0310-9956-ffa450edef68
1 parent ddf6ebf commit b872234

1 file changed

Lines changed: 49 additions & 3 deletions

File tree

src/test/org/apache/commons/codec/binary/Base64Test.java

Lines changed: 49 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@
6464
import junit.framework.TestCase;
6565

6666
/**
67-
* @version $Revision: 1.8 $ $Date: 2003/10/05 21:45:49 $
67+
* @version $Revision: 1.9 $ $Date: 2003/11/03 07:23:33 $
6868
* @author <a href="mailto:sanders@apache.org">Scott Sanders</a>
6969
* @author <a href="mailto:rwaldhoff@apache.org">Rodney Waldhoff</a>
7070
* @author Tim O'Brien
@@ -92,6 +92,26 @@ public void testBase64() {
9292
assertTrue("encoding hello world", encodedContent.equals("SGVsbG8gV29ybGQ="));
9393
}
9494

95+
/**
96+
* Tests conditional true branch for "marker0" test.
97+
*/
98+
public void testDecodePadMarkerIndex2() {
99+
assertEquals("A", new String(Base64.decodeBase64("QQ==".getBytes())));
100+
}
101+
102+
/**
103+
* Tests conditional branches for "marker1" test.
104+
*/
105+
public void testDecodePadMarkerIndex3() {
106+
assertEquals("AA", new String(Base64.decodeBase64("QUE=".getBytes())));
107+
assertEquals("AAA", new String(Base64.decodeBase64("QUFB".getBytes())));
108+
}
109+
110+
public void testDecodePadOnly() {
111+
assertTrue(Base64.decodeBase64("====".getBytes()).length == 0);
112+
assertEquals("", new String(Base64.decodeBase64("====".getBytes())));
113+
}
114+
95115
// encode/decode random arrays from size 0 to size 11
96116
public void testEncodeDecodeSmall() {
97117
for(int i=0;i<12;i++) {
@@ -100,7 +120,7 @@ public void testEncodeDecodeSmall() {
100120
byte[] enc = Base64.encodeBase64(data);
101121
assertTrue("\"" + (new String(enc)) + "\" is Base64 data.",Base64.isArrayByteBase64(enc) );
102122
byte[] data2 = Base64.decodeBase64(enc);
103-
assertTrue(toString(data) + " equals " + toString(data2),Arrays.equals(data,data2));
123+
assertTrue(toString(data) + " equals " + toString(data2), Arrays.equals(data,data2));
104124
}
105125
}
106126

@@ -407,7 +427,7 @@ public void testObjectEncodeWithValidParameter() throws Exception {
407427
dest.equals( original ) );
408428
}
409429

410-
public void testDiscardingOfWhiteSpace() throws Exception {
430+
public void testDecodeWithWhitespace() throws Exception {
411431

412432
String orig = "I am a late night coder.";
413433

@@ -429,6 +449,32 @@ public void testDiscardingOfWhiteSpace() throws Exception {
429449
dest.equals( orig ) );
430450
}
431451

452+
public void testDiscardWhitespace() throws Exception {
453+
454+
String orig = "I am a late night coder.";
455+
456+
byte[] encodedArray = Base64.encodeBase64( orig.getBytes() );
457+
StringBuffer intermediate =
458+
new StringBuffer( new String(encodedArray) );
459+
460+
intermediate.insert( 2, ' ' );
461+
intermediate.insert( 5, '\t' );
462+
intermediate.insert( 10, '\r' );
463+
intermediate.insert( 15, '\n' );
464+
465+
byte[] encodedWithWS = intermediate.toString().getBytes();
466+
byte[] encodedNoWS = Base64.discardWhitespace( encodedWithWS );
467+
byte[] decodedWithWS = Base64.decodeBase64( encodedWithWS );
468+
byte[] decodedNoWS = Base64.decodeBase64( encodedNoWS );
469+
470+
String destFromWS = new String( decodedWithWS );
471+
String destFromNoWS = new String( decodedNoWS );
472+
473+
assertTrue( "Dest string doesn't eausl original",
474+
destFromWS.equals( orig ) );
475+
assertTrue( "Dest string doesn't eausl original",
476+
destFromNoWS.equals( orig ) );
477+
}
432478

433479
// -------------------------------------------------------- Private Methods
434480

0 commit comments

Comments
 (0)