Skip to content

Commit a0c1b19

Browse files
committed
Fix some typos. Tidy test cases.
git-svn-id: https://svn.apache.org/repos/asf/commons/proper/codec/trunk@669695 13f79535-47bb-0310-9956-ffa450edef68
1 parent 6bc22c0 commit a0c1b19

1 file changed

Lines changed: 18 additions & 28 deletions

File tree

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

Lines changed: 18 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,15 @@
2121
import java.util.Arrays;
2222
import java.util.Random;
2323
import java.math.BigInteger;
24+
25+
import org.apache.commons.codec.DecoderException;
26+
import org.apache.commons.codec.EncoderException;
27+
2428
import junit.framework.TestCase;
2529

2630
/**
31+
* Testcases for Base64 class.
32+
*
2733
* @author Apache Software Foundation
2834
* @version $Id$
2935
*/
@@ -489,8 +495,6 @@ public void testNonBase64Test() throws Exception {
489495
"an array of Base64 encoded data",
490496
Base64.isArrayByteBase64( bArray ) );
491497

492-
boolean exceptionThrown = false;
493-
494498
try {
495499
Base64 b64 = new Base64();
496500
byte[] result = b64.decode( bArray );
@@ -499,15 +503,11 @@ public void testNonBase64Test() throws Exception {
499503
"not contain any valid base 64 characters", result.length == 0);
500504
}
501505
catch( Exception e ) {
502-
exceptionThrown = true;
503-
}
504-
505-
assertFalse( "Exception was thrown when trying to decode " +
506+
fail( "Exception was thrown when trying to decode " +
506507
"invalid base64 encoded data - RFC 2045 requires that all " +
507508
"non base64 character be discarded, an exception should not" +
508-
" have been thrown", exceptionThrown );
509-
510-
509+
" have been thrown");
510+
}
511511
}
512512

513513
public void testIgnoringNonBase64InDecode() throws Exception {
@@ -529,19 +529,15 @@ public void testIsArrayByteBase64() {
529529
}
530530

531531
public void testObjectDecodeWithInvalidParameter() throws Exception {
532-
boolean exceptionThrown = false;
533-
534532
Base64 b64 = new Base64();
535533

536534
try {
537-
Object o = "Yadayadayada";
538-
b64.decode( o );
539-
} catch( Exception e ) {
540-
exceptionThrown = true;
535+
b64.decode( "Yadayadayada");
536+
fail( "decode(Object) didn't throw an exception when passed a String object");
537+
} catch( DecoderException e ) {
538+
// ignored
541539
}
542540

543-
assertTrue( "decode(Object) didn't throw an exception when passed a " +
544-
"String object", exceptionThrown );
545541
}
546542

547543
public void testObjectDecodeWithValidParameter() throws Exception {
@@ -556,24 +552,18 @@ public void testObjectDecodeWithValidParameter() throws Exception {
556552
byte[] baDecoded = (byte[]) oDecoded;
557553
String dest = new String( baDecoded );
558554

559-
assertTrue( "dest string down not equal original",
555+
assertTrue( "dest string does not equal original",
560556
dest.equals( original ) );
561557
}
562558

563559
public void testObjectEncodeWithInvalidParameter() throws Exception {
564-
boolean exceptionThrown = false;
565-
566560
Base64 b64 = new Base64();
567561

568562
try {
569-
Object o = "Yadayadayada";
570-
b64.encode( o );
571-
} catch( Exception e ) {
572-
exceptionThrown = true;
563+
b64.encode( "Yadayadayada" );
564+
fail( "encode(Object) didn't throw an exception when passed a String object");
565+
} catch( EncoderException e ) {
573566
}
574-
575-
assertTrue( "encode(Object) didn't throw an exception when passed a " +
576-
"String object", exceptionThrown );
577567
}
578568

579569
public void testObjectEncodeWithValidParameter() throws Exception {
@@ -588,7 +578,7 @@ public void testObjectEncodeWithValidParameter() throws Exception {
588578
Base64.decodeBase64( (byte[]) oEncoded );
589579
String dest = new String( bArray );
590580

591-
assertTrue( "dest string down not equal original",
581+
assertTrue( "dest string does not equal original",
592582
dest.equals( original ) );
593583
}
594584

0 commit comments

Comments
 (0)