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.staticfield;
08:
09: import junit.framework.TestCase;
10:
11: /**
12: * Test case for AW-92 for static field
13: *
14: * @author <a href="mailto:alex@gnilux.com">Alexandre Vasseur </a>
15: */
16: public class StaticFieldAdviceTest extends TestCase {
17: public static int s_fieldA = 0;
18:
19: public static int s_fieldB = 0;
20:
21: public int m_fieldA = 0;
22:
23: public int m_fieldB = 0;
24:
25: public void testStaticFieldAccessedOutsideStaticCtx() {
26: assertEquals(1, accessStaticFieldA());
27: }
28:
29: public void testStaticFieldAccessedInsideStaticCtx() {
30: assertEquals(1, StaticFieldAdviceTest.accessStaticFieldB());
31: }
32:
33: public void testFieldAccessedOutsideStaticCtx() {
34: assertEquals(1, accessFieldA());
35: }
36:
37: public void testFieldAccessedInsideStaticCtx() {
38: assertEquals(1, StaticFieldAdviceTest.accessFieldB(this ));
39: }
40:
41: // -- methods --
42: private int accessStaticFieldA() {
43: //static field access in member method
44: s_fieldA = 1;
45: int value = s_fieldA;
46: return value;
47: }
48:
49: private static int accessStaticFieldB() {
50: //static field access in static method
51: s_fieldB = 1;
52: int value = s_fieldB;
53: return value;
54: }
55:
56: private int accessFieldA() {
57: //static field access in member method
58: m_fieldA = 1;
59: int value = m_fieldA;
60: return value;
61: }
62:
63: private static int accessFieldB(StaticFieldAdviceTest myself) {
64: //field access in static method
65: myself.m_fieldB = 1;
66: int value = myself.m_fieldB;
67: return value;
68: }
69:
70: public static void main(String[] args) {
71: junit.textui.TestRunner.run(suite());
72: }
73:
74: public static junit.framework.Test suite() {
75: return new junit.framework.TestSuite(
76: StaticFieldAdviceTest.class);
77: }
78: }
|