KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > test > staticfield > CollectionFieldTest


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 import java.util.ArrayList JavaDoc;
13 import java.util.Collection JavaDoc;
14
15 /**
16  * Test case for AW-92 for collection field altered
17  *
18  * @author <a HREF="mailto:alex@gnilux.com">Alexandre Vasseur </a>
19  */

20 public class CollectionFieldTest extends TestCase {
21     public static String JavaDoc s_log = "";
22
23     private static Collection JavaDoc s_field = new ArrayList JavaDoc();
24
25     private Collection JavaDoc m_field = new ArrayList JavaDoc();
26
27     //-- member field --//
28
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     //-- static field --//
53
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     // -- methods for member collection field -- //
78
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 JavaDoc ref = m_field;
88         m_field = new ArrayList JavaDoc();
89     }
90
91     public static void getFieldInsideStaticContext(CollectionFieldTest myself) {
92         Collection JavaDoc ref = myself.m_field;
93         myself.m_field = new ArrayList JavaDoc();
94     }
95
96     // -- method for static member collection -- //
97
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 JavaDoc ref = s_field;
107         s_field = new ArrayList JavaDoc();
108     }
109
110     public static void getStaticFieldInsideStaticContext() {
111         Collection JavaDoc ref = s_field;
112         s_field = new ArrayList JavaDoc();
113     }
114
115     //-- check the bytecode created FYI. That's fun here. --//
116
public void showComplexUsage() {
117         int local = 0;
118         while (m_field.remove(null)) {
119             local++;
120         }
121     }
122
123     //-- junit hooks --//
124
public static void main(String JavaDoc[] 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