Fix [rawtypes] compiler warnings
- Suppress rawtypes warnings for src/main - Enable rawtypes warnings for src/test This commit attempts to to resolve all rawtypes problems across tests as aggressively as possible, i.e. without regard for binary compatibility, whereas main sources must be treated much more cautiously with an eye toward compatibility.
This commit is contained in:
@@ -41,15 +41,15 @@ public class ConventionsTests extends TestCase {
|
||||
}
|
||||
|
||||
public void testCollections() {
|
||||
List list = new ArrayList();
|
||||
List<TestBean> list = new ArrayList<TestBean>();
|
||||
list.add(new TestBean());
|
||||
assertEquals("Incorrect plural List form", "testBeanList", Conventions.getVariableName(list));
|
||||
|
||||
Set set = new HashSet();
|
||||
Set<TestBean> set = new HashSet<TestBean>();
|
||||
set.add(new TestBean());
|
||||
assertEquals("Incorrect plural Set form", "testBeanList", Conventions.getVariableName(set));
|
||||
|
||||
List emptyList = new ArrayList();
|
||||
List<?> emptyList = new ArrayList<Object>();
|
||||
try {
|
||||
Conventions.getVariableName(emptyList);
|
||||
fail("Should not be able to generate name for empty collection");
|
||||
@@ -67,7 +67,7 @@ public class ConventionsTests extends TestCase {
|
||||
|
||||
public void testGetQualifiedAttributeName() throws Exception {
|
||||
String baseName = "foo";
|
||||
Class cls = String.class;
|
||||
Class<String> cls = String.class;
|
||||
String desiredResult = "java.lang.String.foo";
|
||||
assertEquals(desiredResult, Conventions.getQualifiedAttributeName(cls, baseName));
|
||||
}
|
||||
|
||||
@@ -50,14 +50,14 @@ public class LocalVariableTableParameterNameDiscovererTests extends TestCase {
|
||||
}
|
||||
|
||||
public void testConsParameterNameDiscoveryNoArgs() throws NoSuchMethodException {
|
||||
Constructor noArgsCons = TestBean.class.getConstructor(new Class[0]);
|
||||
Constructor<TestBean> noArgsCons = TestBean.class.getConstructor(new Class[0]);
|
||||
String[] names = discoverer.getParameterNames(noArgsCons);
|
||||
assertNotNull("should find cons info", names);
|
||||
assertEquals("no argument names", 0, names.length);
|
||||
}
|
||||
|
||||
public void testConsParameterNameDiscoveryArgs() throws NoSuchMethodException {
|
||||
Constructor twoArgCons = TestBean.class.getConstructor(new Class[] { String.class, int.class });
|
||||
Constructor<TestBean> twoArgCons = TestBean.class.getConstructor(new Class[] { String.class, int.class });
|
||||
String[] names = discoverer.getParameterNames(twoArgCons);
|
||||
assertNotNull("should find cons info", names);
|
||||
assertEquals("one argument", 2, names.length);
|
||||
@@ -73,7 +73,7 @@ public class LocalVariableTableParameterNameDiscovererTests extends TestCase {
|
||||
}
|
||||
|
||||
public void testOverloadedStaticMethod() throws Exception {
|
||||
Class clazz = this.getClass();
|
||||
Class<? extends LocalVariableTableParameterNameDiscovererTests> clazz = this.getClass();
|
||||
|
||||
Method m1 = clazz.getMethod("staticMethod", new Class[] { Long.TYPE, Long.TYPE });
|
||||
String[] names = discoverer.getParameterNames(m1);
|
||||
@@ -92,7 +92,7 @@ public class LocalVariableTableParameterNameDiscovererTests extends TestCase {
|
||||
}
|
||||
|
||||
public void testOverloadedStaticMethodInInnerClass() throws Exception {
|
||||
Class clazz = InnerClass.class;
|
||||
Class<InnerClass> clazz = InnerClass.class;
|
||||
|
||||
Method m1 = clazz.getMethod("staticMethod", new Class[] { Long.TYPE });
|
||||
String[] names = discoverer.getParameterNames(m1);
|
||||
@@ -109,7 +109,7 @@ public class LocalVariableTableParameterNameDiscovererTests extends TestCase {
|
||||
}
|
||||
|
||||
public void testOverloadedMethod() throws Exception {
|
||||
Class clazz = this.getClass();
|
||||
Class<? extends LocalVariableTableParameterNameDiscovererTests> clazz = this.getClass();
|
||||
|
||||
Method m1 = clazz.getMethod("instanceMethod", new Class[] { Double.TYPE, Double.TYPE });
|
||||
String[] names = discoverer.getParameterNames(m1);
|
||||
@@ -128,7 +128,7 @@ public class LocalVariableTableParameterNameDiscovererTests extends TestCase {
|
||||
}
|
||||
|
||||
public void testOverloadedMethodInInnerClass() throws Exception {
|
||||
Class clazz = InnerClass.class;
|
||||
Class<InnerClass> clazz = InnerClass.class;
|
||||
|
||||
Method m1 = clazz.getMethod("instanceMethod", new Class[] { String.class });
|
||||
String[] names = discoverer.getParameterNames(m1);
|
||||
@@ -145,9 +145,9 @@ public class LocalVariableTableParameterNameDiscovererTests extends TestCase {
|
||||
}
|
||||
|
||||
public void testGenerifiedClass() throws Exception {
|
||||
Class clazz = GenerifiedClass.class;
|
||||
Class<?> clazz = (Class<?>)GenerifiedClass.class;
|
||||
|
||||
Constructor ctor = clazz.getDeclaredConstructor(Object.class);
|
||||
Constructor<?> ctor = clazz.getDeclaredConstructor(Object.class);
|
||||
String[] names = discoverer.getParameterNames(ctor);
|
||||
assertEquals(1, names.length);
|
||||
assertEquals("key", names[0]);
|
||||
@@ -199,7 +199,7 @@ public class LocalVariableTableParameterNameDiscovererTests extends TestCase {
|
||||
@Ignore
|
||||
public void ignore_testClassesWithoutDebugSymbols() throws Exception {
|
||||
// JDK classes don't have debug information (usually)
|
||||
Class clazz = Component.class;
|
||||
Class<Component> clazz = Component.class;
|
||||
String methodName = "list";
|
||||
|
||||
Method m = clazz.getMethod(methodName);
|
||||
@@ -275,9 +275,6 @@ public class LocalVariableTableParameterNameDiscovererTests extends TestCase {
|
||||
public static class GenerifiedClass<K, V> {
|
||||
private static long date;
|
||||
|
||||
private K key;
|
||||
private V value;
|
||||
|
||||
static {
|
||||
// some custom static bloc or <clinit>
|
||||
date = new Date().getTime();
|
||||
@@ -292,8 +289,6 @@ public class LocalVariableTableParameterNameDiscovererTests extends TestCase {
|
||||
}
|
||||
|
||||
public GenerifiedClass(K key, V value) {
|
||||
this.key = key;
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
public static <P> long generifiedStaticMethod(P param) {
|
||||
|
||||
@@ -38,7 +38,7 @@ public class AssertTests {
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void instanceOf() {
|
||||
final Set set = new HashSet();
|
||||
final Set<?> set = new HashSet<Object>();
|
||||
Assert.isInstanceOf(HashSet.class, set);
|
||||
Assert.isInstanceOf(HashMap.class, set);
|
||||
}
|
||||
@@ -105,12 +105,12 @@ public class AssertTests {
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void assertNotEmptyWithNullCollectionThrowsException() throws Exception {
|
||||
Assert.notEmpty((Collection) null);
|
||||
Assert.notEmpty((Collection<?>) null);
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void assertNotEmptyWithEmptyCollectionThrowsException() throws Exception {
|
||||
Assert.notEmpty(new ArrayList());
|
||||
Assert.notEmpty(new ArrayList<Object>());
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -122,12 +122,12 @@ public class AssertTests {
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void assertNotEmptyWithNullMapThrowsException() throws Exception {
|
||||
Assert.notEmpty((Map) null);
|
||||
Assert.notEmpty((Map<?, ?>) null);
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void assertNotEmptyWithEmptyMapThrowsException() throws Exception {
|
||||
Assert.notEmpty(new HashMap());
|
||||
Assert.notEmpty(new HashMap<Object, Object>());
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -30,22 +30,22 @@ import org.springframework.beans.TestBean;
|
||||
public class AutoPopulatingListTests extends TestCase {
|
||||
|
||||
public void testWithClass() throws Exception {
|
||||
doTestWithClass(new AutoPopulatingList(TestBean.class));
|
||||
doTestWithClass(new AutoPopulatingList<Object>(TestBean.class));
|
||||
}
|
||||
|
||||
public void testWithClassAndUserSuppliedBackingList() throws Exception {
|
||||
doTestWithClass(new AutoPopulatingList(new LinkedList(), TestBean.class));
|
||||
doTestWithClass(new AutoPopulatingList<Object>(new LinkedList<Object>(), TestBean.class));
|
||||
}
|
||||
|
||||
public void testWithElementFactory() throws Exception {
|
||||
doTestWithElementFactory(new AutoPopulatingList(new MockElementFactory()));
|
||||
doTestWithElementFactory(new AutoPopulatingList<Object>(new MockElementFactory()));
|
||||
}
|
||||
|
||||
public void testWithElementFactoryAndUserSuppliedBackingList() throws Exception {
|
||||
doTestWithElementFactory(new AutoPopulatingList(new LinkedList(), new MockElementFactory()));
|
||||
doTestWithElementFactory(new AutoPopulatingList<Object>(new LinkedList<Object>(), new MockElementFactory()));
|
||||
}
|
||||
|
||||
private void doTestWithClass(AutoPopulatingList list) {
|
||||
private void doTestWithClass(AutoPopulatingList<Object> list) {
|
||||
Object lastElement = null;
|
||||
for (int x = 0; x < 10; x++) {
|
||||
Object element = list.get(x);
|
||||
@@ -66,7 +66,7 @@ public class AutoPopulatingListTests extends TestCase {
|
||||
assertTrue(list.get(20) instanceof TestBean);
|
||||
}
|
||||
|
||||
private void doTestWithElementFactory(AutoPopulatingList list) {
|
||||
private void doTestWithElementFactory(AutoPopulatingList<Object> list) {
|
||||
doTestWithClass(list);
|
||||
|
||||
for(int x = 0; x < list.size(); x++) {
|
||||
@@ -78,7 +78,7 @@ public class AutoPopulatingListTests extends TestCase {
|
||||
}
|
||||
|
||||
public void testSerialization() throws Exception {
|
||||
AutoPopulatingList list = new AutoPopulatingList(TestBean.class);
|
||||
AutoPopulatingList<?> list = new AutoPopulatingList<Object>(TestBean.class);
|
||||
Assert.assertEquals(list, SerializationTestUtils.serializeAndDeserialize(list));
|
||||
}
|
||||
|
||||
|
||||
@@ -40,16 +40,16 @@ public class CollectionUtilsTests {
|
||||
|
||||
@Test
|
||||
public void testIsEmpty() {
|
||||
assertTrue(CollectionUtils.isEmpty((Set) null));
|
||||
assertTrue(CollectionUtils.isEmpty((Map) null));
|
||||
assertTrue(CollectionUtils.isEmpty(new HashMap()));
|
||||
assertTrue(CollectionUtils.isEmpty(new HashSet()));
|
||||
assertTrue(CollectionUtils.isEmpty((Set<Object>) null));
|
||||
assertTrue(CollectionUtils.isEmpty((Map<String, String>) null));
|
||||
assertTrue(CollectionUtils.isEmpty(new HashMap<String, String>()));
|
||||
assertTrue(CollectionUtils.isEmpty(new HashSet<Object>()));
|
||||
|
||||
List list = new LinkedList();
|
||||
List<Object> list = new LinkedList<Object>();
|
||||
list.add(new Object());
|
||||
assertFalse(CollectionUtils.isEmpty(list));
|
||||
|
||||
Map map = new HashMap();
|
||||
Map<String, String> map = new HashMap<String, String>();
|
||||
map.put("foo", "bar");
|
||||
assertFalse(CollectionUtils.isEmpty(map));
|
||||
}
|
||||
@@ -57,7 +57,7 @@ public class CollectionUtilsTests {
|
||||
@Test
|
||||
public void testMergeArrayIntoCollection() {
|
||||
Object[] arr = new Object[] {"value1", "value2"};
|
||||
List list = new LinkedList();
|
||||
List<Comparable<?>> list = new LinkedList<Comparable<?>>();
|
||||
list.add("value3");
|
||||
|
||||
CollectionUtils.mergeArrayIntoCollection(arr, list);
|
||||
@@ -69,7 +69,7 @@ public class CollectionUtilsTests {
|
||||
@Test
|
||||
public void testMergePrimitiveArrayIntoCollection() {
|
||||
int[] arr = new int[] {1, 2};
|
||||
List list = new LinkedList();
|
||||
List<Comparable<?>> list = new LinkedList<Comparable<?>>();
|
||||
list.add(new Integer(3));
|
||||
|
||||
CollectionUtils.mergeArrayIntoCollection(arr, list);
|
||||
@@ -86,7 +86,7 @@ public class CollectionUtilsTests {
|
||||
props.setProperty("prop2", "value2");
|
||||
props.put("prop3", new Integer(3));
|
||||
|
||||
Map map = new HashMap();
|
||||
Map<String, String> map = new HashMap<String, String>();
|
||||
map.put("prop4", "value4");
|
||||
|
||||
CollectionUtils.mergePropertiesIntoMap(props, map);
|
||||
@@ -98,28 +98,28 @@ public class CollectionUtilsTests {
|
||||
|
||||
@Test
|
||||
public void testContains() {
|
||||
assertFalse(CollectionUtils.contains((Iterator) null, "myElement"));
|
||||
assertFalse(CollectionUtils.contains((Enumeration) null, "myElement"));
|
||||
assertFalse(CollectionUtils.contains(new LinkedList().iterator(), "myElement"));
|
||||
assertFalse(CollectionUtils.contains(new Hashtable().keys(), "myElement"));
|
||||
assertFalse(CollectionUtils.contains((Iterator<String>) null, "myElement"));
|
||||
assertFalse(CollectionUtils.contains((Enumeration<String>) null, "myElement"));
|
||||
assertFalse(CollectionUtils.contains(new LinkedList<String>().iterator(), "myElement"));
|
||||
assertFalse(CollectionUtils.contains(new Hashtable<String, Object>().keys(), "myElement"));
|
||||
|
||||
List list = new LinkedList();
|
||||
List<String> list = new LinkedList<String>();
|
||||
list.add("myElement");
|
||||
assertTrue(CollectionUtils.contains(list.iterator(), "myElement"));
|
||||
|
||||
Hashtable ht = new Hashtable();
|
||||
Hashtable<String, String> ht = new Hashtable<String, String>();
|
||||
ht.put("myElement", "myValue");
|
||||
assertTrue(CollectionUtils.contains(ht.keys(), "myElement"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testContainsAny() throws Exception {
|
||||
List source = new ArrayList();
|
||||
List<String> source = new ArrayList<String>();
|
||||
source.add("abc");
|
||||
source.add("def");
|
||||
source.add("ghi");
|
||||
|
||||
List candidates = new ArrayList();
|
||||
List<String> candidates = new ArrayList<String>();
|
||||
candidates.add("xyz");
|
||||
candidates.add("def");
|
||||
candidates.add("abc");
|
||||
@@ -139,7 +139,7 @@ public class CollectionUtilsTests {
|
||||
|
||||
@Test
|
||||
public void testContainsInstanceWithInstancesThatAreEqualButDistinct() throws Exception {
|
||||
List list = new ArrayList();
|
||||
List<Instance> list = new ArrayList<Instance>();
|
||||
list.add(new Instance("fiona"));
|
||||
assertFalse("Must return false if instance is not in the supplied Collection argument",
|
||||
CollectionUtils.containsInstance(list, new Instance("fiona")));
|
||||
@@ -147,7 +147,7 @@ public class CollectionUtilsTests {
|
||||
|
||||
@Test
|
||||
public void testContainsInstanceWithSameInstance() throws Exception {
|
||||
List list = new ArrayList();
|
||||
List<Instance> list = new ArrayList<Instance>();
|
||||
list.add(new Instance("apple"));
|
||||
Instance instance = new Instance("fiona");
|
||||
list.add(instance);
|
||||
@@ -157,7 +157,7 @@ public class CollectionUtilsTests {
|
||||
|
||||
@Test
|
||||
public void testContainsInstanceWithNullInstance() throws Exception {
|
||||
List list = new ArrayList();
|
||||
List<Instance> list = new ArrayList<Instance>();
|
||||
list.add(new Instance("apple"));
|
||||
list.add(new Instance("fiona"));
|
||||
assertFalse("Must return false if null instance is supplied",
|
||||
@@ -166,12 +166,12 @@ public class CollectionUtilsTests {
|
||||
|
||||
@Test
|
||||
public void testFindFirstMatch() throws Exception {
|
||||
List source = new ArrayList();
|
||||
List<String> source = new ArrayList<String>();
|
||||
source.add("abc");
|
||||
source.add("def");
|
||||
source.add("ghi");
|
||||
|
||||
List candidates = new ArrayList();
|
||||
List<String> candidates = new ArrayList<String>();
|
||||
candidates.add("xyz");
|
||||
candidates.add("def");
|
||||
candidates.add("abc");
|
||||
@@ -181,35 +181,35 @@ public class CollectionUtilsTests {
|
||||
|
||||
@Test
|
||||
public void testHasUniqueObject() {
|
||||
List list = new LinkedList();
|
||||
List<String> list = new LinkedList<String>();
|
||||
list.add("myElement");
|
||||
list.add("myOtherElement");
|
||||
assertFalse(CollectionUtils.hasUniqueObject(list));
|
||||
|
||||
list = new LinkedList();
|
||||
list = new LinkedList<String>();
|
||||
list.add("myElement");
|
||||
assertTrue(CollectionUtils.hasUniqueObject(list));
|
||||
|
||||
list = new LinkedList();
|
||||
list = new LinkedList<String>();
|
||||
list.add("myElement");
|
||||
list.add(null);
|
||||
assertFalse(CollectionUtils.hasUniqueObject(list));
|
||||
|
||||
list = new LinkedList();
|
||||
list = new LinkedList<String>();
|
||||
list.add(null);
|
||||
list.add("myElement");
|
||||
assertFalse(CollectionUtils.hasUniqueObject(list));
|
||||
|
||||
list = new LinkedList();
|
||||
list = new LinkedList<String>();
|
||||
list.add(null);
|
||||
list.add(null);
|
||||
assertTrue(CollectionUtils.hasUniqueObject(list));
|
||||
|
||||
list = new LinkedList();
|
||||
list = new LinkedList<String>();
|
||||
list.add(null);
|
||||
assertTrue(CollectionUtils.hasUniqueObject(list));
|
||||
|
||||
list = new LinkedList();
|
||||
list = new LinkedList<String>();
|
||||
assertFalse(CollectionUtils.hasUniqueObject(list));
|
||||
}
|
||||
|
||||
|
||||
@@ -43,14 +43,14 @@ public class MethodInvokerTests extends TestCase {
|
||||
mi = new MethodInvoker();
|
||||
mi.setTargetClass(TestClass1.class);
|
||||
mi.setTargetMethod("supertypes");
|
||||
mi.setArguments(new Object[] {new ArrayList(), new ArrayList(), "hello"});
|
||||
mi.setArguments(new Object[] {new ArrayList<>(), new ArrayList<>(), "hello"});
|
||||
mi.prepare();
|
||||
assertEquals("hello", mi.invoke());
|
||||
|
||||
mi = new MethodInvoker();
|
||||
mi.setTargetClass(TestClass1.class);
|
||||
mi.setTargetMethod("supertypes2");
|
||||
mi.setArguments(new Object[] {new ArrayList(), new ArrayList(), "hello", "bogus"});
|
||||
mi.setArguments(new Object[] {new ArrayList<>(), new ArrayList<>(), "hello", "bogus"});
|
||||
mi.prepare();
|
||||
assertEquals("hello", mi.invoke());
|
||||
|
||||
@@ -58,7 +58,7 @@ public class MethodInvokerTests extends TestCase {
|
||||
mi = new MethodInvoker();
|
||||
mi.setTargetClass(TestClass1.class);
|
||||
mi.setTargetMethod("supertypes2");
|
||||
mi.setArguments(new Object[] {new ArrayList(), new ArrayList(), "hello", Boolean.TRUE});
|
||||
mi.setArguments(new Object[] {new ArrayList<>(), new ArrayList<>(), "hello", Boolean.TRUE});
|
||||
try {
|
||||
mi.prepare();
|
||||
fail("Shouldn't have matched without argument conversion");
|
||||
@@ -169,23 +169,23 @@ public class MethodInvokerTests extends TestCase {
|
||||
public static void intArguments(int[] arg) {
|
||||
}
|
||||
|
||||
public static String supertypes(Collection c, Integer i) {
|
||||
public static String supertypes(Collection<?> c, Integer i) {
|
||||
return i.toString();
|
||||
}
|
||||
|
||||
public static String supertypes(Collection c, List l, String s) {
|
||||
public static String supertypes(Collection<?> c, List<?> l, String s) {
|
||||
return s;
|
||||
}
|
||||
|
||||
public static String supertypes2(Collection c, List l, Integer i) {
|
||||
public static String supertypes2(Collection<?> c, List<?> l, Integer i) {
|
||||
return i.toString();
|
||||
}
|
||||
|
||||
public static String supertypes2(Collection c, List l, String s, Integer i) {
|
||||
public static String supertypes2(Collection<?> c, List<?> l, String s, Integer i) {
|
||||
return s;
|
||||
}
|
||||
|
||||
public static String supertypes2(Collection c, List l, String s, String s2) {
|
||||
public static String supertypes2(Collection<?> c, List<?> l, String s, String s2) {
|
||||
return s;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user