4
4
import static org .assertj .core .api .Assertions .assertThatCode ;
5
5
import static org .assertj .core .api .Assertions .fail ;
6
6
import static org .junit .jupiter .api .Assertions .assertEquals ;
7
- import static org .junit .jupiter .api .Assertions .assertInstanceOf ;
8
7
import static org .junit .jupiter .api .Assertions .assertNotNull ;
9
8
import static org .junit .jupiter .api .Assertions .assertTrue ;
10
9
import static org .mockito .ArgumentMatchers .any ;
16
15
import static org .mockito .Mockito .verify ;
17
16
import static org .mockito .Mockito .when ;
18
17
19
- import dev .openfeature .sdk .exceptions .FlagNotFoundError ;
20
18
import dev .openfeature .sdk .fixtures .HookFixtures ;
21
19
import dev .openfeature .sdk .testutils .TestEventsProvider ;
22
20
import java .util .ArrayList ;
@@ -200,7 +198,7 @@ void error_hook_run_during_non_finally_stage() {
200
198
Hook h = mockBooleanHook ();
201
199
doThrow (RuntimeException .class ).when (h ).finallyAfter (any (), any (), any ());
202
200
203
- verify (h , times (0 )).error (any (), any (), any ());
201
+ verify (h , times (0 )).error (any (), any (Exception . class ), any ());
204
202
}
205
203
206
204
@ Test
@@ -225,16 +223,16 @@ void error_hook_must_run_if_resolution_details_returns_an_error_code() {
225
223
invocationCtx ,
226
224
FlagEvaluationOptions .builder ().hook (hook ).build ());
227
225
228
- ArgumentCaptor <Exception > captor = ArgumentCaptor .forClass (Exception .class );
226
+ ArgumentCaptor <ErrorDetails > captor = ArgumentCaptor .forClass (ErrorDetails .class );
229
227
230
228
verify (hook , times (1 )).before (any (), any ());
231
229
verify (hook , times (1 )).error (any (), captor .capture (), any ());
232
230
verify (hook , times (1 )).finallyAfter (any (), any (), any ());
233
231
verify (hook , never ()).after (any (), any (), any ());
234
232
235
- Exception exception = captor .getValue ();
236
- assertEquals (errorMessage , exception . getMessage ());
237
- assertInstanceOf ( FlagNotFoundError . class , exception );
233
+ ErrorDetails errorDetails = captor .getValue ();
234
+ assertEquals (errorMessage , errorDetails . getErrorMessage ());
235
+ assertEquals ( ErrorCode . FLAG_NOT_FOUND , errorDetails . getErrorCode () );
238
236
}
239
237
240
238
@ Specification (
@@ -279,7 +277,8 @@ public void after(
279
277
}
280
278
281
279
@ Override
282
- public void error (HookContext <Boolean > ctx , Exception error , Map <String , Object > hints ) {
280
+ public void error (
281
+ HookContext <Boolean > ctx , ErrorDetails <Boolean > error , Map <String , Object > hints ) {
283
282
evalOrder .add ("provider error" );
284
283
}
285
284
@@ -308,7 +307,7 @@ public void after(
308
307
}
309
308
310
309
@ Override
311
- public void error (HookContext <Boolean > ctx , Exception error , Map <String , Object > hints ) {
310
+ public void error (HookContext <Boolean > ctx , ErrorDetails < Boolean > error , Map <String , Object > hints ) {
312
311
evalOrder .add ("api error" );
313
312
}
314
313
@@ -334,7 +333,7 @@ public void after(
334
333
}
335
334
336
335
@ Override
337
- public void error (HookContext <Boolean > ctx , Exception error , Map <String , Object > hints ) {
336
+ public void error (HookContext <Boolean > ctx , ErrorDetails < Boolean > error , Map <String , Object > hints ) {
338
337
evalOrder .add ("client error" );
339
338
}
340
339
@@ -367,7 +366,8 @@ public void after(
367
366
}
368
367
369
368
@ Override
370
- public void error (HookContext <Boolean > ctx , Exception error , Map <String , Object > hints ) {
369
+ public void error (
370
+ HookContext <Boolean > ctx , ErrorDetails <Boolean > error , Map <String , Object > hints ) {
371
371
evalOrder .add ("invocation error" );
372
372
}
373
373
@@ -546,7 +546,7 @@ void error_hooks__before() {
546
546
new ImmutableContext (),
547
547
FlagEvaluationOptions .builder ().hook (hook ).build ());
548
548
verify (hook , times (1 )).before (any (), any ());
549
- verify (hook , times (1 )).error (any (), any (), any ());
549
+ verify (hook , times (1 )).error (any (), any (ErrorDetails . class ), any ());
550
550
assertEquals (false , value , "Falls through to the default." );
551
551
}
552
552
@@ -564,7 +564,7 @@ void error_hooks__after() {
564
564
new ImmutableContext (),
565
565
FlagEvaluationOptions .builder ().hook (hook ).build ());
566
566
verify (hook , times (1 )).after (any (), any (), any ());
567
- verify (hook , times (1 )).error (any (), any (), any ());
567
+ verify (hook , times (1 )).error (any (), any (ErrorDetails . class ), any ());
568
568
}
569
569
570
570
@ Test
@@ -609,7 +609,7 @@ void shortCircuit_flagResolution_runsHooksWithAllFields() {
609
609
FlagEvaluationOptions .builder ().hook (hook ).build ());
610
610
611
611
verify (hook ).before (any (), any ());
612
- verify (hook ).error (any (HookContext .class ), any (Exception .class ), any (Map .class ));
612
+ verify (hook ).error (any (HookContext .class ), any (ErrorDetails .class ), any (Map .class ));
613
613
verify (hook ).finallyAfter (any (HookContext .class ), any (FlagEvaluationDetails .class ), any (Map .class ));
614
614
}
615
615
@@ -655,8 +655,8 @@ void multi_hooks_early_out__before() {
655
655
verify (hook , times (1 )).before (any (), any ());
656
656
verify (hook2 , times (0 )).before (any (), any ());
657
657
658
- verify (hook , times (1 )).error (any (), any (), any ());
659
- verify (hook2 , times (1 )).error (any (), any (), any ());
658
+ verify (hook , times (1 )).error (any (), any (ErrorDetails . class ), any ());
659
+ verify (hook2 , times (1 )).error (any (), any (ErrorDetails . class ), any ());
660
660
}
661
661
662
662
@ Specification (number = "4.1.4" , text = "The evaluation context MUST be mutable only within the before hook." )
@@ -760,7 +760,7 @@ void first_finally_broken() {
760
760
void first_error_broken () {
761
761
Hook hook = mockBooleanHook ();
762
762
doThrow (RuntimeException .class ).when (hook ).before (any (), any ());
763
- doThrow (RuntimeException .class ).when (hook ).error (any (), any (), any ());
763
+ doThrow (RuntimeException .class ).when (hook ).error (any (), any (Exception . class ), any ());
764
764
Hook hook2 = mockBooleanHook ();
765
765
InOrder order = inOrder (hook , hook2 );
766
766
@@ -772,8 +772,8 @@ void first_error_broken() {
772
772
FlagEvaluationOptions .builder ().hook (hook2 ).hook (hook ).build ());
773
773
774
774
order .verify (hook ).before (any (), any ());
775
- order .verify (hook2 ).error (any (), any (), any ());
776
- order .verify (hook ).error (any (), any (), any ());
775
+ order .verify (hook2 ).error (any (), any (ErrorDetails . class ), any ());
776
+ order .verify (hook ).error (any (), any (ErrorDetails . class ), any ());
777
777
}
778
778
779
779
private Client getClient (FeatureProvider provider ) {
0 commit comments