1 8 package test.staticfield; 9 10 import junit.framework.TestCase; 11 12 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 private int accessStaticFieldA() { 44 s_fieldA = 1; 46 int value = s_fieldA; 47 return value; 48 } 49 50 private static int accessStaticFieldB() { 51 s_fieldB = 1; 53 int value = s_fieldB; 54 return value; 55 } 56 57 private int accessFieldA() { 58 m_fieldA = 1; 60 int value = m_fieldA; 61 return value; 62 } 63 64 private static int accessFieldB(StaticFieldAdviceTest myself) { 65 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 } | Popular Tags |