01: /*
02: * FindBugs - Find Bugs in Java programs
03: * Copyright (C) 2005, University of Maryland
04: *
05: * This library is free software; you can redistribute it and/or
06: * modify it under the terms of the GNU Lesser General Public
07: * License as published by the Free Software Foundation; either
08: * version 2.1 of the License, or (at your option) any later version.
09: *
10: * This library is distributed in the hope that it will be useful,
11: * but WITHOUT ANY WARRANTY; without even the implied warranty of
12: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13: * Lesser General Public License for more details.
14: *
15: * You should have received a copy of the GNU Lesser General Public
16: * License along with this library; if not, write to the Free Software
17: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18: */
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: /**
28: * @author David Hovemeyer
29: */
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: /* (non-Javadoc)
41: * @see junit.framework.TestCase#setUp()
42: */
43:
44: @Override
45: protected void setUp() throws Exception {
46: hash = new byte[] { 0x06, 0x04, (byte) 0xDE, (byte) 0xAD,
47: (byte) 0xBE, (byte) 0xEF };
48: s = "0604deadbeef";
49: sameHash = new byte[] { 0x06, 0x04, (byte) 0xDE, (byte) 0xAD,
50: (byte) 0xBE, (byte) 0xEF };
51: greaterHash = new byte[] { 0x06, 0x05, (byte) 0xDE,
52: (byte) 0xAD, (byte) 0xBE, (byte) 0xEF };
53: lesserHash = new byte[] { 0x06, 0x03, (byte) 0xDE, (byte) 0xAD,
54: (byte) 0xBE, (byte) 0xEF };
55: shorterHash = new byte[] { 0x06, 0x04, (byte) 0xDE,
56: (byte) 0xAD, (byte) 0xBE };
57: longerHash = new byte[] { 0x06, 0x04, (byte) 0xDE, (byte) 0xAD,
58: (byte) 0xBE, (byte) 0xEF, (byte) 0x01 };
59: }
60:
61: public void testHashToString() {
62: String s2 = ClassHash.hashToString(hash);
63: Assert.assertEquals(s, s2);
64: }
65:
66: public void testStringToHash() {
67: byte[] hash2 = ClassHash.stringToHash(s);
68: Assert.assertTrue(Arrays.equals(hash, hash2));
69: }
70:
71: public void testSame() {
72: Assert
73: .assertTrue(MethodHash.compareHashes(hash, sameHash) == 0);
74: Assert
75: .assertTrue(MethodHash.compareHashes(sameHash, hash) == 0);
76: }
77:
78: public void testGreater() {
79: Assert
80: .assertTrue(MethodHash.compareHashes(hash, greaterHash) < 0);
81: }
82:
83: public void testLesser() {
84: Assert
85: .assertTrue(MethodHash.compareHashes(hash, lesserHash) > 0);
86: }
87:
88: public void testShorter() {
89: Assert
90: .assertTrue(MethodHash.compareHashes(hash, shorterHash) > 0);
91: }
92:
93: public void testLonger() {
94: Assert
95: .assertTrue(MethodHash.compareHashes(hash, longerHash) < 0);
96: }
97: }
|