diff --git a/junit-jupiter-migration-support/src/main/java/org/junit/jupiter/migrationsupport/parameterized/ParameterizedExtension.java b/junit-jupiter-migration-support/src/main/java/org/junit/jupiter/migrationsupport/parameterized/ParameterizedExtension.java index b09adbc83a0a..dc7d15c9ff65 100644 --- a/junit-jupiter-migration-support/src/main/java/org/junit/jupiter/migrationsupport/parameterized/ParameterizedExtension.java +++ b/junit-jupiter-migration-support/src/main/java/org/junit/jupiter/migrationsupport/parameterized/ParameterizedExtension.java @@ -37,6 +37,7 @@ import org.junit.jupiter.api.extension.TestTemplateInvocationContext; import org.junit.jupiter.api.extension.TestTemplateInvocationContextProvider; import org.junit.platform.commons.meta.API; +import org.junit.platform.commons.util.CollectionUtils; import org.junit.platform.commons.util.ReflectionUtils; import org.junit.runners.Parameterized; @@ -243,18 +244,14 @@ private static ParameterResolutionException unMatchedAmountOfParametersException "The amount of parametersFields in the constructor doesn't match those in the provided parametersFields"); } - private static ParameterResolutionException wrongParametersReturnType() { - return new ParameterResolutionException("The @Parameters returns the wrong type"); - } - @SuppressWarnings("unchecked") - private static Collection convertParametersMethodReturnType(Object o) { - if (o instanceof Collection) { - return (Collection) o; - } - else { - throw wrongParametersReturnType(); - } + private static Collection convertParametersMethodReturnType(Object obj) { + return CollectionUtils.toStream(obj).map(o -> { + if (o instanceof Object[]) { + return (Object[]) o; + } + return new Object[] { o }; + }).collect(toList()); } private static class ParameterWrapper { diff --git a/junit-jupiter-migration-support/src/test/java/org/junit/jupiter/migrationsupport/parameterized/ParameterizedExtensionTests.java b/junit-jupiter-migration-support/src/test/java/org/junit/jupiter/migrationsupport/parameterized/ParameterizedExtensionTests.java index 9eb0a40ca03a..d7e849e4a20a 100644 --- a/junit-jupiter-migration-support/src/test/java/org/junit/jupiter/migrationsupport/parameterized/ParameterizedExtensionTests.java +++ b/junit-jupiter-migration-support/src/test/java/org/junit/jupiter/migrationsupport/parameterized/ParameterizedExtensionTests.java @@ -49,7 +49,7 @@ void parametrizedWithParameterFieldInjection() { } @ExtendWith(ParameterizedExtension.class) - protected static class FibonacciTest { + private static class FibonacciTest { @Parameters public static Collection data() { return Arrays.asList( @@ -88,7 +88,7 @@ void paremeterizedWithConstructorInjection() { } @ExtendWith(ParameterizedExtension.class) - protected static class ParameterizedTestWithConstructor { + private static class ParameterizedTestWithConstructor { @Parameters public static Collection data() { return Arrays.asList( @@ -116,7 +116,7 @@ void unMatchedConstructorArgumentCount() { } @ExtendWith(ParameterizedExtension.class) - protected static class UnMatchedConstructor { + private static class UnMatchedConstructor { @Parameters public static Collection data() { return Arrays.asList(new Object[][] { { 0, 2 } }); @@ -140,7 +140,7 @@ void unMatchedParameterFieldsCount() { } @ExtendWith(ParameterizedExtension.class) - protected static class WrongParameters { + private static class WrongParameters { @Parameterized.Parameter public int a; @Parameterized.Parameter(1) @@ -168,7 +168,7 @@ void noInjectionMix() { } @ExtendWith(ParameterizedExtension.class) - protected static class DoubleInjection { + private static class DoubleInjection { @Parameterized.Parameter public int a; @@ -220,7 +220,7 @@ void emptyParametersList() { } @ExtendWith(ParameterizedExtension.class) - protected static class EmptyParameters { + private static class EmptyParameters { public EmptyParameters() { } @@ -243,7 +243,7 @@ void duplicatedParameterFieldIndex() { } @ExtendWith(ParameterizedExtension.class) - protected static class DuplicatedIndex { + private static class DuplicatedIndex { @Parameterized.Parameter public int a; @@ -268,7 +268,7 @@ void parametersAreOnlyCalledOnce() { } @ExtendWith(ParameterizedExtension.class) - protected static class ParametersCalledOnce { + private static class ParametersCalledOnce { private static int invocationCount = 0; public ParametersCalledOnce(int a) { @@ -294,7 +294,7 @@ void multipleTestTemplatesShouldBeRun() { } @ExtendWith(ParameterizedExtension.class) - static class MultipleTestTemplates { + private static class MultipleTestTemplates { private static int invocationCount = 0; public MultipleTestTemplates(int a) { @@ -319,6 +319,30 @@ void secondTemplate() { } } + @Test + void singleParameterIterable() { + ExecutionEventRecorder eventRecorder = executeTestsForClass(IterableTest.class); + assertThat(eventRecorder.getTestSuccessfulCount()).isEqualTo(2); + } + + @ExtendWith(ParameterizedExtension.class) + private static class IterableTest { + + public IterableTest(Object o) { + + } + + @Parameters + public static Object[] data() { + return new Object[] { new Object(), new Object() }; + } + + @TestTemplate + void dummy() { + + } + } + private ExecutionEventRecorder executeTestsForClass(Class testClass) { LauncherDiscoveryRequest request = request().selectors(selectClass(testClass)).build(); JupiterTestEngine engine = new JupiterTestEngine();