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.constructor;
008:
009: import junit.framework.TestCase;
010:
011: /**
012: * @author <a href="mailto:jboner@codehaus.org">Jonas BonŽr </a>
013: */
014: public class ConstructorAdviceTest extends TestCase {
015: private static String s_logCall = "";
016:
017: private static String s_logExecution = "";
018:
019: public ConstructorAdviceTest() {
020: }
021:
022: public ConstructorAdviceTest(String name) {
023: super (name);
024: }
025:
026: public void testCallAroundAdvice() {
027: s_logCall = "";
028: TestAroundAdvice test = new TestAroundAdvice(1L, new Object(),
029: new String[] {});
030: assertEquals("beforeCall init afterCall ", s_logCall);
031: assertNotNull(test);
032: }
033:
034: public void testCallBeforeAdvice() {
035: s_logCall = "";
036: TestBeforeAdvice test = new TestBeforeAdvice();
037: assertEquals("preCall init ", s_logCall);
038: assertNotNull(test);
039: }
040:
041: public void testCallAfterAdvice() {
042: s_logCall = "";
043: TestAfterAdvice test = new TestAfterAdvice("test");
044: assertEquals("test postCall ", s_logCall);
045: assertNotNull(test);
046: }
047:
048: public void testCallBeforeAfterAdvice() {
049: s_logCall = "";
050: TestBeforeAfterAdvice test = new TestBeforeAfterAdvice(
051: new String[] { "test" });
052: assertEquals("preCall test postCall ", s_logCall);
053: assertNotNull(test);
054: }
055:
056: public void testCallReturnFalseType() {
057: s_logCall = "";
058: TestReturnFalseType test = null;
059: try {
060: test = new TestReturnFalseType();
061: } catch (ClassCastException e) {
062: return;
063: }
064: fail("this point should not have been reached a class cast exception should have been thrown");
065: }
066:
067: public void testExecutionAroundAdvice() {
068: s_logExecution = "";
069: TestAroundAdvice test = new TestAroundAdvice(1L, new Object(),
070: new String[] {});
071: assertEquals("beforeExecution init afterExecution ",
072: s_logExecution);
073: assertNotNull(test);
074: assertTrue(test instanceof TestAroundAdvice);
075: }
076:
077: public void testExecutionBeforeAdvice() {
078: s_logExecution = "";
079: TestBeforeAdvice test = new TestBeforeAdvice();
080: assertEquals("preExecution init ", s_logExecution);
081: assertNotNull(test);
082: assertTrue(test instanceof TestBeforeAdvice);
083: }
084:
085: public void testExecutionAfterAdvice() {
086: s_logExecution = "";
087: TestAfterAdvice test = new TestAfterAdvice("test");
088: assertEquals("init postExecution ", s_logExecution);
089: assertNotNull(test);
090: assertTrue(test instanceof TestAfterAdvice);
091: }
092:
093: public void testExecutionBeforeAfterAdvice() {
094: s_logExecution = "";
095: TestBeforeAfterAdvice test = new TestBeforeAfterAdvice(
096: new String[] { "test" });
097: assertEquals("preExecution init postExecution ", s_logExecution);
098: assertNotNull(test);
099: assertTrue(test instanceof TestBeforeAfterAdvice);
100: }
101:
102: public void testExecutionReturnFalseType() {
103: s_logExecution = "";
104: TestReturnFalseType test = null;
105: test = new TestReturnFalseType();
106: if (!test.m_updatedByAdvice) {
107: fail("should have been updated by advice");
108: }
109: }
110:
111: public static void main(String[] args) {
112: junit.textui.TestRunner.run(suite());
113: }
114:
115: public static junit.framework.Test suite() {
116: return new junit.framework.TestSuite(
117: ConstructorAdviceTest.class);
118: }
119:
120: public static void logCall(final String wasHere) {
121: s_logCall += wasHere;
122: }
123:
124: public static void logExecution(final String wasHere) {
125: s_logExecution += wasHere;
126: }
127: }
|