Fix compiler warnings in Constants/ConstantsTests
This commit is contained in:
@@ -58,7 +58,7 @@ public class Constants {
|
||||
* @param clazz the class to analyze
|
||||
* @throws IllegalArgumentException if the supplied <code>clazz</code> is <code>null</code>
|
||||
*/
|
||||
public Constants(Class clazz) {
|
||||
public Constants(Class<?> clazz) {
|
||||
Assert.notNull(clazz);
|
||||
this.className = clazz.getName();
|
||||
Field[] fields = clazz.getFields();
|
||||
@@ -189,7 +189,7 @@ public class Constants {
|
||||
* @param nameSuffix suffix of the constant names to search (may be <code>null</code>)
|
||||
* @return the set of constant names
|
||||
*/
|
||||
public Set getNamesForSuffix(String nameSuffix) {
|
||||
public Set<String> getNamesForSuffix(String nameSuffix) {
|
||||
String suffixToUse = (nameSuffix != null ? nameSuffix.trim().toUpperCase(Locale.ENGLISH) : "");
|
||||
Set<String> names = new HashSet<String>();
|
||||
for (String code : this.fieldCache.keySet()) {
|
||||
|
||||
@@ -57,7 +57,7 @@ public class ConstantsTests extends TestCase {
|
||||
public void testGetNames() {
|
||||
Constants c = new Constants(A.class);
|
||||
|
||||
Set names = c.getNames("");
|
||||
Set<?> names = c.getNames("");
|
||||
assertEquals(c.getSize(), names.size());
|
||||
assertTrue(names.contains("DOG"));
|
||||
assertTrue(names.contains("CAT"));
|
||||
@@ -75,7 +75,7 @@ public class ConstantsTests extends TestCase {
|
||||
public void testGetValues() {
|
||||
Constants c = new Constants(A.class);
|
||||
|
||||
Set values = c.getValues("");
|
||||
Set<?> values = c.getValues("");
|
||||
assertEquals(7, values.size());
|
||||
assertTrue(values.contains(new Integer(0)));
|
||||
assertTrue(values.contains(new Integer(66)));
|
||||
@@ -102,7 +102,7 @@ public class ConstantsTests extends TestCase {
|
||||
try {
|
||||
Constants c = new Constants(A.class);
|
||||
|
||||
Set values = c.getValues("");
|
||||
Set<?> values = c.getValues("");
|
||||
assertEquals(7, values.size());
|
||||
assertTrue(values.contains(new Integer(0)));
|
||||
assertTrue(values.contains(new Integer(66)));
|
||||
@@ -130,12 +130,12 @@ public class ConstantsTests extends TestCase {
|
||||
public void testSuffixAccess() {
|
||||
Constants c = new Constants(A.class);
|
||||
|
||||
Set names = c.getNamesForSuffix("_PROPERTY");
|
||||
Set<?> names = c.getNamesForSuffix("_PROPERTY");
|
||||
assertEquals(2, names.size());
|
||||
assertTrue(names.contains("NO_PROPERTY"));
|
||||
assertTrue(names.contains("YES_PROPERTY"));
|
||||
|
||||
Set values = c.getValuesForSuffix("_PROPERTY");
|
||||
Set<?> values = c.getValuesForSuffix("_PROPERTY");
|
||||
assertEquals(2, values.size());
|
||||
assertTrue(values.contains(new Integer(3)));
|
||||
assertTrue(values.contains(new Integer(4)));
|
||||
@@ -210,26 +210,26 @@ public class ConstantsTests extends TestCase {
|
||||
|
||||
public void testGetValuesWithNullPrefix() throws Exception {
|
||||
Constants c = new Constants(A.class);
|
||||
Set values = c.getValues(null);
|
||||
Set<?> values = c.getValues(null);
|
||||
assertEquals("Must have returned *all* public static final values", 7, values.size());
|
||||
}
|
||||
|
||||
public void testGetValuesWithEmptyStringPrefix() throws Exception {
|
||||
Constants c = new Constants(A.class);
|
||||
Set values = c.getValues("");
|
||||
Set<Object> values = c.getValues("");
|
||||
assertEquals("Must have returned *all* public static final values", 7, values.size());
|
||||
}
|
||||
|
||||
public void testGetValuesWithWhitespacedStringPrefix() throws Exception {
|
||||
Constants c = new Constants(A.class);
|
||||
Set values = c.getValues(" ");
|
||||
Set<?> values = c.getValues(" ");
|
||||
assertEquals("Must have returned *all* public static final values", 7, values.size());
|
||||
}
|
||||
|
||||
public void testWithClassThatExposesNoConstants() throws Exception {
|
||||
Constants c = new Constants(NoConstants.class);
|
||||
assertEquals(0, c.getSize());
|
||||
final Set values = c.getValues("");
|
||||
final Set<?> values = c.getValues("");
|
||||
assertNotNull(values);
|
||||
assertEquals(0, values.size());
|
||||
}
|
||||
@@ -245,10 +245,11 @@ public class ConstantsTests extends TestCase {
|
||||
|
||||
private static final class NoConstants {
|
||||
}
|
||||
|
||||
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
private static final class A {
|
||||
|
||||
|
||||
public static final int DOG = 0;
|
||||
public static final int CAT = 66;
|
||||
public static final String S1 = "";
|
||||
|
||||
Reference in New Issue
Block a user