1 38 package com.gargoylesoftware.htmlunit; 39 40 47 public class Base64Test extends WebTestCase { 48 52 public Base64Test( final String name ) { 53 super( name ); 54 } 55 56 57 60 public void testEncode() { 61 final String data[][] = { 62 {"", ""}, 63 {"a", "YQ=="}, 64 {"bc", "YmM="}, 65 {"def", "ZGVm"}, 66 {"ghij", "Z2hpag=="}, 67 {"klmno", "a2xtbm8="}, 68 {"pqrztu", "cHFyenR1"}, 69 }; 70 71 for( int i = 0; i < data.length; i++ ) { 72 final String input = data[i][0]; 73 final String expectedOutput = data[i][1]; 74 75 assertEquals( "encoding \"" + input + "\"", expectedOutput, Base64.encode( input ) ); 76 } 77 } 78 79 80 84 public void testEncodeStringEncoding_NullString() 85 throws Exception { 86 try { 87 Base64.encode( null, "us-ascii" ); 88 fail( "Expected NullPointerException" ); 89 } 90 catch( final NullPointerException e ) { 91 } 93 } 94 95 96 100 public void testEncodeStringEncoding_NullEncoding() 101 throws Exception { 102 try { 103 Base64.encode( null, "us-ascii" ); 104 fail( "Expected NullPointerException" ); 105 } 106 catch( final NullPointerException e ) { 107 } 109 } 110 111 112 116 public void testEncodeString_Null() 117 throws Exception { 118 try { 119 Base64.encode( ( String )null ); 120 fail( "Expected NullPointerException" ); 121 } 122 catch( final NullPointerException e ) { 123 } 125 } 126 127 128 132 public void testEncodeBytes_NullArray() 133 throws Exception { 134 try { 135 Base64.encode( "foo", null ); 136 fail( "Expected NullPointerException" ); 137 } 138 catch( final NullPointerException e ) { 139 } 141 } 142 } 143 144 | Popular Tags |