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