@@ -878,7 +878,11 @@ public ConditionEvaluationResult evaluateExecutionCondition(ExtensionContext con
878
878
879
879
@ Override
880
880
public void postProcessTestInstance (ExtensionContext context ) {
881
- Object testInstance = context .getTestInstance ().orElse (null );
881
+ Object testInstance = context .getTestInstance ().orElseThrow (() -> {
882
+ IllegalStateException exception = new IllegalStateException ("test instance must not be null" );
883
+ exception .printStackTrace (System .err );
884
+ return exception ;
885
+ });
882
886
instanceMap .put (postProcessTestInstanceKey (context .getTestClass ().get ()), testInstance );
883
887
}
884
888
@@ -894,15 +898,25 @@ public void afterAll(ExtensionContext context) {
894
898
895
899
@ Override
896
900
public void beforeEach (ExtensionContext context ) {
901
+ Object testInstance = context .getTestInstance ().orElseThrow (() -> {
902
+ IllegalStateException exception = new IllegalStateException ("test instance must not be null" );
903
+ exception .printStackTrace (System .err );
904
+ return exception ;
905
+ });
897
906
instanceMap .put (
898
907
beforeEachCallbackKey (context .getTestClass ().get (), context .getTestMethod ().get ().getName ()),
899
- context . getTestInstance (). orElse ( null ) );
908
+ testInstance );
900
909
}
901
910
902
911
@ Override
903
912
public void afterEach (ExtensionContext context ) {
913
+ Object testInstance = context .getTestInstance ().orElseThrow (() -> {
914
+ IllegalStateException exception = new IllegalStateException ("test instance must not be null" );
915
+ exception .printStackTrace (System .err );
916
+ return exception ;
917
+ });
904
918
instanceMap .put (afterEachCallbackKey (context .getTestClass ().get (), context .getTestMethod ().get ().getName ()),
905
- context . getTestInstance (). orElse ( null ) );
919
+ testInstance );
906
920
}
907
921
908
922
@ Override
@@ -912,9 +926,13 @@ public boolean supportsTestTemplate(ExtensionContext context) {
912
926
913
927
@ Override
914
928
public Stream <TestTemplateInvocationContext > provideTestTemplateInvocationContexts (ExtensionContext context ) {
915
-
929
+ Object testInstance = context .getTestInstance ().orElseThrow (() -> {
930
+ IllegalStateException exception = new IllegalStateException ("test instance must not be null" );
931
+ exception .printStackTrace (System .err );
932
+ return exception ;
933
+ });
916
934
instanceMap .put (testTemplateKey (context .getTestClass ().get (), context .getTestMethod ().get ().getName ()),
917
- context . getTestInstance (). orElse ( null ) );
935
+ testInstance );
918
936
919
937
return Stream .of (new TestTemplateInvocationContext () {
920
938
});
0 commit comments