From d0130853639346c962609e9f8b711336879e39ca Mon Sep 17 00:00:00 2001 From: Marc Philipp Date: Thu, 26 Sep 2024 08:52:01 +0200 Subject: [PATCH] Reduce scope of "unchecked" suppression --- .../params/ParameterizedTestSpiInstantiator.java | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/junit-jupiter-params/src/main/java/org/junit/jupiter/params/ParameterizedTestSpiInstantiator.java b/junit-jupiter-params/src/main/java/org/junit/jupiter/params/ParameterizedTestSpiInstantiator.java index 480569525d7..fa4661f88b6 100644 --- a/junit-jupiter-params/src/main/java/org/junit/jupiter/params/ParameterizedTestSpiInstantiator.java +++ b/junit-jupiter-params/src/main/java/org/junit/jupiter/params/ParameterizedTestSpiInstantiator.java @@ -29,6 +29,13 @@ static T instantiate(Class spiInterface, Class implementatio .invoke(findConstructor(spiInterface, implementationClass)); } + @SuppressWarnings("unchecked") + private static Constructor findConstructor(Class spiInterface, + Class implementationClass) { + + return (Constructor) findBestConstructor(spiInterface, implementationClass); + } + /** * Find the "best" constructor for the supplied implementation class. * @@ -38,9 +45,8 @@ static T instantiate(Class spiInterface, Class implementatio * Otherwise, this method throws an exception stating that it failed to * find a suitable constructor. */ - @SuppressWarnings("unchecked") - private static Constructor findConstructor(Class spiInterface, - Class implementationClass) { + private static Constructor findBestConstructor(Class spiInterface, + Class implementationClass) { Preconditions.condition(!ReflectionUtils.isInnerClass(implementationClass), () -> String.format("The %s [%s] must be either a top-level class or a static nested class", @@ -50,12 +56,12 @@ private static Constructor findConstructor(Class) constructors[0]; + return constructors[0]; } // Find default constructor. for (Constructor constructor : constructors) { if (constructor.getParameterCount() == 0) { - return (Constructor) constructor; + return constructor; } } // Otherwise...