KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > test > SerialVerUidTest


1 /**************************************************************************************
2  * Copyright (c) Jonas Bon?r, Alexandre Vasseur. All rights reserved. *
3  * http://aspectwerkz.codehaus.org *
4  * ---------------------------------------------------------------------------------- *
5  * The software in this package is published under the terms of the LGPL license *
6  * a copy of which has been included with this distribution in the license.txt file. *
7  **************************************************************************************/

8 package test;
9
10 import junit.framework.TestCase;
11
12 import java.io.Serializable JavaDoc;
13 import java.lang.reflect.Field JavaDoc;
14
15 import org.codehaus.aspectwerkz.transform.inlining.weaver.SerialVersionUidVisitor;
16
17 /**
18  * Test for the SerialVerionUid computation.
19  *
20  * @author <a HREF="mailto:alex@gnilux.com">Alexandre Vasseur</a>
21  */

22 public class SerialVerUidTest extends TestCase implements Serializable JavaDoc {
23     static {
24         System.gc();
25     }
26
27     public Object JavaDoc[] someMethod() {
28         return null;
29     }
30
31     protected static final int someField = 32;
32
33     public void testSerialVerUid() throws Throwable JavaDoc {
34         long UID = SerialVersionUidVisitor.calculateSerialVersionUID(SerialVerUidTest.class);
35         //System.out.println(UID);
36

37         Field f = SerialVerUidTest.class.getDeclaredField("serialVersionUID");
38         long uid = ((Long JavaDoc)f.get(null)).longValue();
39         //System.out.println(uid);
40

41         // a bit odd but..
42
try {
43             Class.forName("java.lang.annotation.Annotation");
44             assertEquals(7614081430767231713L, UID);//java 5
45
} catch (ClassNotFoundException JavaDoc e) {
46             assertEquals(-6289975506796941698L, UID);//java 1.4 (mthClass$() synthetic method)
47
}
48     }
49
50     public static void main(String JavaDoc[] args) {
51         junit.textui.TestRunner.run(suite());
52     }
53
54     public static junit.framework.Test suite() {
55         return new junit.framework.TestSuite(SerialVerUidTest.class);
56     }
57 }
58
Popular Tags