KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > test > mixin > perjvm > IntroductionTest


1 /**************************************************************************************
2  * Copyright (c) Jonas BonŽr, Alexandre Vasseur. All rights reserved. *
3  * http://aspectwerkz.codehaus.org *
4  * ---------------------------------------------------------------------------------- *
5  * The software in this package is published under the terms of the LGPL license *
6  * a copy of which has been included with this distribution in the license.txt file. *
7  **************************************************************************************/

8 package test.mixin.perjvm;
9
10 import java.lang.reflect.Method JavaDoc;
11 import java.lang.reflect.Field JavaDoc;
12 import java.io.Serializable JavaDoc;
13
14 import junit.framework.TestCase;
15 import test.SerialVerUidTest;
16
17 /**
18  * @author <a HREF="mailto:jboner@codehaus.org">Jonas BonŽr </a>
19  * @author <a HREF="mailto:alex@gnilux.com">Alexandre Vasseur </a>
20  */

21 public class IntroductionTest extends TestCase {
22
23     public void testIntroducedComesFromInterfaces() {
24         Class JavaDoc klass = ToBeIntroduced.class.getClass();
25         try {
26             Method JavaDoc m = klass.getDeclaredMethod("NOT_IN_MIXIN_INTF", new Class JavaDoc[0]);
27             fail("should not have introduced : " + m);
28         } catch (NoSuchMethodException JavaDoc e) {
29             ;//ok
30
}
31     }
32
33     public void testSerialVer() {
34         // a field should have been added
35
try {
36             Field JavaDoc f = ToBeIntroduced.class.getDeclaredField("serialVersionUID");
37         } catch (Throwable JavaDoc t) {
38             fail(t.toString());
39         }
40     }
41
42     public void testMixinInterface() {
43         ToBeIntroduced target = new ToBeIntroduced();
44         assertTrue(target instanceof Introductions);
45     }
46
47     public void testSome() {
48         ToBeIntroduced target = new ToBeIntroduced();
49         ((Introductions)target).noArgs();
50         ToBeIntroduced target2 = new ToBeIntroduced();
51         assertEquals(2, ((Introductions)target2).intArg(2));
52
53         // only one mixin instance
54
assertEquals(1, MyImpl.s_count);
55     }
56
57     public void testParams() {
58         assertEquals("v1", MyImpl.s_params.get("p1"));
59         assertEquals("v2", MyImpl.s_params.get("p2"));
60     }
61
62     //-- junit
63
public static void main(String JavaDoc[] args) {
64         junit.textui.TestRunner.run(suite());
65     }
66
67     public static junit.framework.Test suite() {
68         return new junit.framework.TestSuite(IntroductionTest.class);
69     }
70 }
Popular Tags