|
33 | 33 | import org.junit.jupiter.api.BeforeEach;
|
34 | 34 | import org.junit.jupiter.api.Nested;
|
35 | 35 | import org.junit.jupiter.api.Test;
|
| 36 | +import org.junit.jupiter.api.TestInstance; |
36 | 37 | import org.junit.jupiter.api.extension.ExtensionContext;
|
37 | 38 | import org.junit.jupiter.api.extension.ParameterContext;
|
38 | 39 | import org.junit.jupiter.api.extension.ParameterResolver;
|
@@ -198,7 +199,7 @@ void throwsExceptionWhenNonStaticFactoryMethodIsReferencedAndStaticIsRequired()
|
198 | 199 | var exception = assertThrows(JUnitException.class,
|
199 | 200 | () -> provideArguments(NonStaticTestCase.class, null, false, "nonStaticStringStreamProvider").toArray());
|
200 | 201 |
|
201 |
| - assertThat(exception).hasMessageContaining("Cannot invoke non-static method"); |
| 202 | + assertThat(exception).hasMessageContaining("method must not be static"); |
202 | 203 | }
|
203 | 204 |
|
204 | 205 | @Test
|
@@ -609,6 +610,9 @@ private Stream<Object[]> provideArguments(Class<?> testClass, Method testMethod,
|
609 | 610 | var testInstance = allowNonStaticMethod ? ReflectionUtils.newInstance(testClass) : null;
|
610 | 611 | when(extensionContext.getTestInstance()).thenReturn(Optional.ofNullable(testInstance));
|
611 | 612 |
|
| 613 | + var lifeCycle = allowNonStaticMethod ? TestInstance.Lifecycle.PER_CLASS : TestInstance.Lifecycle.PER_METHOD; |
| 614 | + when(extensionContext.getTestInstanceLifecycle()).thenReturn(Optional.of(lifeCycle)); |
| 615 | + |
612 | 616 | var provider = new MethodArgumentsProvider();
|
613 | 617 | provider.accept(methodSource);
|
614 | 618 | return provider.provideArguments(extensionContext).map(Arguments::get);
|
@@ -796,6 +800,13 @@ Stream<String> nonStaticStringStreamProvider() {
|
796 | 800 | }
|
797 | 801 | }
|
798 | 802 |
|
| 803 | + @TestInstance(TestInstance.Lifecycle.PER_METHOD) |
| 804 | + static class NonStaticTestCaseForPerMethodLifecycle { |
| 805 | + Stream<String> nonStaticStringStreamProvider() { |
| 806 | + return Stream.of("foo", "bar"); |
| 807 | + } |
| 808 | + } |
| 809 | + |
799 | 810 | static class ExternalFactoryMethods {
|
800 | 811 |
|
801 | 812 | static Stream<String> stringsProvider() {
|
|
0 commit comments