2
2
3
3
import static org .junit .jupiter .api .Assertions .assertEquals ;
4
4
import static org .junit .jupiter .api .Assertions .assertNull ;
5
- import static org .mockito .Mockito .mock ;
6
- import static org .mockito .Mockito .when ;
7
-
8
5
import org .junit .jupiter .api .Test ;
6
+ import java .util .Collections ;
7
+ import java .util .Map ;
9
8
10
9
public class TelemetryTest {
11
10
11
+ String flagKey = "test-flag" ;
12
+ String providerName = "test-provider" ;
13
+ String reason = "static" ;
14
+ Metadata providerMetadata = () -> providerName ;
15
+
12
16
@ Test
13
17
void testCreatesEvaluationEventWithMandatoryFields () {
14
- // Arrange
15
- String flagKey = "test-flag" ;
16
- String providerName = "test-provider" ;
17
- String reason = "static" ;
18
-
19
- Metadata providerMetadata = Mockito .mock (Metadata .class );
20
- Mockito .when (providerMetadata .getName ()).thenReturn (providerName );
21
-
22
18
HookContext <Boolean > hookContext = HookContext .<Boolean >builder ()
23
19
.flagKey (flagKey )
24
20
.providerMetadata (providerMetadata )
@@ -42,13 +38,6 @@ void testCreatesEvaluationEventWithMandatoryFields() {
42
38
43
39
@ Test
44
40
void testHandlesNullReason () {
45
- // Arrange
46
- String flagKey = "test-flag" ;
47
- String providerName = "test-provider" ;
48
-
49
- Metadata providerMetadata = Mockito .mock (Metadata .class );
50
- Mockito .when (providerMetadata .getName ()).thenReturn (providerName );
51
-
52
41
HookContext <Boolean > hookContext = HookContext .<Boolean >builder ()
53
42
.flagKey (flagKey )
54
43
.providerMetadata (providerMetadata )
@@ -73,9 +62,9 @@ void testSetsVariantAttributeWhenVariantExists() {
73
62
.flagKey ("testFlag" )
74
63
.type (FlagValueType .STRING )
75
64
.defaultValue ("default" )
76
- .ctx (Mockito . mock ( EvaluationContext .class ) )
77
- .clientMetadata (Mockito . mock ( ClientMetadata . class ) )
78
- .providerMetadata (Mockito . mock ( Metadata . class ) )
65
+ .ctx (EvaluationContext .EMPTY )
66
+ .clientMetadata (() -> "" )
67
+ .providerMetadata (providerMetadata )
79
68
.build ();
80
69
81
70
FlagEvaluationDetails <String > providerEvaluation = FlagEvaluationDetails .<String >builder ()
@@ -94,9 +83,9 @@ void test_sets_value_in_body_when_variant_is_null() {
94
83
.flagKey ("testFlag" )
95
84
.type (FlagValueType .STRING )
96
85
.defaultValue ("default" )
97
- .ctx (Mockito . mock ( EvaluationContext .class ) )
98
- .clientMetadata (Mockito . mock ( ClientMetadata . class ) )
99
- .providerMetadata (Mockito . mock ( Metadata . class ) )
86
+ .ctx (EvaluationContext .EMPTY )
87
+ .clientMetadata (() -> "" )
88
+ .providerMetadata (providerMetadata )
100
89
.build ();
101
90
102
91
FlagEvaluationDetails <String > providerEvaluation = FlagEvaluationDetails .<String >builder ()
@@ -111,19 +100,13 @@ void test_sets_value_in_body_when_variant_is_null() {
111
100
112
101
@ Test
113
102
void testAllFieldsPopulated () {
114
- EvaluationContext evaluationContext = Mockito .mock (EvaluationContext .class );
115
- Mockito .when (evaluationContext .getTargetingKey ()).thenReturn ("realTargetingKey" );
116
-
117
- Metadata providerMetadata = Mockito .mock (Metadata .class );
118
- Mockito .when (providerMetadata .getName ()).thenReturn ("realProviderName" );
119
-
120
103
HookContext <String > hookContext = HookContext .<String >builder ()
121
104
.flagKey ("realFlag" )
122
105
.type (FlagValueType .STRING )
123
106
.defaultValue ("realDefault" )
124
- .ctx (evaluationContext )
125
- .clientMetadata (Mockito . mock ( ClientMetadata . class ) )
126
- .providerMetadata (providerMetadata )
107
+ .ctx (new ImmutableContext ( "realTargetingKey" , Map . of ()) )
108
+ .clientMetadata (() -> "" )
109
+ .providerMetadata (()-> "realProviderName" )
127
110
.build ();
128
111
129
112
FlagEvaluationDetails <String > providerEvaluation = FlagEvaluationDetails .<String >builder ()
@@ -150,19 +133,13 @@ void testAllFieldsPopulated() {
150
133
151
134
@ Test
152
135
void testErrorEvaluation () {
153
- EvaluationContext evaluationContext = Mockito .mock (EvaluationContext .class );
154
- Mockito .when (evaluationContext .getTargetingKey ()).thenReturn ("realTargetingKey" );
155
-
156
- Metadata providerMetadata = Mockito .mock (Metadata .class );
157
- Mockito .when (providerMetadata .getName ()).thenReturn ("realProviderName" );
158
-
159
136
HookContext <String > hookContext = HookContext .<String >builder ()
160
137
.flagKey ("realFlag" )
161
138
.type (FlagValueType .STRING )
162
139
.defaultValue ("realDefault" )
163
- .ctx (evaluationContext )
164
- .clientMetadata (Mockito . mock ( ClientMetadata . class ) )
165
- .providerMetadata (providerMetadata )
140
+ .ctx (new ImmutableContext ( "realTargetingKey" , Map . of ()) )
141
+ .clientMetadata (() -> "" )
142
+ .providerMetadata (()-> "realProviderName" )
166
143
.build ();
167
144
168
145
FlagEvaluationDetails <String > providerEvaluation = FlagEvaluationDetails .<String >builder ()
@@ -190,19 +167,13 @@ void testErrorEvaluation() {
190
167
191
168
@ Test
192
169
void testErrorCodeEvaluation () {
193
- EvaluationContext evaluationContext = Mockito .mock (EvaluationContext .class );
194
- Mockito .when (evaluationContext .getTargetingKey ()).thenReturn ("realTargetingKey" );
195
-
196
- Metadata providerMetadata = Mockito .mock (Metadata .class );
197
- Mockito .when (providerMetadata .getName ()).thenReturn ("realProviderName" );
198
-
199
170
HookContext <String > hookContext = HookContext .<String >builder ()
200
171
.flagKey ("realFlag" )
201
172
.type (FlagValueType .STRING )
202
173
.defaultValue ("realDefault" )
203
- .ctx (evaluationContext )
204
- .clientMetadata (Mockito . mock ( ClientMetadata . class ) )
205
- .providerMetadata (providerMetadata )
174
+ .ctx (new ImmutableContext ( "realTargetingKey" , Map . of ()) )
175
+ .clientMetadata (() -> "" )
176
+ .providerMetadata (()-> "realProviderName" )
206
177
.build ();
207
178
208
179
FlagEvaluationDetails <String > providerEvaluation = FlagEvaluationDetails .<String >builder ()
0 commit comments