01: /**************************************************************************************
02: * Copyright (c) Jonas Bonér, Alexandre Vasseur. All rights reserved. *
03: * http://aspectwerkz.codehaus.org *
04: * ---------------------------------------------------------------------------------- *
05: * The software in this package is published under the terms of the LGPL license *
06: * a copy of which has been included with this distribution in the license.txt file. *
07: **************************************************************************************/package test;
08:
09: import junit.framework.TestCase;
10: import org.codehaus.aspectwerkz.annotation.Mixin;
11:
12: /**
13: * @author <a href="mailto:alex AT gnilux DOT com">Alexandre Vasseur</a>
14: */
15: public class MixinTest extends TestCase {
16:
17: @AnnotatedMethod
18: public void iHaveAnnotatedMethod() {
19: }
20:
21: public void testIntroduced() {
22: assertTrue(this instanceof Counter);
23: assertEquals(1, ((Counter) this ).getCounter());
24: assertEquals(2, ((Counter) this ).getCounter());
25:
26: // we have perInstance
27: MixinTest another = new MixinTest();
28: assertEquals(1, ((Counter) another).getCounter());
29: }
30:
31: public static void main(String[] args) {
32: junit.textui.TestRunner.run(suite());
33: }
34:
35: public static junit.framework.Test suite() {
36: return new junit.framework.TestSuite(MixinTest.class);
37: }
38:
39: static interface Counter {
40: int getCounter();
41: }
42:
43: @Mixin("hasmethod(@test.MixinTest$AnnotatedMethod * test.Mixin*.*(..))")
44: public static class CounterImpl implements Counter {
45: int i = 0;
46:
47: public int getCounter() {
48: return ++i;
49: }
50: }
51:
52: public static @interface AnnotatedMethod {
53: }
54: }
|