From 90ba9e71b586cbeb5e31376af5e6f40a60b562e4 Mon Sep 17 00:00:00 2001 From: Liam Clark Date: Sun, 9 Apr 2017 16:29:37 +0200 Subject: [PATCH] Move to migrationsupport.parameterized package --- .../ParameterizedExtension.java | 11 +++++------ .../migrationsupport/parameterized/package-info.java | 5 +++++ .../ParametrizedExtensionTests.java | 11 ++++------- 3 files changed, 14 insertions(+), 13 deletions(-) rename junit-jupiter-migration-support/src/main/java/org/junit/jupiter/migrationsupport/{rules => parameterized}/ParameterizedExtension.java (96%) create mode 100644 junit-jupiter-migration-support/src/main/java/org/junit/jupiter/migrationsupport/parameterized/package-info.java rename junit-jupiter-migration-support/src/test/java/org/junit/jupiter/migrationsupport/{ => parameterized}/ParametrizedExtensionTests.java (96%) diff --git a/junit-jupiter-migration-support/src/main/java/org/junit/jupiter/migrationsupport/rules/ParameterizedExtension.java b/junit-jupiter-migration-support/src/main/java/org/junit/jupiter/migrationsupport/parameterized/ParameterizedExtension.java similarity index 96% rename from junit-jupiter-migration-support/src/main/java/org/junit/jupiter/migrationsupport/rules/ParameterizedExtension.java rename to junit-jupiter-migration-support/src/main/java/org/junit/jupiter/migrationsupport/parameterized/ParameterizedExtension.java index c7d7356b40c5..3859a43797be 100644 --- a/junit-jupiter-migration-support/src/main/java/org/junit/jupiter/migrationsupport/rules/ParameterizedExtension.java +++ b/junit-jupiter-migration-support/src/main/java/org/junit/jupiter/migrationsupport/parameterized/ParameterizedExtension.java @@ -8,7 +8,7 @@ * http://www.eclipse.org/legal/epl-v10.html */ -package org.junit.jupiter.migrationsupport.rules; +package org.junit.jupiter.migrationsupport.parameterized; import static java.util.Collections.singletonList; import static java.util.function.Function.identity; @@ -27,14 +27,13 @@ import java.util.stream.IntStream; import java.util.stream.Stream; -import org.junit.jupiter.api.extension.BeforeTestExecutionCallback; import org.junit.jupiter.api.extension.ContainerExtensionContext; import org.junit.jupiter.api.extension.Extension; import org.junit.jupiter.api.extension.ExtensionContext; import org.junit.jupiter.api.extension.ParameterContext; import org.junit.jupiter.api.extension.ParameterResolutionException; import org.junit.jupiter.api.extension.ParameterResolver; -import org.junit.jupiter.api.extension.TestExtensionContext; +import org.junit.jupiter.api.extension.TestInstancePostProcessor; import org.junit.jupiter.api.extension.TestTemplateInvocationContext; import org.junit.jupiter.api.extension.TestTemplateInvocationContextProvider; import org.junit.platform.commons.meta.API; @@ -215,7 +214,7 @@ public List getAdditionalExtensions() { }; } - private static class InjectionExtension implements BeforeTestExecutionCallback { + private static class InjectionExtension implements TestInstancePostProcessor { private final Object[] parameters; public InjectionExtension(Object[] parameters) { @@ -223,7 +222,7 @@ public InjectionExtension(Object[] parameters) { } @Override - public void beforeTestExecution(TestExtensionContext context) throws Exception { + public void postProcessTestInstance(Object testInstance, ExtensionContext context) throws Exception { List parameters = parametersFields(context); if (!parameters.isEmpty() && parameters.size() != this.parameters.length) { @@ -233,7 +232,7 @@ public void beforeTestExecution(TestExtensionContext context) throws Exception { for (Field param : parameters) { Parameterized.Parameter annotation = param.getAnnotation(Parameterized.Parameter.class); int paramIndex = annotation.value(); - param.set(context.getTestInstance(), this.parameters[paramIndex]); + param.set(testInstance, this.parameters[paramIndex]); } } } diff --git a/junit-jupiter-migration-support/src/main/java/org/junit/jupiter/migrationsupport/parameterized/package-info.java b/junit-jupiter-migration-support/src/main/java/org/junit/jupiter/migrationsupport/parameterized/package-info.java new file mode 100644 index 000000000000..c87ae401021c --- /dev/null +++ b/junit-jupiter-migration-support/src/main/java/org/junit/jupiter/migrationsupport/parameterized/package-info.java @@ -0,0 +1,5 @@ +/** + * Extension to run JUnit 4 style parameterized tests in JUnit Jupiter. + */ + +package org.junit.jupiter.migrationsupport.parameterized; diff --git a/junit-jupiter-migration-support/src/test/java/org/junit/jupiter/migrationsupport/ParametrizedExtensionTests.java b/junit-jupiter-migration-support/src/test/java/org/junit/jupiter/migrationsupport/parameterized/ParametrizedExtensionTests.java similarity index 96% rename from junit-jupiter-migration-support/src/test/java/org/junit/jupiter/migrationsupport/ParametrizedExtensionTests.java rename to junit-jupiter-migration-support/src/test/java/org/junit/jupiter/migrationsupport/parameterized/ParametrizedExtensionTests.java index b44e212d14de..2d421b6f5583 100644 --- a/junit-jupiter-migration-support/src/test/java/org/junit/jupiter/migrationsupport/ParametrizedExtensionTests.java +++ b/junit-jupiter-migration-support/src/test/java/org/junit/jupiter/migrationsupport/parameterized/ParametrizedExtensionTests.java @@ -8,7 +8,7 @@ * http://www.eclipse.org/legal/epl-v10.html */ -package org.junit.jupiter.migrationsupport; +package org.junit.jupiter.migrationsupport.parameterized; import static org.assertj.core.api.Assertions.assertThat; import static org.junit.jupiter.api.Assertions.assertEquals; @@ -31,7 +31,6 @@ import org.junit.jupiter.api.extension.ExtendWith; import org.junit.jupiter.api.extension.ParameterResolutionException; import org.junit.jupiter.engine.JupiterTestEngine; -import org.junit.jupiter.migrationsupport.rules.ParameterizedExtension; import org.junit.platform.engine.ExecutionRequest; import org.junit.platform.engine.TestDescriptor; import org.junit.platform.engine.TestExecutionResult; @@ -41,10 +40,10 @@ import org.junit.runners.Parameterized; import org.junit.runners.Parameterized.Parameters; -public class ParametrizedExtensionTests { +class ParametrizedExtensionTests { @Test - public void parametrizedWithParameterFieldInjection() { + void parametrizedWithParameterFieldInjection() { ExecutionEventRecorder executionEventRecorder = executeTestsForClass(FibonacciTest.class); assertThat(executionEventRecorder.getTestSuccessfulCount()).isEqualTo(7); } @@ -83,7 +82,7 @@ private static int compute(int n) { } @Test - public void paremeterizedWithConstructorInjection() { + void paremeterizedWithConstructorInjection() { ExecutionEventRecorder executionEventRecorder = executeTestsForClass(ParameterizedTestWithConstructor.class); assertThat(executionEventRecorder.getTestSuccessfulCount()).isEqualTo(7); } @@ -224,8 +223,6 @@ void emptyParametersList() { protected static class EmptyParameters { public EmptyParameters() { - int a = 0; - int b = a + 3; } @Parameters