11package com .baeldung .jupiter ;
22
3- import org .junit .jupiter .api .extension .*;
3+ import java .lang .reflect .Constructor ;
4+ import java .lang .reflect .Executable ;
5+ import java .lang .reflect .Method ;
6+ import java .lang .reflect .Parameter ;
7+
8+ import org .junit .jupiter .api .extension .AfterAllCallback ;
9+ import org .junit .jupiter .api .extension .AfterEachCallback ;
10+ import org .junit .jupiter .api .extension .BeforeAllCallback ;
11+ import org .junit .jupiter .api .extension .BeforeEachCallback ;
12+ import org .junit .jupiter .api .extension .ExtensionContext ;
13+ import org .junit .jupiter .api .extension .ParameterContext ;
14+ import org .junit .jupiter .api .extension .ParameterResolutionException ;
15+ import org .junit .jupiter .api .extension .ParameterResolver ;
16+ import org .junit .jupiter .api .extension .TestInstancePostProcessor ;
417import org .springframework .beans .factory .annotation .Autowired ;
518import org .springframework .context .ApplicationContext ;
619import org .springframework .core .annotation .AnnotatedElementUtils ;
720import org .springframework .test .context .TestContextManager ;
821import org .springframework .util .Assert ;
922
10- import java .lang .reflect .Constructor ;
11- import java .lang .reflect .Executable ;
12- import java .lang .reflect .Method ;
13- import java .lang .reflect .Parameter ;
14-
1523public class SpringExtension implements BeforeAllCallback , AfterAllCallback , TestInstancePostProcessor , BeforeEachCallback , AfterEachCallback , ParameterResolver {
1624
1725 private static final ExtensionContext .Namespace namespace = ExtensionContext .Namespace .create (SpringExtension .class );
1826
1927 @ Override
20- public void beforeAll (ContainerExtensionContext context ) throws Exception {
28+ public void beforeAll (ExtensionContext context ) throws Exception {
2129 getTestContextManager (context ).beforeTestClass ();
2230 }
2331
2432 @ Override
25- public void afterAll (ContainerExtensionContext context ) throws Exception {
33+ public void afterAll (ExtensionContext context ) throws Exception {
2634 try {
2735 getTestContextManager (context ).afterTestClass ();
2836 } finally {
@@ -38,32 +46,32 @@ public void postProcessTestInstance(Object testInstance, ExtensionContext contex
3846 }
3947
4048 @ Override
41- public void beforeEach (TestExtensionContext context ) throws Exception {
49+ public void beforeEach (ExtensionContext context ) throws Exception {
4250 Object testInstance = context .getTestInstance ();
4351 Method testMethod = context .getTestMethod ()
4452 .get ();
4553 getTestContextManager (context ).beforeTestMethod (testInstance , testMethod );
4654 }
4755
4856 @ Override
49- public void afterEach (TestExtensionContext context ) throws Exception {
57+ public void afterEach (ExtensionContext context ) throws Exception {
5058 Object testInstance = context .getTestInstance ();
5159 Method testMethod = context .getTestMethod ()
5260 .get ();
53- Throwable testException = context .getTestException ()
61+ Throwable testException = context .getExecutionException ()
5462 .orElse (null );
5563 getTestContextManager (context ).afterTestMethod (testInstance , testMethod , testException );
5664 }
5765
5866 @ Override
59- public boolean supports (ParameterContext parameterContext , ExtensionContext extensionContext ) {
67+ public boolean supportsParameter (ParameterContext parameterContext , ExtensionContext extensionContext ) throws ParameterResolutionException {
6068 Parameter parameter = parameterContext .getParameter ();
6169 Executable executable = parameter .getDeclaringExecutable ();
62- return (executable instanceof Constructor && AnnotatedElementUtils .hasAnnotation (executable , Autowired .class )) || ParameterAutowireUtils .isAutowirable (parameter );
70+ return (( executable instanceof Constructor ) && AnnotatedElementUtils .hasAnnotation (executable , Autowired .class )) || ParameterAutowireUtils .isAutowirable (parameter );
6371 }
6472
6573 @ Override
66- public Object resolve (ParameterContext parameterContext , ExtensionContext extensionContext ) {
74+ public Object resolveParameter (ParameterContext parameterContext , ExtensionContext extensionContext ) throws ParameterResolutionException {
6775 Parameter parameter = parameterContext .getParameter ();
6876 Class <?> testClass = extensionContext .getTestClass ()
6977 .get ();
0 commit comments