1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38 package com.gargoylesoftware.base.gui;
39
40 import com.gargoylesoftware.base.util.DetailedNullPointerException;
41 import java.awt.Component;
42 import junit.framework.TestCase;
43
44 /***
45 * Tests for DefaultComponentLoader.
46 *
47 * @version $Revision: 1.7 $
48 * @author <a href="mailto:mbowler@GargoyleSoftware.com">Mike Bowler</a>
49 */
50 public class DefaultComponentLoaderTest extends TestCase {
51
52 /***
53 * Create a new test.
54 * @param name The name of the test.
55 */
56 public DefaultComponentLoaderTest( final String name ) {
57 super(name);
58 }
59
60 /***
61 * Test constructor with valid parameters
62 * @throws ClassNotFoundException If the specified class was not found.
63 */
64 public void testStringConstructor_ValidParms() throws ClassNotFoundException {
65 new DefaultComponentLoader("java.awt.Frame");
66 }
67
68 /***
69 * Test the string constructor with a class that isn't a component.
70 * @throws Exception if something bad happens.
71 */
72 public void testStringConstuctor_NotComponent() throws Exception {
73 try {
74 new DefaultComponentLoader("java.util.Date");
75 fail("Expected exception for class that isn't a component");
76 }
77 catch( final IllegalArgumentException e ) {
78
79 }
80 }
81
82 /***
83 * Test the string constructor with the name of a class that doesn't exist.
84 * @throws Exception if something bad happens.
85 */
86 public void testStringConstuctor_BadClassName() throws Exception {
87 try {
88 new DefaultComponentLoader("java.util.Foobar");
89 fail("Expected exception for missing class");
90 }
91 catch( final ClassNotFoundException e ) {
92
93 }
94 }
95
96 /***
97 * Test the string constructor with a null class name.
98 * @throws Exception if something bad happens.
99 */
100 public void testStringConstuctor_Null() throws Exception {
101 try {
102 new DefaultComponentLoader((String)null);
103 fail("Expected exception for null string");
104 }
105 catch( final DetailedNullPointerException e ) {
106 assertEquals("clazz", e.getArgumentName());
107 }
108 }
109
110 /***
111 * Test the class constructor with a null class.
112 * @throws Exception if something bad happens.
113 */
114 public void testClassConstuctor_Null() throws Exception {
115 try {
116 new DefaultComponentLoader((Class)null);
117 fail("Expected exception for null class");
118 }
119 catch( final DetailedNullPointerException e ) {
120 assertEquals("clazz", e.getArgumentName());
121 }
122 }
123
124 /***
125 * Test the class constructor with a class that doesn't have a default constructor.
126 * @throws Exception if something bad happens.
127 */
128 public void testClassConstuctor_NoDefaultConstructor() throws Exception {
129 /*** A fake component for testing */
130 class FakeComponent extends Component {
131 private static final long serialVersionUID = 1L;
132
133 /*** @param a Some parameter that is ignored for the test */
134 public FakeComponent(int a) {
135 }
136 }
137 try {
138 new DefaultComponentLoader( FakeComponent.class );
139 fail("Expected exception for class with no default constructor");
140 }
141 catch( final IllegalArgumentException e ) {
142
143 }
144 }
145
146 /***
147 * Test the class constructor with a class that has a private constructor.
148 * @throws Exception if something bad happens.
149 */
150 public void testClassConstuctor_PrivateDefaultConstructor() throws Exception {
151 /*** A fake component for testing */
152 class FakeComponent extends Component {
153 private static final long serialVersionUID = 1L;
154
155 private FakeComponent() {
156 }
157 }
158 try {
159 new DefaultComponentLoader( FakeComponent.class );
160 fail("Expected exception for class with private default constructor");
161 }
162 catch( final IllegalArgumentException e ) {
163
164 }
165 }
166 }
167