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;
008:
009: import junit.framework.TestCase;
010:
011: /**
012: * test "pc AND (cf OR cf2)"
013: *
014: * @author <a href="mailto:jboner@codehaus.org">Jonas BonŽr</a>
015: * @author <a href="mailto:alex@gnilux.com">Alexandre Vasseur </a>
016: */
017: public class CFlowTest extends TestCase implements Loggable {
018: private String m_logString = "";
019:
020: public CFlowTest(String name) {
021: super (name);
022: }
023:
024: public void testCallWithinCFlow() {
025: m_logString = "";
026: step1(); //will have cflow and will call step2()
027: assertEquals("step1 advice-before step2 advice-after ",
028: m_logString);
029: }
030:
031: public void testCallWithinCFlowAnonymous() {
032: m_logString = "";
033: step1Anonymous(); //will have cflow and will call step2()
034: assertEquals(
035: "step1Anonymous advice-beforeAnonymous step2Anonymous advice-afterAnonymous ",
036: m_logString);
037: }
038:
039: public void testCallWithinCFlowWithinCflow() {
040: m_logString = "";
041: step1_A(); //will have cflow and will call step1_B that will call step2_B()
042: assertEquals(
043: "step1_A step1_B advice-before2 step2_B advice-after2 ",
044: m_logString);
045: }
046:
047: public void testCallOutsideCFlow() {
048: m_logString = "";
049: step2();
050: assertEquals("step2 ", m_logString);
051: }
052:
053: public void testCallWithinCFlow_B() {
054: m_logString = "";
055: step1_B(); //will have cflow and will call step2_B() but is NOT in step1_A cflow
056: assertEquals("step1_B step2_B ", m_logString);
057: }
058:
059: public void testCallOutsideCFlowAnonymous() {
060: m_logString = "";
061: step2Anonymous();
062: assertEquals("step2Anonymous ", m_logString);
063: }
064:
065: public void testCflowOnMySelfForPrecedence() {
066: m_logString = "";
067: cflowOnMyself();
068: assertEquals("cflowOnMyself advice-cflowOnMyself ", m_logString);
069: }
070:
071: // //FIXME: see the aspect, pc is deactivated - see AW-251
072: // public void testCallWithinNotCFlow_C() {
073: // m_logString = "";
074: // step1_C(); //will have "NOT cflow" and will call step2_C
075: // assertEquals("step1_C step2_C ", m_logString);
076: // m_logString = "";
077: // step2_C(); //should be advised since not in step1_C cflow
078: // assertEquals("advice-beforeC step2_C advice-afterC ", m_logString);
079: // }
080:
081: public static void main(String[] args) {
082: junit.textui.TestRunner.run(suite());
083: }
084:
085: public static junit.framework.Test suite() {
086: return new junit.framework.TestSuite(CFlowTest.class);
087: }
088:
089: // ==== methods to test ====
090: public void log(final String wasHere) {
091: m_logString += wasHere;
092: }
093:
094: public void step1() {
095: log("step1 ");
096: step2();
097: }
098:
099: public void step1Anonymous() {
100: log("step1Anonymous ");
101: step2Anonymous();
102: }
103:
104: public void step1_B() {
105: log("step1_B ");
106: step2_B();
107: }
108:
109: public void step1_A() {
110: log("step1_A ");
111: step1_B();
112: }
113:
114: public void step2() {
115: log("step2 ");
116: }
117:
118: public void step2Anonymous() {
119: log("step2Anonymous ");
120: }
121:
122: public void step2_B() {
123: log("step2_B ");
124: }
125:
126: public void step1_C() {
127: log("step1_C ");
128: step2_C();
129: }
130:
131: public void step2_C() {
132: log("step2_C ");
133: }
134:
135: public void cflowOnMyself() {
136: log("cflowOnMyself ");
137: }
138: }
|