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.mixin.perjvm;
08:
09: import java.lang.reflect.Method;
10: import java.lang.reflect.Field;
11: import java.io.Serializable;
12:
13: import junit.framework.TestCase;
14: import test.SerialVerUidTest;
15:
16: /**
17: * @author <a href="mailto:jboner@codehaus.org">Jonas BonŽr </a>
18: * @author <a href="mailto:alex@gnilux.com">Alexandre Vasseur </a>
19: */
20: public class IntroductionTest extends TestCase {
21:
22: public void testIntroducedComesFromInterfaces() {
23: Class klass = ToBeIntroduced.class.getClass();
24: try {
25: Method m = klass.getDeclaredMethod("NOT_IN_MIXIN_INTF",
26: new Class[0]);
27: fail("should not have introduced : " + m);
28: } catch (NoSuchMethodException e) {
29: ;//ok
30: }
31: }
32:
33: public void testSerialVer() {
34: // a field should have been added
35: try {
36: Field f = ToBeIntroduced.class
37: .getDeclaredField("serialVersionUID");
38: } catch (Throwable t) {
39: fail(t.toString());
40: }
41: }
42:
43: public void testMixinInterface() {
44: ToBeIntroduced target = new ToBeIntroduced();
45: assertTrue(target instanceof Introductions);
46: }
47:
48: public void testSome() {
49: ToBeIntroduced target = new ToBeIntroduced();
50: ((Introductions) target).noArgs();
51: ToBeIntroduced target2 = new ToBeIntroduced();
52: assertEquals(2, ((Introductions) target2).intArg(2));
53:
54: // only one mixin instance
55: assertEquals(1, MyImpl.s_count);
56: }
57:
58: public void testParams() {
59: assertEquals("v1", MyImpl.s_params.get("p1"));
60: assertEquals("v2", MyImpl.s_params.get("p2"));
61: }
62:
63: //-- junit
64: public static void main(String[] args) {
65: junit.textui.TestRunner.run(suite());
66: }
67:
68: public static junit.framework.Test suite() {
69: return new junit.framework.TestSuite(IntroductionTest.class);
70: }
71: }
|