01: /**************************************************************************************
02: * Copyright (c) Jonas Bon?r, Alexandre Vasseur. All rights reserved. *
03: * http://aspectwerkz.codehaus.org *
04: * ---------------------------------------------------------------------------------- *
05: * The software in this package is published under the terms of the LGPL license *
06: * a copy of which has been included with this distribution in the license.txt file. *
07: **************************************************************************************/package test;
08:
09: import junit.framework.TestCase;
10:
11: import java.io.Serializable;
12: import java.lang.reflect.Field;
13:
14: import org.codehaus.aspectwerkz.transform.inlining.weaver.SerialVersionUidVisitor;
15:
16: /**
17: * Test for the SerialVerionUid computation.
18: *
19: * @author <a href="mailto:alex@gnilux.com">Alexandre Vasseur</a>
20: */
21: public class SerialVerUidTest extends TestCase implements Serializable {
22: static {
23: System.gc();
24: }
25:
26: public Object[] someMethod() {
27: return null;
28: }
29:
30: protected static final int someField = 32;
31:
32: public void testSerialVerUid() throws Throwable {
33: long UID = SerialVersionUidVisitor
34: .calculateSerialVersionUID(SerialVerUidTest.class);
35: //System.out.println(UID);
36:
37: Field f = SerialVerUidTest.class
38: .getDeclaredField("serialVersionUID");
39: long uid = ((Long) f.get(null)).longValue();
40: //System.out.println(uid);
41:
42: // a bit odd but..
43: try {
44: Class.forName("java.lang.annotation.Annotation");
45: assertEquals(7614081430767231713L, UID);//java 5
46: } catch (ClassNotFoundException e) {
47: assertEquals(-6289975506796941698L, UID);//java 1.4 (mthClass$() synthetic method)
48: }
49: }
50:
51: public static void main(String[] args) {
52: junit.textui.TestRunner.run(suite());
53: }
54:
55: public static junit.framework.Test suite() {
56: return new junit.framework.TestSuite(SerialVerUidTest.class);
57: }
58: }
|