KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > openedit > archive > cumulus > HexToBinaryConverterTest


1 package com.openedit.archive.cumulus;
2
3 import com.openedit.archive.cumulus.HexToBinaryConverter;
4
5 import junit.framework.TestCase;
6
7 public class HexToBinaryConverterTest extends TestCase
8 {
9     public void testHexToBinary_Normal()
10     {
11         byte[] bytes = new HexToBinaryConverter().hexToBinary( "00121EA0FF" );
12         assertEquals( 5, bytes.length );
13         assertEquals( (byte) 0, bytes[0] );
14         assertEquals( (byte) '\u0012', bytes[1] );
15         assertEquals( (byte) '\u001E', bytes[2] );
16         assertEquals( (byte) '\u00A0', bytes[3] );
17         assertEquals( (byte) '\u00FF', bytes[4] );
18     }
19     
20     public void testHexToBinary_InvalidHex()
21     {
22         try
23         {
24             new HexToBinaryConverter().hexToBinary( "0012FX" );
25             fail( "Should have caught an IllegalArgumentException" );
26         }
27         catch ( IllegalArgumentException JavaDoc iae )
28         {
29             // This is expected.
30
}
31     }
32     
33     public void testHexToBinary_InvalidLength()
34     {
35         try
36         {
37             new HexToBinaryConverter().hexToBinary( "12345" );
38             fail( "Should have caught an IllegalArgumentException" );
39         }
40         catch ( IllegalArgumentException JavaDoc iae )
41         {
42             // This is expected.
43
}
44     }
45 }
46
Popular Tags