001: /**************************************************************************************
002: * Copyright (c) Jonas BonŽr, Alexandre Vasseur. All rights reserved. *
003: * http://aspectwerkz.codehaus.org *
004: * ---------------------------------------------------------------------------------- *
005: * The software in this package is published under the terms of the LGPL license *
006: * a copy of which has been included with this distribution in the license.txt file. *
007: **************************************************************************************/package test.staticfield;
008:
009: import junit.framework.TestCase;
010:
011: import java.util.ArrayList;
012: import java.util.Collection;
013:
014: /**
015: * Test case for AW-92 for collection field altered
016: *
017: * @author <a href="mailto:alex@gnilux.com">Alexandre Vasseur </a>
018: */
019: public class CollectionFieldTest extends TestCase {
020: public static String s_log = "";
021:
022: private static Collection s_field = new ArrayList();
023:
024: private Collection m_field = new ArrayList();
025:
026: //-- member field --//
027: public void testCollectionFieldOutsideStaticContext() {
028: s_log = "";
029: alterFieldOutsideStaticContext();
030: assertEquals("MyPreAdvice2 ", s_log);
031: }
032:
033: public void testCollectionFieldInsideStaticContext() {
034: s_log = "";
035: alterFieldInsideStaticContext(this );
036: assertEquals("MyPreAdvice2 ", s_log);
037: }
038:
039: public void testGetCollectionFieldOusideStaticContext() {
040: s_log = "";
041: getFieldOutsideStaticContext();
042: assertEquals("MyPostAdvice2 MyPreAdvice2 ", s_log);
043: }
044:
045: public void testGetCollectionFieldInsideStaticContext() {
046: s_log = "";
047: getFieldInsideStaticContext(this );
048: assertEquals("MyPostAdvice2 MyPreAdvice2 ", s_log);
049: }
050:
051: //-- static field --//
052: public void testStaticCollectionFieldOutsideStaticContext() {
053: s_log = "";
054: alterStaticFieldOutsideStaticContext();
055: assertEquals("MyPreAdvice1 ", s_log);
056: }
057:
058: public void testStaticCollectionFieldInsideStaticContext() {
059: s_log = "";
060: alterStaticFieldInsideStaticContext();
061: assertEquals("MyPreAdvice1 ", s_log);
062: }
063:
064: public void testGetStaticCollectionFieldInsideStaticContext() {
065: s_log = "";
066: getStaticFieldInsideStaticContext();
067: assertEquals("MyPostAdvice1 MyPreAdvice1 ", s_log);
068: }
069:
070: public void testGetStaticCollectionFieldOutsideStaticContext() {
071: s_log = "";
072: getStaticFieldOutsideStaticContext();
073: assertEquals("MyPostAdvice1 MyPreAdvice1 ", s_log);
074: }
075:
076: // -- methods for member collection field -- //
077: public void alterFieldOutsideStaticContext() {
078: m_field.clear();
079: }
080:
081: public static void alterFieldInsideStaticContext(
082: CollectionFieldTest myself) {
083: myself.m_field.clear();
084: }
085:
086: public void getFieldOutsideStaticContext() {
087: Collection ref = m_field;
088: m_field = new ArrayList();
089: }
090:
091: public static void getFieldInsideStaticContext(
092: CollectionFieldTest myself) {
093: Collection ref = myself.m_field;
094: myself.m_field = new ArrayList();
095: }
096:
097: // -- method for static member collection -- //
098: public void alterStaticFieldOutsideStaticContext() {
099: s_field.clear();
100: }
101:
102: public static void alterStaticFieldInsideStaticContext() {
103: s_field.clear();
104: }
105:
106: public void getStaticFieldOutsideStaticContext() {
107: Collection ref = s_field;
108: s_field = new ArrayList();
109: }
110:
111: public static void getStaticFieldInsideStaticContext() {
112: Collection ref = s_field;
113: s_field = new ArrayList();
114: }
115:
116: //-- check the bytecode created FYI. That's fun here. --//
117: public void showComplexUsage() {
118: int local = 0;
119: while (m_field.remove(null)) {
120: local++;
121: }
122: }
123:
124: //-- junit hooks --//
125: public static void main(String[] args) {
126: junit.textui.TestRunner.run(suite());
127: }
128:
129: public static junit.framework.Test suite() {
130: return new junit.framework.TestSuite(CollectionFieldTest.class);
131: }
132: }
|