Skip to content

Commit d013085

Browse files
committed
Reduce scope of "unchecked" suppression
1 parent daea6f1 commit d013085

File tree

1 file changed

+11
-5
lines changed

1 file changed

+11
-5
lines changed

junit-jupiter-params/src/main/java/org/junit/jupiter/params/ParameterizedTestSpiInstantiator.java

+11-5
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,13 @@ static <T> T instantiate(Class<T> spiInterface, Class<? extends T> implementatio
2929
.invoke(findConstructor(spiInterface, implementationClass));
3030
}
3131

32+
@SuppressWarnings("unchecked")
33+
private static <T> Constructor<? extends T> findConstructor(Class<T> spiInterface,
34+
Class<? extends T> implementationClass) {
35+
36+
return (Constructor<? extends T>) findBestConstructor(spiInterface, implementationClass);
37+
}
38+
3239
/**
3340
* Find the "best" constructor for the supplied implementation class.
3441
*
@@ -38,9 +45,8 @@ static <T> T instantiate(Class<T> spiInterface, Class<? extends T> implementatio
3845
* Otherwise, this method throws an exception stating that it failed to
3946
* find a suitable constructor.
4047
*/
41-
@SuppressWarnings("unchecked")
42-
private static <T, V extends T> Constructor<? extends V> findConstructor(Class<T> spiInterface,
43-
Class<V> implementationClass) {
48+
private static <T> Constructor<?> findBestConstructor(Class<T> spiInterface,
49+
Class<? extends T> implementationClass) {
4450

4551
Preconditions.condition(!ReflectionUtils.isInnerClass(implementationClass),
4652
() -> String.format("The %s [%s] must be either a top-level class or a static nested class",
@@ -50,12 +56,12 @@ private static <T, V extends T> Constructor<? extends V> findConstructor(Class<T
5056

5157
// Single constructor?
5258
if (constructors.length == 1) {
53-
return (Constructor<V>) constructors[0];
59+
return constructors[0];
5460
}
5561
// Find default constructor.
5662
for (Constructor<?> constructor : constructors) {
5763
if (constructor.getParameterCount() == 0) {
58-
return (Constructor<V>) constructor;
64+
return constructor;
5965
}
6066
}
6167
// Otherwise...

0 commit comments

Comments
 (0)