1 19 20 package edu.umd.cs.findbugs.ba; 21 22 import java.util.Arrays ; 23 24 import junit.framework.Assert; 25 import junit.framework.TestCase; 26 27 30 public class MethodHashTest extends TestCase { 31 32 byte[] hash; 33 String s; 34 byte[] sameHash; 35 byte[] greaterHash; 36 byte[] lesserHash; 37 byte[] shorterHash; 38 byte[] longerHash; 39 40 43 @Override 45 protected void setUp() throws Exception { 46 hash = new byte[]{0x06, 0x04, (byte)0xDE, (byte)0xAD, (byte)0xBE, (byte)0xEF}; 47 s = "0604deadbeef"; 48 sameHash = new byte[]{0x06, 0x04, (byte)0xDE, (byte)0xAD, (byte)0xBE, (byte)0xEF}; 49 greaterHash = new byte[]{0x06, 0x05, (byte)0xDE, (byte)0xAD, (byte)0xBE, (byte)0xEF}; 50 lesserHash = new byte[]{0x06, 0x03, (byte)0xDE, (byte)0xAD, (byte)0xBE, (byte)0xEF}; 51 shorterHash = new byte[]{0x06, 0x04, (byte)0xDE, (byte)0xAD, (byte)0xBE}; 52 longerHash = new byte[]{0x06, 0x04, (byte)0xDE, (byte)0xAD, (byte)0xBE, (byte)0xEF, (byte)0x01}; 53 } 54 55 public void testHashToString() { 56 String s2 = ClassHash.hashToString(hash); 57 Assert.assertEquals(s, s2); 58 } 59 60 public void testStringToHash() { 61 byte[] hash2 = ClassHash.stringToHash(s); 62 Assert.assertTrue(Arrays.equals(hash, hash2)); 63 } 64 65 public void testSame() { 66 Assert.assertTrue(MethodHash.compareHashes(hash, sameHash) == 0); 67 Assert.assertTrue(MethodHash.compareHashes(sameHash, hash) == 0); 68 } 69 70 public void testGreater() { 71 Assert.assertTrue(MethodHash.compareHashes(hash, greaterHash) < 0); 72 } 73 74 public void testLesser() { 75 Assert.assertTrue(MethodHash.compareHashes(hash, lesserHash) > 0); 76 } 77 78 public void testShorter() { 79 Assert.assertTrue(MethodHash.compareHashes(hash, shorterHash) > 0); 80 } 81 82 public void testLonger() { 83 Assert.assertTrue(MethodHash.compareHashes(hash, longerHash) < 0); 84 } 85 } 86 | Popular Tags |