1 16 17 package org.apache.commons.codec.digest; 18 19 import junit.framework.TestCase; 20 21 26 public class DigestUtilsTest extends TestCase { 27 28 public void testInternalNoSuchAlgorithmException() { 29 try { 30 DigestUtils.getDigest("Bogus Bogus"); 31 fail("A RuntimeException should have been thrown."); 32 } catch (RuntimeException e) { 33 } 35 } 36 37 public void testMd5Hex() { 38 assertEquals("d41d8cd98f00b204e9800998ecf8427e", DigestUtils.md5Hex("")); 40 41 assertEquals("0cc175b9c0f1b6a831c399e269772661", DigestUtils.md5Hex("a")); 42 43 assertEquals("900150983cd24fb0d6963f7d28e17f72", DigestUtils.md5Hex("abc")); 44 45 assertEquals("f96b697d7cb7938d525a2f31aaf161d0", DigestUtils.md5Hex("message digest")); 46 47 assertEquals("c3fcd3d76192e4007dfb496cca67e13b", DigestUtils.md5Hex("abcdefghijklmnopqrstuvwxyz")); 48 49 assertEquals( 50 "d174ab98d277d9f5a5611c2c9f419d9f", 51 DigestUtils.md5Hex("ABCDEFGHIJKLMNOPQRSTUVWXYZ" + "abcdefghijklmnopqrstuvwxyz" + "0123456789")); 52 53 assertEquals( 54 "57edf4a22be3c955ac49da2e2107b67a", 55 DigestUtils.md5Hex("1234567890123456789012345678901234567890" + "1234567890123456789012345678901234567890")); 56 } 57 58 61 public void testMD5HexLength() { 62 String hashMe = "this is some string that is longer than 32 characters"; 63 String hash = DigestUtils.md5Hex(hashMe.getBytes()); 64 assertEquals(32, hash.length()); 65 66 hashMe = "length < 32"; 67 hash = DigestUtils.md5Hex(hashMe.getBytes()); 68 assertEquals(32, hash.length()); 69 } 70 71 74 public void testMD5Length() { 75 String hashMe = "this is some string that is longer than 16 characters"; 76 byte[] hash = DigestUtils.md5(hashMe.getBytes()); 77 assertEquals(16, hash.length); 78 79 hashMe = "length < 16"; 80 hash = DigestUtils.md5(hashMe.getBytes()); 81 assertEquals(16, hash.length); 82 } 83 84 public void testShaHex() { 85 assertEquals("a9993e364706816aba3e25717850c26c9cd0d89d", DigestUtils.shaHex("abc")); 87 88 assertEquals("a9993e364706816aba3e25717850c26c9cd0d89d", DigestUtils.shaHex("abc".getBytes())); 89 90 assertEquals( 91 "84983e441c3bd26ebaae4aa1f95129e5e54670f1", 92 DigestUtils.shaHex("abcdbcdecdefdefgefghfghighij" + "hijkijkljklmklmnlmnomnopnopq")); 93 } 94 95 } 96 | Popular Tags |