View Javadoc

1   package liquibase.util;
2   
3   import static org.junit.Assert.*;
4   import org.junit.Test;
5   
6   import java.io.ByteArrayInputStream;
7   
8   public class MD5UtilTest {
9   
10  	private static final String TEST_STRING = "foo";
11  	private static final String TEST_STRING_MD5_HASH = "acbd18db4cc2f85cedef654fccc4a4d8";
12  
13      private static final String TEST_STRING2 = "abc";
14      private static final String TEST_STRING2_MD5_HASH = "900150983cd24fb0d6963f7d28e17f72";
15  
16      private static final String TEST_STRING3 = "bbb";
17      private static final String TEST_STRING3_MD5_HASH = "08f8e0260c64418510cefb2b06eee5cd";
18  
19  	@Test
20  	public void testComputeMD5() throws Exception {
21  		String hash = MD5Util.computeMD5(TEST_STRING);
22  		assertEquals(TEST_STRING_MD5_HASH, hash);
23  
24          String hash2 = MD5Util.computeMD5(TEST_STRING2);
25          assertEquals(TEST_STRING2_MD5_HASH, hash2);
26  
27          String hash3 = MD5Util.computeMD5(TEST_STRING3);
28          assertEquals(TEST_STRING3_MD5_HASH, hash3);
29  	}
30  
31  	@Test
32  	public void testComputeMD5InputStream() {
33  		ByteArrayInputStream bais = new ByteArrayInputStream(TEST_STRING.getBytes());
34  		String hexString = MD5Util.computeMD5(bais);
35  		assertEquals(TEST_STRING_MD5_HASH, hexString);
36  	}
37  
38  }