1
0

Fix generics warnings in tests

Javadoc in test
This commit is contained in:
Gary Gregory
2024-08-14 08:30:16 -04:00
parent 8e5855505d
commit 1e987dcace
26 changed files with 55 additions and 56 deletions

View File

@@ -28,7 +28,7 @@ import junit.framework.TestCase;
public class AltHashtableTestCase extends TestCase {
public static Test suite() throws Exception {
final Class thisClass = AltHashtableTestCase.class;
final Class<AltHashtableTestCase> thisClass = AltHashtableTestCase.class;
final ClassLoader thisClassLoader = thisClass.getClassLoader();
final PathableClassLoader loader = new PathableClassLoader(null);
@@ -36,7 +36,7 @@ public class AltHashtableTestCase extends TestCase {
loader.addLogicalLib("testclasses");
loader.addLogicalLib("commons-logging");
final Class testClass = loader.loadClass(thisClass.getName());
final Class<?> testClass = loader.loadClass(thisClass.getName());
return new PathableTestSuite(testClass, loader);
}

View File

@@ -77,7 +77,7 @@ public class LoadTestCase extends TestCase {
// not very trivial to emulate we must implement "findClass",
// but it will delegate to JUnit class loader first
@Override
public Class loadClass(final String name) throws ClassNotFoundException {
public Class<?> loadClass(final String name) throws ClassNotFoundException {
// isolates all logging classes, application in the same class loader too.
// filters exceptions to simplify handling in test
for (final String element : LOG_PCKG) {
@@ -96,7 +96,7 @@ public class LoadTestCase extends TestCase {
private ClassLoader origContextClassLoader;
private void execute(final Class cls) throws Exception {
private void execute(final Class<?> cls) throws Exception {
cls.getConstructor().newInstance();
}
@@ -104,8 +104,8 @@ public class LoadTestCase extends TestCase {
* Load class UserClass via a temporary class loader which is a child of
* the class loader used to load this test class.
*/
private Class reload() throws Exception {
Class testObjCls = null;
private Class<?> reload() throws Exception {
Class<?> testObjCls = null;
final AppClassLoader appLoader = new AppClassLoader(this.getClass().getClassLoader());
try {

View File

@@ -304,7 +304,7 @@ public class PathableClassLoader extends URLClassLoader {
* that entries' class loader.
*/
@Override
protected Class loadClass(final String name, final boolean resolve)
protected Class<?> loadClass(final String name, final boolean resolve)
throws ClassNotFoundException {
// just for performance, check java and javax
if (name.startsWith("java.") || name.startsWith("javax.")) {
@@ -326,7 +326,7 @@ public class PathableClassLoader extends URLClassLoader {
return super.loadClass(name, resolve);
}
try {
Class clazz = findLoadedClass(name);
Class<?> clazz = findLoadedClass(name);
if (clazz == null) {
clazz = super.findClass(name);
}
@@ -360,7 +360,6 @@ public class PathableClassLoader extends URLClassLoader {
}
/**
*
* Clean implementation of list function of
* {@link java.util.Collection} added in JDK 1.4
* @param en {@code Enumeration}, possibly null

View File

@@ -120,7 +120,7 @@ public class PathableTestSuite extends TestSuite {
* calls to Thread.currentThread.getContextClassLoader from test methods
* (or any method called by test methods).
*/
public PathableTestSuite(final Class testClass, final ClassLoader contextClassLoader) {
public PathableTestSuite(final Class<?> testClass, final ClassLoader contextClassLoader) {
super(testClass);
contextLoader = contextClassLoader;
}

View File

@@ -43,7 +43,7 @@ public class FirstPriorityConfigTestCase extends TestCase {
* Return the tests included in this test suite.
*/
public static Test suite() throws Exception {
final Class thisClass = FirstPriorityConfigTestCase.class;
final Class<FirstPriorityConfigTestCase> thisClass = FirstPriorityConfigTestCase.class;
// Determine the URL to this .class file, so that we can then
// append the priority dirs to it. For tidiness, load this
@@ -75,7 +75,7 @@ public class FirstPriorityConfigTestCase extends TestCase {
// load the test class via webapp loader, and use the webapp loader
// as the tccl loader too.
final Class testClass = webappLoader.loadClass(thisClass.getName());
final Class<?> testClass = webappLoader.loadClass(thisClass.getName());
return new PathableTestSuite(testClass, webappLoader);
}

View File

@@ -50,7 +50,7 @@ public class PriorityConfigTestCase extends TestCase {
* Return the tests included in this test suite.
*/
public static Test suite() throws Exception {
final Class thisClass = PriorityConfigTestCase.class;
final Class<PriorityConfigTestCase> thisClass = PriorityConfigTestCase.class;
// Determine the URL to this .class file, so that we can then
// append the priority dirs to it. For tidiness, load this
@@ -93,7 +93,7 @@ public class PriorityConfigTestCase extends TestCase {
// load the test class via webapp loader, and use the webapp loader
// as the tccl loader too.
final Class testClass = webappLoader.loadClass(thisClass.getName());
final Class<?> testClass = webappLoader.loadClass(thisClass.getName());
return new PathableTestSuite(testClass, webappLoader);
}

View File

@@ -50,7 +50,7 @@ public class CustomConfigAPITestCase extends CustomConfigTestCase {
child.addLogicalLib("testclasses");
child.addLogicalLib("commons-logging");
final Class testClass = child.loadClass(CustomConfigAPITestCase.class.getName());
final Class<?> testClass = child.loadClass(CustomConfigAPITestCase.class.getName());
return new PathableTestSuite(testClass, child);
}

View File

@@ -49,7 +49,7 @@ public class CustomConfigFullTestCase extends CustomConfigTestCase {
final PathableClassLoader child = new PathableClassLoader(parent);
child.addLogicalLib("testclasses");
final Class testClass = child.loadClass(CustomConfigFullTestCase.class.getName());
final Class<?> testClass = child.loadClass(CustomConfigFullTestCase.class.getName());
return new PathableTestSuite(testClass, child);
}

View File

@@ -62,7 +62,7 @@ public class CustomConfigTestCase extends DefaultConfigTestCase {
final ClassLoader srcCL = CustomConfigAPITestCase.class.getClassLoader();
final byte[] classData = readClass(className, srcCL);
final Class[] params = { String.class, classData.getClass(), Integer.TYPE, Integer.TYPE };
final Class<?>[] params = { String.class, classData.getClass(), Integer.TYPE, Integer.TYPE };
final Method m = ClassLoader.class.getDeclaredMethod("defineClass", params);
final Object[] args = new Object[4];
@@ -118,7 +118,7 @@ public class CustomConfigTestCase extends DefaultConfigTestCase {
cl.addLogicalLib("commons-logging");
cl.addLogicalLib("testclasses");
final Class testClass = cl.loadClass(CustomConfigTestCase.class.getName());
final Class<?> testClass = cl.loadClass(CustomConfigTestCase.class.getName());
return new PathableTestSuite(testClass, cl);
}

View File

@@ -46,7 +46,7 @@ public class DefaultConfigTestCase extends TestCase {
loader.addLogicalLib("testclasses");
loader.addLogicalLib("commons-logging");
final Class testClass = loader.loadClass(DefaultConfigTestCase.class.getName());
final Class<?> testClass = loader.loadClass(DefaultConfigTestCase.class.getName());
return new PathableTestSuite(testClass, loader);
}

View File

@@ -50,7 +50,7 @@ public class ApiClasspathStandardTestCase extends TestCase {
child.addLogicalLib("commons-logging");
child.addLogicalLib("testclasses");
final Class testClass = child.loadClass(
final Class<?> testClass = child.loadClass(
"org.apache.commons.logging.log4j.log4j12.Log4j12StandardTests");
return new PathableTestSuite(testClass, child);
}

View File

@@ -46,7 +46,7 @@ public class AppClasspathStandardTestCase extends TestCase {
loader.addLogicalLib("log4j2-core");
loader.addLogicalLib("commons-logging");
final Class testClass = loader.loadClass(
final Class<?> testClass = loader.loadClass(
"org.apache.commons.logging.log4j.log4j12.Log4j12StandardTests");
return new PathableTestSuite(testClass, loader);
}

View File

@@ -48,7 +48,7 @@ public class ChildClasspathStandardTestCase extends TestCase {
child.addLogicalLib("log4j2-core");
child.addLogicalLib("commons-logging");
final Class testClass = child.loadClass(
final Class<?> testClass = child.loadClass(
"org.apache.commons.logging.log4j.log4j12.Log4j12StandardTests");
return new PathableTestSuite(testClass, child);
}

View File

@@ -48,7 +48,7 @@ public class ParentClasspathStandardTestCase extends TestCase {
final PathableClassLoader child = new PathableClassLoader(parent);
child.addLogicalLib("testclasses");
final Class testClass = child.loadClass(
final Class<?> testClass = child.loadClass(
"org.apache.commons.logging.log4j.log4j12.Log4j12StandardTests");
return new PathableTestSuite(testClass, child);
}

View File

@@ -41,7 +41,7 @@ public class StandardTestCase extends AbstractLogTest {
* Return the tests included in this test suite.
*/
public static Test suite() throws Exception {
final Class thisClass = StandardTestCase.class;
final Class<StandardTestCase> thisClass = StandardTestCase.class;
final PathableClassLoader loader = new PathableClassLoader(null);
loader.useExplicitLoader("junit.", Test.class.getClassLoader());
@@ -49,7 +49,7 @@ public class StandardTestCase extends AbstractLogTest {
loader.addLogicalLib("commons-logging");
loader.addLogicalLib("logkit");
final Class testClass = loader.loadClass(thisClass.getName());
final Class<?> testClass = loader.loadClass(thisClass.getName());
return new PathableTestSuite(testClass, loader);
}

View File

@@ -53,7 +53,7 @@ public class ChildFirstTestCase extends TestCase {
* </ul>
*/
public static Test suite() throws Exception {
final Class thisClass = ChildFirstTestCase.class;
final Class<ChildFirstTestCase> thisClass = ChildFirstTestCase.class;
final ClassLoader thisClassLoader = thisClass.getClassLoader();
// Make the parent a direct child of the bootloader to hide all
@@ -86,7 +86,7 @@ public class ChildFirstTestCase extends TestCase {
context.setParentFirst(false);
// reload this class via the child class loader
final Class testClass = child.loadClass(thisClass.getName());
final Class<?> testClass = child.loadClass(thisClass.getName());
// and return our custom TestSuite class
return new PathableTestSuite(testClass, context);
@@ -167,30 +167,30 @@ public class ChildFirstTestCase extends TestCase {
// junit classes should be visible; their class loader is not
// in the hierarchy of parent class loaders for this class,
// though it is accessible due to trickery in the PathableClassLoader.
final Class junitTest = contextLoader.loadClass("junit.framework.Test");
final Class<?> junitTest = contextLoader.loadClass("junit.framework.Test");
final Set<ClassLoader> ancestorCLs = getAncestorCLs();
assertFalse("Junit not loaded by ancestor class loader",
ancestorCLs.contains(junitTest.getClassLoader()));
// jcl api classes should be visible only via the parent
final Class logClass = contextLoader.loadClass("org.apache.commons.logging.Log");
final Class<?> logClass = contextLoader.loadClass("org.apache.commons.logging.Log");
assertSame("Log class not loaded via parent",
logClass.getClassLoader(), parentLoader);
// jcl adapter classes should be visible via both parent and child. However
// as the class loaders are child-first we should see the child one.
final Class log4jClass = contextLoader.loadClass("org.apache.commons.logging.impl.Log4JLogger");
final Class<?> log4jClass = contextLoader.loadClass("org.apache.commons.logging.impl.Log4JLogger");
assertSame("Log4JLogger not loaded via child",
log4jClass.getClassLoader(), thisLoader);
// test classes should be visible via the child only
final Class testClass = contextLoader.loadClass("org.apache.commons.logging.PathableTestSuite");
final Class<?> testClass = contextLoader.loadClass("org.apache.commons.logging.PathableTestSuite");
assertSame("PathableTestSuite not loaded via child",
testClass.getClassLoader(), thisLoader);
// test loading of class that is not available
try {
final Class noSuchClass = contextLoader.loadClass("no.such.class");
final Class<?> noSuchClass = contextLoader.loadClass("no.such.class");
fail("Class no.such.class is unexpectedly available");
assertNotNull(noSuchClass); // silence warning about unused var
} catch (final ClassNotFoundException ex) {
@@ -198,7 +198,7 @@ public class ChildFirstTestCase extends TestCase {
}
// String class class loader is null
final Class stringClass = contextLoader.loadClass("java.lang.String");
final Class<?> stringClass = contextLoader.loadClass("java.lang.String");
assertNull("String class class loader is not null!",
stringClass.getClassLoader());
}

View File

@@ -60,7 +60,7 @@ public class GeneralTestCase extends TestCase {
* Sets up a custom class loader hierarchy for this test case.
*/
public static Test suite() throws Exception {
final Class thisClass = GeneralTestCase.class;
final Class<GeneralTestCase> thisClass = GeneralTestCase.class;
final ClassLoader thisClassLoader = thisClass.getClassLoader();
final PathableClassLoader loader = new PathableClassLoader(null);
@@ -68,7 +68,7 @@ public class GeneralTestCase extends TestCase {
loader.addLogicalLib("testclasses");
// reload this class via the child class loader
final Class testClass = loader.loadClass(thisClass.getName());
final Class<?> testClass = loader.loadClass(thisClass.getName());
// and return our custom TestSuite class
return new PathableTestSuite(testClass, loader);

View File

@@ -62,7 +62,7 @@ public class SecurityAllowedTestCase extends TestCase {
parent.addLogicalLib("commons-logging");
parent.addLogicalLib("testclasses");
final Class testClass = parent.loadClass(
final Class<?> testClass = parent.loadClass(
"org.apache.commons.logging.security.SecurityAllowedTestCase");
return new PathableTestSuite(testClass, parent);
}
@@ -101,7 +101,7 @@ public class SecurityAllowedTestCase extends TestCase {
try {
// Use reflection so that we can control exactly when the static
// initializer for the LogFactory class is executed.
final Class c = this.getClass().getClassLoader().loadClass(
final Class<?> c = this.getClass().getClassLoader().loadClass(
"org.apache.commons.logging.LogFactory");
final Method m = c.getMethod("getLog", Class.class);
final Log log = (Log) m.invoke(null, this.getClass());

View File

@@ -71,7 +71,7 @@ public class SecurityForbiddenTestCase extends TestCase {
parent.addLogicalLib("commons-logging");
parent.addLogicalLib("testclasses");
final Class testClass = parent.loadClass(
final Class<?> testClass = parent.loadClass(
"org.apache.commons.logging.security.SecurityForbiddenTestCase");
return new PathableTestSuite(testClass, parent);
}
@@ -85,7 +85,7 @@ public class SecurityForbiddenTestCase extends TestCase {
*/
private Object loadClass(final String name, final ClassLoader classLoader) {
try {
final Class clazz = classLoader.loadClass(name);
final Class<?> clazz = classLoader.loadClass(name);
return clazz.getConstructor().newInstance();
} catch (final Exception e) {
final StringWriter sw = new StringWriter();
@@ -135,7 +135,7 @@ public class SecurityForbiddenTestCase extends TestCase {
try {
// Use reflection so that we can control exactly when the static
// initializer for the LogFactory class is executed.
final Class c = this.getClass().getClassLoader().loadClass(
final Class<?> c = this.getClass().getClassLoader().loadClass(
"org.apache.commons.logging.LogFactory");
final Method m = c.getMethod("getLog", Class.class);
final Log log = (Log) m.invoke(null, this.getClass());

View File

@@ -32,7 +32,7 @@ public class DummyLogFactory extends LogFactory {
}
@Override
public Log getInstance(final Class clazz) throws LogConfigurationException {
public Log getInstance(final Class<?> clazz) throws LogConfigurationException {
return null;
}

View File

@@ -56,7 +56,7 @@ public class BasicServletTestCase extends TestCase {
tccl.setParentFirst(false);
tccl.addLogicalLib("commons-logging");
final Class testClass = child.loadClass(BasicServletTestCase.class.getName());
final Class<?> testClass = child.loadClass(BasicServletTestCase.class.getName());
return new PathableTestSuite(testClass, tccl);
}

View File

@@ -48,14 +48,14 @@ public class CustomConfigTestCase extends DefaultConfigTestCase {
* Or we could fix SimpleLog to be sane...
*/
public static Test suite() throws Exception {
final Class thisClass = CustomConfigTestCase.class;
final Class<CustomConfigTestCase> thisClass = CustomConfigTestCase.class;
final PathableClassLoader loader = new PathableClassLoader(null);
loader.useExplicitLoader("junit.", Test.class.getClassLoader());
loader.addLogicalLib("testclasses");
loader.addLogicalLib("commons-logging");
final Class testClass = loader.loadClass(thisClass.getName());
final Class<?> testClass = loader.loadClass(thisClass.getName());
return new PathableTestSuite(testClass, loader);
}

View File

@@ -44,14 +44,14 @@ public class DateTimeCustomConfigTestCase extends CustomConfigTestCase {
* Or we could fix SimpleLog to be sane...
*/
public static Test suite() throws Exception {
final Class thisClass = DateTimeCustomConfigTestCase.class;
final Class<DateTimeCustomConfigTestCase> thisClass = DateTimeCustomConfigTestCase.class;
final PathableClassLoader loader = new PathableClassLoader(null);
loader.useExplicitLoader("junit.", Test.class.getClassLoader());
loader.addLogicalLib("testclasses");
loader.addLogicalLib("commons-logging");
final Class testClass = loader.loadClass(thisClass.getName());
final Class<?> testClass = loader.loadClass(thisClass.getName());
return new PathableTestSuite(testClass, loader);
}

View File

@@ -51,14 +51,14 @@ public class DefaultConfigTestCase extends TestCase {
* Or we could fix SimpleLog to be sane...
*/
public static Test suite() throws Exception {
final Class thisClass = DefaultConfigTestCase.class;
final Class<DefaultConfigTestCase> thisClass = DefaultConfigTestCase.class;
final PathableClassLoader loader = new PathableClassLoader(null);
loader.useExplicitLoader("junit.", Test.class.getClassLoader());
loader.addLogicalLib("testclasses");
loader.addLogicalLib("commons-logging");
final Class testClass = loader.loadClass(thisClass.getName());
final Class<?> testClass = loader.loadClass(thisClass.getName());
return new PathableTestSuite(testClass, loader);
}

View File

@@ -42,7 +42,7 @@ public class TcclDisabledTestCase extends TestCase {
* Returns the tests included in this test suite.
*/
public static Test suite() throws Exception {
final Class thisClass = TcclDisabledTestCase.class;
final Class<TcclDisabledTestCase> thisClass = TcclDisabledTestCase.class;
// Determine the URL to this .class file, so that we can then
// append the priority dirs to it. For tidiness, load this
@@ -80,7 +80,7 @@ public class TcclDisabledTestCase extends TestCase {
final PathableClassLoader tcclLoader = new PathableClassLoader(parentLoader);
tcclLoader.addLogicalLib("testclasses");
final Class testClass = parentLoader.loadClass(thisClass.getName());
final Class<?> testClass = parentLoader.loadClass(thisClass.getName());
return new PathableTestSuite(testClass, tcclLoader);
}
@@ -113,7 +113,7 @@ public class TcclDisabledTestCase extends TestCase {
// MyLogFactoryImpl should not be loadable via parent loader
try {
final Class clazz = thisClassLoader.loadClass(MY_LOG_FACTORY_IMPL);
final Class<?> clazz = thisClassLoader.loadClass(MY_LOG_FACTORY_IMPL);
fail("Unexpectedly able to load MyLogFactoryImpl via test class class loader");
assertNotNull(clazz); // silence warning about unused var
} catch (final ClassNotFoundException ex) {
@@ -122,7 +122,7 @@ public class TcclDisabledTestCase extends TestCase {
// MyLogFactoryImpl should be loadable via TCCL loader
try {
final Class clazz = tcclLoader.loadClass(MY_LOG_FACTORY_IMPL);
final Class<?> clazz = tcclLoader.loadClass(MY_LOG_FACTORY_IMPL);
assertNotNull(clazz);
} catch (final ClassNotFoundException ex) {
fail("Unexpectedly unable to load MyLogFactoryImpl via TCCL class loader");

View File

@@ -36,7 +36,7 @@ public class TcclEnabledTestCase extends TestCase {
* Return the tests included in this test suite.
*/
public static Test suite() throws Exception {
final Class thisClass = TcclEnabledTestCase.class;
final Class<TcclEnabledTestCase> thisClass = TcclEnabledTestCase.class;
// Determine the URL to this .class file, so that we can then
// append the priority dirs to it. For tidiness, load this
@@ -74,7 +74,7 @@ public class TcclEnabledTestCase extends TestCase {
final PathableClassLoader tcclLoader = new PathableClassLoader(parentLoader);
tcclLoader.addLogicalLib("testclasses");
final Class testClass = parentLoader.loadClass(thisClass.getName());
final Class<?> testClass = parentLoader.loadClass(thisClass.getName());
return new PathableTestSuite(testClass, tcclLoader);
}
@@ -107,7 +107,7 @@ public class TcclEnabledTestCase extends TestCase {
// MyLogFactoryImpl should not be loadable via parent loader
try {
final Class clazz = thisClassLoader.loadClass(
final Class<?> clazz = thisClassLoader.loadClass(
"org.apache.commons.logging.tccl.custom.MyLogFactoryImpl");
fail("Unexpectedly able to load MyLogFactoryImpl via test class class loader");
assertNotNull(clazz); // silence warning about unused var
@@ -117,7 +117,7 @@ public class TcclEnabledTestCase extends TestCase {
// MyLogFactoryImpl should be loadable via TCCL loader
try {
final Class clazz = tcclLoader.loadClass(
final Class<?> clazz = tcclLoader.loadClass(
"org.apache.commons.logging.tccl.custom.MyLogFactoryImpl");
assertNotNull(clazz);
} catch (final ClassNotFoundException ex) {