1
1
/*
2
- * Copyright 2002-2007 the original author or authors.
2
+ * Copyright 2002-2012 the original author or authors.
3
3
*
4
4
* Licensed under the Apache License, Version 2.0 (the "License");
5
5
* you may not use this file except in compliance with the License.
@@ -57,7 +57,7 @@ public void testConstants() {
57
57
public void testGetNames () {
58
58
Constants c = new Constants (A .class );
59
59
60
- Set names = c .getNames ("" );
60
+ Set <?> names = c .getNames ("" );
61
61
assertEquals (c .getSize (), names .size ());
62
62
assertTrue (names .contains ("DOG" ));
63
63
assertTrue (names .contains ("CAT" ));
@@ -75,7 +75,7 @@ public void testGetNames() {
75
75
public void testGetValues () {
76
76
Constants c = new Constants (A .class );
77
77
78
- Set values = c .getValues ("" );
78
+ Set <?> values = c .getValues ("" );
79
79
assertEquals (7 , values .size ());
80
80
assertTrue (values .contains (new Integer (0 )));
81
81
assertTrue (values .contains (new Integer (66 )));
@@ -102,7 +102,7 @@ public void testGetValuesInTurkey() {
102
102
try {
103
103
Constants c = new Constants (A .class );
104
104
105
- Set values = c .getValues ("" );
105
+ Set <?> values = c .getValues ("" );
106
106
assertEquals (7 , values .size ());
107
107
assertTrue (values .contains (new Integer (0 )));
108
108
assertTrue (values .contains (new Integer (66 )));
@@ -130,12 +130,12 @@ public void testGetValuesInTurkey() {
130
130
public void testSuffixAccess () {
131
131
Constants c = new Constants (A .class );
132
132
133
- Set names = c .getNamesForSuffix ("_PROPERTY" );
133
+ Set <?> names = c .getNamesForSuffix ("_PROPERTY" );
134
134
assertEquals (2 , names .size ());
135
135
assertTrue (names .contains ("NO_PROPERTY" ));
136
136
assertTrue (names .contains ("YES_PROPERTY" ));
137
137
138
- Set values = c .getValuesForSuffix ("_PROPERTY" );
138
+ Set <?> values = c .getValuesForSuffix ("_PROPERTY" );
139
139
assertEquals (2 , values .size ());
140
140
assertTrue (values .contains (new Integer (3 )));
141
141
assertTrue (values .contains (new Integer (4 )));
@@ -148,19 +148,28 @@ public void testToCode() {
148
148
assertEquals (c .toCode (new Integer (0 ), "D" ), "DOG" );
149
149
assertEquals (c .toCode (new Integer (0 ), "DO" ), "DOG" );
150
150
assertEquals (c .toCode (new Integer (0 ), "DoG" ), "DOG" );
151
+ assertEquals (c .toCode (new Integer (0 ), null ), "DOG" );
151
152
assertEquals (c .toCode (new Integer (66 ), "" ), "CAT" );
152
153
assertEquals (c .toCode (new Integer (66 ), "C" ), "CAT" );
153
154
assertEquals (c .toCode (new Integer (66 ), "ca" ), "CAT" );
154
155
assertEquals (c .toCode (new Integer (66 ), "cAt" ), "CAT" );
156
+ assertEquals (c .toCode (new Integer (66 ), null ), "CAT" );
155
157
assertEquals (c .toCode ("" , "" ), "S1" );
156
158
assertEquals (c .toCode ("" , "s" ), "S1" );
157
159
assertEquals (c .toCode ("" , "s1" ), "S1" );
160
+ assertEquals (c .toCode ("" , null ), "S1" );
158
161
try {
159
162
c .toCode ("bogus" , "bogus" );
160
163
fail ("Should have thrown ConstantException" );
161
164
}
162
165
catch (ConstantException expected ) {
163
166
}
167
+ try {
168
+ c .toCode ("bogus" , null );
169
+ fail ("Should have thrown ConstantException" );
170
+ }
171
+ catch (ConstantException expected ) {
172
+ }
164
173
165
174
assertEquals (c .toCodeForProperty (new Integer (1 ), "myProperty" ), "MY_PROPERTY_NO" );
166
175
assertEquals (c .toCodeForProperty (new Integer (2 ), "myProperty" ), "MY_PROPERTY_YES" );
@@ -175,43 +184,52 @@ public void testToCode() {
175
184
assertEquals (c .toCodeForSuffix (new Integer (0 ), "G" ), "DOG" );
176
185
assertEquals (c .toCodeForSuffix (new Integer (0 ), "OG" ), "DOG" );
177
186
assertEquals (c .toCodeForSuffix (new Integer (0 ), "DoG" ), "DOG" );
187
+ assertEquals (c .toCodeForSuffix (new Integer (0 ), null ), "DOG" );
178
188
assertEquals (c .toCodeForSuffix (new Integer (66 ), "" ), "CAT" );
179
189
assertEquals (c .toCodeForSuffix (new Integer (66 ), "T" ), "CAT" );
180
190
assertEquals (c .toCodeForSuffix (new Integer (66 ), "at" ), "CAT" );
181
191
assertEquals (c .toCodeForSuffix (new Integer (66 ), "cAt" ), "CAT" );
192
+ assertEquals (c .toCodeForSuffix (new Integer (66 ), null ), "CAT" );
182
193
assertEquals (c .toCodeForSuffix ("" , "" ), "S1" );
183
194
assertEquals (c .toCodeForSuffix ("" , "1" ), "S1" );
184
195
assertEquals (c .toCodeForSuffix ("" , "s1" ), "S1" );
196
+ assertEquals (c .toCodeForSuffix ("" , null ), "S1" );
185
197
try {
186
198
c .toCodeForSuffix ("bogus" , "bogus" );
187
199
fail ("Should have thrown ConstantException" );
188
200
}
189
201
catch (ConstantException expected ) {
190
202
}
203
+ try {
204
+ c .toCodeForSuffix ("bogus" , null );
205
+ fail ("Should have thrown ConstantException" );
206
+ }
207
+ catch (ConstantException expected ) {
208
+ }
191
209
}
192
210
193
211
public void testGetValuesWithNullPrefix () throws Exception {
194
212
Constants c = new Constants (A .class );
195
- Set values = c .getValues (null );
213
+ Set <?> values = c .getValues (null );
196
214
assertEquals ("Must have returned *all* public static final values" , 7 , values .size ());
197
215
}
198
216
199
217
public void testGetValuesWithEmptyStringPrefix () throws Exception {
200
218
Constants c = new Constants (A .class );
201
- Set values = c .getValues ("" );
219
+ Set < Object > values = c .getValues ("" );
202
220
assertEquals ("Must have returned *all* public static final values" , 7 , values .size ());
203
221
}
204
222
205
223
public void testGetValuesWithWhitespacedStringPrefix () throws Exception {
206
224
Constants c = new Constants (A .class );
207
- Set values = c .getValues (" " );
225
+ Set <?> values = c .getValues (" " );
208
226
assertEquals ("Must have returned *all* public static final values" , 7 , values .size ());
209
227
}
210
228
211
229
public void testWithClassThatExposesNoConstants () throws Exception {
212
230
Constants c = new Constants (NoConstants .class );
213
231
assertEquals (0 , c .getSize ());
214
- final Set values = c .getValues ("" );
232
+ final Set <?> values = c .getValues ("" );
215
233
assertNotNull (values );
216
234
assertEquals (0 , values .size ());
217
235
}
@@ -227,10 +245,11 @@ public void testCtorWithNullClass() throws Exception {
227
245
228
246
private static final class NoConstants {
229
247
}
230
-
231
248
249
+
250
+ @ SuppressWarnings ("unused" )
232
251
private static final class A {
233
-
252
+
234
253
public static final int DOG = 0 ;
235
254
public static final int CAT = 66 ;
236
255
public static final String S1 = "" ;
0 commit comments