1
2
3
4
5
6
7
8 package org.codehaus.metaclass.model;
9
10 import junit.framework.TestCase;
11
12 /***
13 * @author Peter Donald
14 * @version $Revision: 1.3 $ $Date: 2003/11/28 11:14:54 $
15 */
16 public class ClassDescriptorTestCase
17 extends TestCase
18 {
19 public void testNullNamePassedToCtor()
20 throws Exception
21 {
22 try
23 {
24 new ClassDescriptor( null,
25 Attribute.EMPTY_SET,
26 Attribute.EMPTY_SET,
27 FieldDescriptor.EMPTY_SET,
28 MethodDescriptor.EMPTY_SET );
29 }
30 catch( final NullPointerException npe )
31 {
32 assertEquals( "npe.getMessage()", "name", npe.getMessage() );
33 return;
34 }
35 fail( "Expected to fail due to null name passed into Ctor" );
36 }
37
38 public void testNullFieldsPassedToCtor()
39 throws Exception
40 {
41 try
42 {
43 new ClassDescriptor( "MyClass",
44 Attribute.EMPTY_SET,
45 Attribute.EMPTY_SET,
46 null,
47 MethodDescriptor.EMPTY_SET );
48 }
49 catch( final NullPointerException npe )
50 {
51 assertEquals( "npe.getMessage()", "fields", npe.getMessage() );
52 return;
53 }
54 fail( "Expected to fail due to null fields passed into Ctor" );
55 }
56
57 public void testNullInFieldsPassedToCtor()
58 throws Exception
59 {
60 try
61 {
62 new ClassDescriptor( "MyClass",
63 Attribute.EMPTY_SET,
64 Attribute.EMPTY_SET,
65 new FieldDescriptor[]{null},
66 MethodDescriptor.EMPTY_SET );
67 }
68 catch( final NullPointerException npe )
69 {
70 assertEquals( "npe.getMessage()", "fields[0]", npe.getMessage() );
71 return;
72 }
73 fail( "Expected to fail due to null fields[0] passed into Ctor" );
74 }
75
76 public void testNullMethodsPassedToCtor()
77 throws Exception
78 {
79 try
80 {
81 new ClassDescriptor( "MyClass",
82 Attribute.EMPTY_SET,
83 Attribute.EMPTY_SET,
84 FieldDescriptor.EMPTY_SET,
85 null );
86 }
87 catch( final NullPointerException npe )
88 {
89 assertEquals( "npe.getMessage()", "methods", npe.getMessage() );
90 return;
91 }
92 fail( "Expected to fail due to null methods passed into Ctor" );
93 }
94
95 public void testNullInMethodsPassedToCtor()
96 throws Exception
97 {
98 try
99 {
100 new ClassDescriptor( "MyClass",
101 Attribute.EMPTY_SET,
102 Attribute.EMPTY_SET,
103 FieldDescriptor.EMPTY_SET,
104 new MethodDescriptor[]{null} );
105 }
106 catch( final NullPointerException npe )
107 {
108 assertEquals( "npe.getMessage()", "methods[0]", npe.getMessage() );
109 return;
110 }
111 fail( "Expected to fail due to null methods[0] passed into Ctor" );
112 }
113
114 public void testClassDescriptor()
115 throws Exception
116 {
117 final ClassDescriptor descriptor =
118 new ClassDescriptor( "X",
119 Attribute.EMPTY_SET,
120 Attribute.EMPTY_SET,
121 FieldDescriptor.EMPTY_SET,
122 MethodDescriptor.EMPTY_SET );
123 assertEquals( "name", "X", descriptor.getName() );
124 assertEquals( "fields.length", 0, descriptor.getFields().length );
125 assertEquals( "methods.length", 0, descriptor.getMethods().length );
126 }
127 }