Clean up warnings and tests in spring-core

This commit is contained in:
Sam Brannen 2015-08-20 15:49:33 +02:00
parent 9ab4062317
commit a3e7848a30
16 changed files with 92 additions and 96 deletions

View File

@ -1,5 +1,5 @@
/*
* Copyright 2002-2014 the original author or authors.
* Copyright 2002-2015 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -364,7 +364,7 @@ public abstract class AbstractEnvironment implements ConfigurableEnvironment {
}
@Override
@SuppressWarnings("unchecked")
@SuppressWarnings({ "unchecked", "rawtypes" })
public Map<String, Object> getSystemEnvironment() {
if (suppressGetenvAccess()) {
return Collections.emptyMap();
@ -408,7 +408,7 @@ public abstract class AbstractEnvironment implements ConfigurableEnvironment {
}
@Override
@SuppressWarnings("unchecked")
@SuppressWarnings({ "unchecked", "rawtypes" })
public Map<String, Object> getSystemProperties() {
try {
return (Map) System.getProperties();

View File

@ -91,7 +91,6 @@ public class ListenableFutureCallbackRegistry<T> {
* @param callback the failure callback to add
* @since 4.1
*/
@SuppressWarnings("unchecked")
public void addFailureCallback(FailureCallback callback) {
Assert.notNull(callback, "'callback' must not be null");
synchronized (this.mutex) {

View File

@ -1,5 +1,5 @@
/*
* Copyright 2002-2014 the original author or authors.
* Copyright 2002-2015 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -42,6 +42,7 @@ import static org.junit.Assert.*;
* @author Juergen Hoeller
* @author Chris Beams
*/
@SuppressWarnings("rawtypes")
public class BridgeMethodResolverTests {
private static TypeVariable<?> findTypeVariable(Class<?> clazz, String name) {

View File

@ -1,5 +1,5 @@
/*
* Copyright 2002-2012 the original author or authors.
* Copyright 2002-2015 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -26,6 +26,7 @@ import static org.junit.Assert.*;
* @author Juergen Hoeller
* @author Chris Shepperd
*/
@SuppressWarnings("unchecked")
public class ExceptionDepthComparatorTests {
@Test

View File

@ -36,6 +36,7 @@ import static org.springframework.util.ReflectionUtils.*;
* @author Juergen Hoeller
* @author Sam Brannen
*/
@SuppressWarnings({ "unchecked", "rawtypes" })
public class GenericTypeResolverTests {
@Test
@ -160,7 +161,7 @@ public class GenericTypeResolverTests {
MethodParameter methodParameter = MethodParameter.forMethodOrConstructor(
WithArrayBase.class.getDeclaredMethod("array", Object[].class), 0);
Class<?> resolved = GenericTypeResolver.resolveParameterType(methodParameter, WithArray.class);
assertThat(resolved, equalTo((Class) Object[].class));
assertThat(resolved, equalTo((Class<?>) Object[].class));
}
@Test
@ -168,7 +169,7 @@ public class GenericTypeResolverTests {
// SPR-11044
Class<?> resolved = GenericTypeResolver.resolveReturnType(
WithArrayBase.class.getDeclaredMethod("array", Object[].class), WithArray.class);
assertThat(resolved, equalTo((Class) Object[].class));
assertThat(resolved, equalTo((Class<?>) Object[].class));
}
@Test
@ -214,7 +215,6 @@ public class GenericTypeResolverTests {
return null;
}
@SuppressWarnings("rawtypes")
public MyInterfaceType raw() {
return null;
}

View File

@ -1,5 +1,5 @@
/*
* Copyright 2002-2014 the original author or authors.
* Copyright 2002-2015 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -343,7 +343,7 @@ public class CollectionToCollectionConverterTests {
public List<String> strings;
public List list = Collections.emptyList();
public List<?> list = Collections.emptyList();
public Collection<?> wildcardCollection = Collections.emptyList();

View File

@ -1,5 +1,5 @@
/*
* Copyright 2002-2014 the original author or authors.
* Copyright 2002-2015 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -278,6 +278,7 @@ public class MapToMapConverterTests {
public MultiValueMap<String, String> multiValueMapTarget;
@SuppressWarnings("rawtypes")
public Map notGenericMapSource;
public EnumMap<MyEnum, Integer> enumMap;

View File

@ -1,5 +1,5 @@
/*
* Copyright 2002-2012 the original author or authors.
* Copyright 2002-2015 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -30,6 +30,7 @@ import org.springframework.util.ObjectUtils;
/**
* @author Keith Donald
*/
@SuppressWarnings({ "rawtypes", "unchecked" })
public class ToStringCreatorTests extends TestCase {
private SomeObject s1, s2, s3;

View File

@ -1,5 +1,5 @@
/*
* Copyright 2002-2007 the original author or authors.
* Copyright 2002-2015 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -17,29 +17,27 @@ package org.springframework.core.type;
import java.lang.reflect.Method;
import junit.framework.TestCase;
import org.springframework.util.ClassUtils;
import org.springframework.util.ReflectionUtils;
import static org.junit.Assert.*;
/**
*
* @author Ramnivas Laddad
*
* @author Sam Brannen
*/
public class ClassloadingAssertions {
public static boolean isClassLoaded(String className) {
abstract class ClassloadingAssertions {
private static boolean isClassLoaded(String className) {
ClassLoader cl = ClassUtils.getDefaultClassLoader();
Method findLoadeClassMethod = ReflectionUtils.findMethod(cl.getClass(), "findLoadedClass", new Class[]{String.class});
findLoadeClassMethod.setAccessible(true);
Class loadedClass = (Class)ReflectionUtils.invokeMethod(findLoadeClassMethod, cl, new Object[]{className});
Method findLoadeClassMethod = ReflectionUtils.findMethod(cl.getClass(), "findLoadedClass", new Class[] { String.class });
ReflectionUtils.makeAccessible(findLoadeClassMethod);
Class<?> loadedClass = (Class<?>) ReflectionUtils.invokeMethod(findLoadeClassMethod, cl, new Object[] { className });
return loadedClass != null;
}
public static void assertClassLoaded(String className) {
public static void assertClassNotLoaded(String className) {
assertFalse("Class [" + className + "] should not have been loaded", isClassLoaded(className));
}
public static void assertClassNotLoaded(String className) {
TestCase.assertFalse("Class shouldn't have been loaded", isClassLoaded(className));
}
}

View File

@ -1,5 +1,5 @@
/*
* Copyright 2002-2013 the original author or authors.
* Copyright 2002-2015 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -18,29 +18,35 @@ package org.springframework.util;
import java.util.LinkedList;
import junit.framework.TestCase;
import org.junit.Test;
import org.springframework.tests.sample.objects.TestObject;
import static org.junit.Assert.*;
/**
* @author Rob Harrop
* @author Juergen Hoeller
*/
public class AutoPopulatingListTests extends TestCase {
public class AutoPopulatingListTests {
public void testWithClass() throws Exception {
@Test
public void withClass() throws Exception {
doTestWithClass(new AutoPopulatingList<Object>(TestObject.class));
}
public void testWithClassAndUserSuppliedBackingList() throws Exception {
@Test
public void withClassAndUserSuppliedBackingList() throws Exception {
doTestWithClass(new AutoPopulatingList<Object>(new LinkedList<Object>(), TestObject.class));
}
public void testWithElementFactory() throws Exception {
@Test
public void withElementFactory() throws Exception {
doTestWithElementFactory(new AutoPopulatingList<Object>(new MockElementFactory()));
}
public void testWithElementFactoryAndUserSuppliedBackingList() throws Exception {
@Test
public void withElementFactoryAndUserSuppliedBackingList() throws Exception {
doTestWithElementFactory(new AutoPopulatingList<Object>(new LinkedList<Object>(), new MockElementFactory()));
}
@ -76,13 +82,14 @@ public class AutoPopulatingListTests extends TestCase {
}
}
public void testSerialization() throws Exception {
@Test
public void serialization() throws Exception {
AutoPopulatingList<?> list = new AutoPopulatingList<Object>(TestObject.class);
assertEquals(list, SerializationTestUtils.serializeAndDeserialize(list));
}
private static class MockElementFactory implements AutoPopulatingList.ElementFactory {
private static class MockElementFactory implements AutoPopulatingList.ElementFactory<Object> {
@Override
public Object createElement(int index) {

View File

@ -1,5 +1,5 @@
/*
* Copyright 2002-2013 the original author or authors.
* Copyright 2002-2015 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -44,6 +44,7 @@ import static org.junit.Assert.*;
* @author Rob Harrop
* @author Rick Evans
*/
@SuppressWarnings({ "rawtypes", "unchecked" })
public class ClassUtilsTests {
private ClassLoader classLoader = getClass().getClassLoader();

View File

@ -1,5 +1,5 @@
/*
* Copyright 2002-2012 the original author or authors.
* Copyright 2002-2015 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -19,49 +19,62 @@ package org.springframework.util;
import java.io.FileNotFoundException;
import java.net.URL;
import junit.framework.TestCase;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.junit.Test;
import static org.junit.Assert.*;
/**
* @author Alef Arendsen
* @author Juergen Hoeller
* @author Sam Brannen
*/
public class Log4jConfigurerTests extends TestCase {
public class Log4jConfigurerTests {
public void testInitLoggingWithClasspath() throws FileNotFoundException {
@Test
public void initLoggingWithClasspath() throws FileNotFoundException {
doTestInitLogging("classpath:org/springframework/util/testlog4j.properties", false);
}
public void testInitLoggingWithRelativeFilePath() throws FileNotFoundException {
@Test
public void initLoggingWithRelativeFilePath() throws FileNotFoundException {
doTestInitLogging("src/test/resources/org/springframework/util/testlog4j.properties", false);
}
public void testInitLoggingWithAbsoluteFilePath() throws FileNotFoundException {
@Test
public void initLoggingWithAbsoluteFilePath() throws FileNotFoundException {
URL url = getClass().getResource("testlog4j.properties");
doTestInitLogging(url.toString(), false);
}
public void testInitLoggingWithClasspathAndRefreshInterval() throws FileNotFoundException {
@Test
public void initLoggingWithClasspathAndRefreshInterval() throws FileNotFoundException {
doTestInitLogging("classpath:org/springframework/util/testlog4j.properties", true);
}
public void testInitLoggingWithRelativeFilePathAndRefreshInterval() throws FileNotFoundException {
@Test
public void initLoggingWithRelativeFilePathAndRefreshInterval() throws FileNotFoundException {
doTestInitLogging("src/test/resources/org/springframework/util/testlog4j.properties", true);
}
/* only works on Windows
public void testInitLoggingWithAbsoluteFilePathAndRefreshInterval() throws FileNotFoundException {
@Test
public void initLoggingWithAbsoluteFilePathAndRefreshInterval() throws FileNotFoundException {
URL url = getClass().getResource("testlog4j.properties");
doTestInitLogging(url.getFile(), true);
}
*/
public void testInitLoggingWithFileUrlAndRefreshInterval() throws FileNotFoundException {
@Test
public void initLoggingWithFileUrlAndRefreshInterval() throws FileNotFoundException {
URL url = getClass().getResource("testlog4j.properties");
doTestInitLogging(url.toString(), true);
}
@Test(expected = FileNotFoundException.class)
public void initLoggingWithRefreshIntervalAndFileNotFound() throws FileNotFoundException {
Log4jConfigurer.initLogging("test/org/springframework/util/bla.properties", 10);
}
private void doTestInitLogging(String location, boolean refreshInterval) throws FileNotFoundException {
if (refreshInterval) {
Log4jConfigurer.initLogging(location, 10);
@ -87,14 +100,5 @@ public class Log4jConfigurerTests extends TestCase {
assertTrue(MockLog4jAppender.closeCalled);
}
public void testInitLoggingWithRefreshIntervalAndFileNotFound() throws FileNotFoundException {
try {
Log4jConfigurer.initLogging("test/org/springframework/util/bla.properties", 10);
fail("Exception should have been thrown, file does not exist!");
}
catch (FileNotFoundException ex) {
// OK
}
}
}

View File

@ -1,5 +1,5 @@
/*
* Copyright 2002-2012 the original author or authors.
* Copyright 2002-2015 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -27,36 +27,24 @@ import org.apache.log4j.spi.LoggingEvent;
*/
public class MockLog4jAppender extends AppenderSkeleton {
public static final List loggingStrings = new ArrayList();
public static final List<String> loggingStrings = new ArrayList<String>();
public static boolean closeCalled = false;
/* (non-Javadoc)
* @see org.apache.log4j.AppenderSkeleton#append(org.apache.log4j.spi.LoggingEvent)
*/
@Override
protected void append(LoggingEvent evt) {
//System.out.println("Adding " + evt.getMessage());
loggingStrings.add(evt.getMessage());
loggingStrings.add(evt.getMessage().toString());
}
/* (non-Javadoc)
* @see org.apache.log4j.Appender#close()
*/
@Override
public void close() {
closeCalled = true;
}
/* (non-Javadoc)
* @see org.apache.log4j.Appender#requiresLayout()
*/
@Override
public boolean requiresLayout() {
return false;
}
}

View File

@ -1,5 +1,5 @@
/*
* Copyright 2002-2014 the original author or authors.
* Copyright 2002-2015 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -28,6 +28,7 @@ import static org.mockito.Mockito.*;
* @author Arjen Poutsma
* @author Sebastien Deleuze
*/
@SuppressWarnings("unchecked")
public class ListenableFutureTaskTests {
@Test

View File

@ -1,5 +1,5 @@
/*
* Copyright 2002-2014 the original author or authors.
* Copyright 2002-2015 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -29,10 +29,10 @@ import static org.junit.Assert.*;
import static org.mockito.Mockito.any;
import static org.mockito.Mockito.*;
/**
* @author Mattias Severson
*/
@SuppressWarnings({ "rawtypes", "unchecked" })
public class SettableListenableFutureTests {
private SettableListenableFuture<String> settableListenableFuture;

View File

@ -1,5 +1,5 @@
/*
* Copyright 2002-2009 the original author or authors.
* Copyright 2002-2015 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -13,26 +13,23 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.util.xml;
import java.util.Collections;
import java.util.Iterator;
import javax.xml.XMLConstants;
import org.junit.Before;
import org.junit.Test;
import static org.junit.Assert.*;
public class SimpleNamespaceContextTests {
private SimpleNamespaceContext context;
private final SimpleNamespaceContext context = new SimpleNamespaceContext() {{
bindNamespaceUri("prefix", "namespaceURI");
}};
@Before
public void createContext() throws Exception {
context = new SimpleNamespaceContext();
context.bindNamespaceUri("prefix", "namespaceURI");
}
@Test
public void getNamespaceURI() {
@ -48,7 +45,6 @@ public class SimpleNamespaceContextTests {
context.getNamespaceURI(XMLConstants.XML_NS_PREFIX));
assertEquals("Invalid namespaceURI for attribute prefix", XMLConstants.XMLNS_ATTRIBUTE_NS_URI,
context.getNamespaceURI(XMLConstants.XMLNS_ATTRIBUTE));
}
@Test
@ -75,32 +71,32 @@ public class SimpleNamespaceContextTests {
public void multiplePrefixes() {
context.bindNamespaceUri("prefix1", "namespace");
context.bindNamespaceUri("prefix2", "namespace");
Iterator iterator = context.getPrefixes("namespace");
Iterator<String> iterator = context.getPrefixes("namespace");
assertNotNull("getPrefixes returns null", iterator);
assertTrue("iterator is empty", iterator.hasNext());
String result = (String) iterator.next();
String result = iterator.next();
assertTrue("Invalid prefix", result.equals("prefix1") || result.equals("prefix2"));
assertTrue("iterator is empty", iterator.hasNext());
result = (String) iterator.next();
result = iterator.next();
assertTrue("Invalid prefix", result.equals("prefix1") || result.equals("prefix2"));
assertFalse("iterator contains more than two values", iterator.hasNext());
}
private void assertPrefixes(String namespaceUri, String prefix) {
Iterator iterator = context.getPrefixes(namespaceUri);
Iterator<String> iterator = context.getPrefixes(namespaceUri);
assertNotNull("getPrefixes returns null", iterator);
assertTrue("iterator is empty", iterator.hasNext());
String result = (String) iterator.next();
String result = iterator.next();
assertEquals("Invalid prefix", prefix, result);
assertFalse("iterator contains multiple values", iterator.hasNext());
}
@Test
public void getBoundPrefixes() throws Exception {
Iterator iterator = context.getBoundPrefixes();
Iterator<String> iterator = context.getBoundPrefixes();
assertNotNull("getPrefixes returns null", iterator);
assertTrue("iterator is empty", iterator.hasNext());
String result = (String) iterator.next();
String result = iterator.next();
assertEquals("Invalid prefix", "prefix", result);
assertFalse("iterator contains multiple values", iterator.hasNext());
}
@ -115,8 +111,6 @@ public class SimpleNamespaceContextTests {
public void removeBinding() throws Exception {
context.removeBinding("prefix");
assertNull("Invalid prefix for unbound namespace", context.getPrefix("prefix"));
}
}