1 8 package test.staticfield; 9 10 import junit.framework.TestCase; 11 12 import java.util.ArrayList ; 13 import java.util.Collection ; 14 15 20 public class CollectionFieldTest extends TestCase { 21 public static String s_log = ""; 22 23 private static Collection s_field = new ArrayList (); 24 25 private Collection m_field = new ArrayList (); 26 27 public void testCollectionFieldOutsideStaticContext() { 29 s_log = ""; 30 alterFieldOutsideStaticContext(); 31 assertEquals("MyPreAdvice2 ", s_log); 32 } 33 34 public void testCollectionFieldInsideStaticContext() { 35 s_log = ""; 36 alterFieldInsideStaticContext(this); 37 assertEquals("MyPreAdvice2 ", s_log); 38 } 39 40 public void testGetCollectionFieldOusideStaticContext() { 41 s_log = ""; 42 getFieldOutsideStaticContext(); 43 assertEquals("MyPostAdvice2 MyPreAdvice2 ", s_log); 44 } 45 46 public void testGetCollectionFieldInsideStaticContext() { 47 s_log = ""; 48 getFieldInsideStaticContext(this); 49 assertEquals("MyPostAdvice2 MyPreAdvice2 ", s_log); 50 } 51 52 public void testStaticCollectionFieldOutsideStaticContext() { 54 s_log = ""; 55 alterStaticFieldOutsideStaticContext(); 56 assertEquals("MyPreAdvice1 ", s_log); 57 } 58 59 public void testStaticCollectionFieldInsideStaticContext() { 60 s_log = ""; 61 alterStaticFieldInsideStaticContext(); 62 assertEquals("MyPreAdvice1 ", s_log); 63 } 64 65 public void testGetStaticCollectionFieldInsideStaticContext() { 66 s_log = ""; 67 getStaticFieldInsideStaticContext(); 68 assertEquals("MyPostAdvice1 MyPreAdvice1 ", s_log); 69 } 70 71 public void testGetStaticCollectionFieldOutsideStaticContext() { 72 s_log = ""; 73 getStaticFieldOutsideStaticContext(); 74 assertEquals("MyPostAdvice1 MyPreAdvice1 ", s_log); 75 } 76 77 public void alterFieldOutsideStaticContext() { 79 m_field.clear(); 80 } 81 82 public static void alterFieldInsideStaticContext(CollectionFieldTest myself) { 83 myself.m_field.clear(); 84 } 85 86 public void getFieldOutsideStaticContext() { 87 Collection ref = m_field; 88 m_field = new ArrayList (); 89 } 90 91 public static void getFieldInsideStaticContext(CollectionFieldTest myself) { 92 Collection ref = myself.m_field; 93 myself.m_field = new ArrayList (); 94 } 95 96 public void alterStaticFieldOutsideStaticContext() { 98 s_field.clear(); 99 } 100 101 public static void alterStaticFieldInsideStaticContext() { 102 s_field.clear(); 103 } 104 105 public void getStaticFieldOutsideStaticContext() { 106 Collection ref = s_field; 107 s_field = new ArrayList (); 108 } 109 110 public static void getStaticFieldInsideStaticContext() { 111 Collection ref = s_field; 112 s_field = new ArrayList (); 113 } 114 115 public void showComplexUsage() { 117 int local = 0; 118 while (m_field.remove(null)) { 119 local++; 120 } 121 } 122 123 public static void main(String [] args) { 125 junit.textui.TestRunner.run(suite()); 126 } 127 128 public static junit.framework.Test suite() { 129 return new junit.framework.TestSuite(CollectionFieldTest.class); 130 } 131 } | Popular Tags |