forked from open-feature/java-sdk
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMockHook.java
50 lines (40 loc) · 1.27 KB
/
MockHook.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
package dev.openfeature.sdk.e2e;
import dev.openfeature.sdk.EvaluationContext;
import dev.openfeature.sdk.FlagEvaluationDetails;
import dev.openfeature.sdk.Hook;
import dev.openfeature.sdk.HookContext;
import java.util.HashMap;
import java.util.Map;
import java.util.Optional;
import lombok.Getter;
public class MockHook implements Hook {
@Getter
private boolean beforeCalled;
@Getter
private boolean afterCalled;
@Getter
private boolean errorCalled;
@Getter
private boolean finallyAfterCalled;
@Getter
private final Map<String, FlagEvaluationDetails> evaluationDetails = new HashMap<>();
@Override
public Optional<EvaluationContext> before(HookContext ctx, Map hints) {
beforeCalled = true;
return Optional.of(ctx.getCtx());
}
@Override
public void after(HookContext ctx, FlagEvaluationDetails details, Map hints) {
afterCalled = true;
evaluationDetails.put("after", details);
}
@Override
public void error(HookContext ctx, Exception error, Map hints) {
errorCalled = true;
}
@Override
public void finallyAfter(HookContext ctx, FlagEvaluationDetails details, Map hints) {
finallyAfterCalled = true;
evaluationDetails.put("finally", details);
}
}