KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > alt > jiapi > reflect > SignatureTest


1 /*
2  * Copyright(C) 2002 Mika Riekkinen, Joni Suominen
3  *
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Lesser General Public
6  * License as published by the Free Software Foundation; either
7  * version 2.1 of the License, or(at your option) any later version.
8  *
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12  * Lesser General Public License for more details.
13  *
14  * You should have received a copy of the GNU Lesser General Public
15  * License along with this library; if not, write to the Free Software
16  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17  */

18
19 package alt.jiapi.reflect;
20
21 import junit.framework.TestCase;
22
23 /**
24  * @author Mika Riekkinen
25  * @author Joni Suominen
26  * @version $Revision: 1.2 $ $Date: 2004/03/29 10:10:24 $
27  */

28 public class SignatureTest extends TestCase {
29     public SignatureTest(String JavaDoc name) {
30         super(name);
31     }
32
33     public String JavaDoc getName() {
34         return "SignatureTest: " + super.getName();
35     }
36
37     protected void setUp() {
38     }
39
40     public void testSignature() {
41         assertTrue("(B)V".equals(new Signature("void", new String JavaDoc[]{"byte"}).getDescriptor()));
42         assertTrue("(I)V".equals(new Signature("void", new String JavaDoc[]{"int"}).getDescriptor()));
43         assertTrue("(J)V".equals(new Signature("void", new String JavaDoc[]{"long"}).getDescriptor()));
44         assertTrue("(C)V".equals(new Signature("void", new String JavaDoc[]{"char"}).getDescriptor()));
45         assertTrue("(Z)V".equals(new Signature("void", new String JavaDoc[]{"boolean"}).getDescriptor()));
46         assertTrue("(F)V".equals(new Signature("void", new String JavaDoc[]{"float"}).getDescriptor()));
47         assertTrue("(D)V".equals(new Signature("void", new String JavaDoc[]{"double"}).getDescriptor()));
48         assertTrue("()V".equals(new Signature("void", new String JavaDoc[0]).getDescriptor()));
49         assertTrue("(Ljava/lang/Object;)V".equals(new Signature("void", new String JavaDoc[]{"java.lang.Object"}).getDescriptor()));
50
51         assertTrue("(BI)V".equals(new Signature("void", new String JavaDoc[]{"byte", "int"}).getDescriptor()));
52         assertTrue("(BLjava/lang/Object;I)V".equals(new Signature("void", new String JavaDoc[]{"byte", "java.lang.Object", "int"}).getDescriptor()));
53         assertTrue("([B[I)V".equals(new Signature("void", new String JavaDoc[]{"byte[]", "int[]"}).getDescriptor()));
54         assertTrue("([B[I)[F".equals(new Signature(" float [] ", new String JavaDoc[]{" byte [] ", " int [] "}).getDescriptor()));
55     }
56
57
58     public void testSignatureToSimpleName() {
59         assertTrue("byte".equals(SignatureUtil.toSimpleName("B")));
60         assertTrue("int".equals(SignatureUtil.toSimpleName("I")));
61         assertTrue("long".equals(SignatureUtil.toSimpleName("J")));
62         assertTrue("char".equals(SignatureUtil.toSimpleName("C")));
63         assertTrue("boolean".equals(SignatureUtil.toSimpleName("Z")));
64         assertTrue("float".equals(SignatureUtil.toSimpleName("F")));
65         assertTrue("double".equals(SignatureUtil.toSimpleName("D")));
66         assertTrue("void".equals(SignatureUtil.toSimpleName("V")));
67
68         assertTrue("java.lang.Object".equals(SignatureUtil.toSimpleName("Ljava/lang/Object;")));
69         assertTrue("byte[]".equals(SignatureUtil.toSimpleName("[B")));
70         assertTrue("byte[][]".equals(SignatureUtil.toSimpleName("[[B")));
71         assertTrue("byte[][][]".equals(SignatureUtil.toSimpleName("[[[B")));
72         assertTrue("java.lang.Object[]".equals(SignatureUtil.toSimpleName("[Ljava/lang/Object;")));
73         assertTrue("java.lang.Object[][]".equals(SignatureUtil.toSimpleName("[[Ljava/lang/Object;")));
74         assertTrue("java.lang.Object[][][]".equals(SignatureUtil.toSimpleName("[[[Ljava/lang/Object;")));
75     }
76 }
77
Popular Tags