KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > edu > umd > cs > findbugs > ba > MethodHashTest


1 /*
2  * FindBugs - Find Bugs in Java programs
3  * Copyright (C) 2005, University of Maryland
4  *
5  * This library is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Lesser General Public
7  * License as published by the Free Software Foundation; either
8  * version 2.1 of the License, or (at your option) any later version.
9  *
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 JavaDoc;
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 JavaDoc 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     //@Override
44
@Override JavaDoc
45          protected void setUp() throws Exception JavaDoc {
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 JavaDoc 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