1010public class TelemetryTest {
1111
1212 @ Test
13- public void testCreatesEvaluationEventWithMandatoryFields () {
13+ void testCreatesEvaluationEventWithMandatoryFields () {
1414 // Arrange
1515 String flagKey = "test-flag" ;
1616 String providerName = "test-provider" ;
@@ -20,17 +20,15 @@ public void testCreatesEvaluationEventWithMandatoryFields() {
2020 when (providerMetadata .getName ()).thenReturn (providerName );
2121
2222 HookContext <Boolean > hookContext = HookContext .<Boolean >builder ()
23- .flagKey (flagKey )
24- .providerMetadata (providerMetadata )
25- .type (FlagValueType .BOOLEAN )
26- .defaultValue (false )
27- .ctx (new ImmutableContext ())
28- .build ();
29-
30- ProviderEvaluation <Boolean > evaluation = ProviderEvaluation .<Boolean >builder ()
31- .reason (reason )
32- .value (true )
33- .build ();
23+ .flagKey (flagKey )
24+ .providerMetadata (providerMetadata )
25+ .type (FlagValueType .BOOLEAN )
26+ .defaultValue (false )
27+ .ctx (new ImmutableContext ())
28+ .build ();
29+
30+ ProviderEvaluation <Boolean > evaluation =
31+ ProviderEvaluation .<Boolean >builder ().reason (reason ).value (true ).build ();
3432
3533 EvaluationEvent event = Telemetry .createEvaluationEvent (hookContext , evaluation );
3634
@@ -41,7 +39,7 @@ public void testCreatesEvaluationEventWithMandatoryFields() {
4139 }
4240
4341 @ Test
44- public void testHandlesNullReason () {
42+ void testHandlesNullReason () {
4543 // Arrange
4644 String flagKey = "test-flag" ;
4745 String providerName = "test-provider" ;
@@ -50,88 +48,86 @@ public void testHandlesNullReason() {
5048 when (providerMetadata .getName ()).thenReturn (providerName );
5149
5250 HookContext <Boolean > hookContext = HookContext .<Boolean >builder ()
53- .flagKey (flagKey )
54- .providerMetadata (providerMetadata )
55- .type (FlagValueType .BOOLEAN )
56- .defaultValue (false )
57- .ctx (new ImmutableContext ())
58- .build ();
59-
60- ProviderEvaluation <Boolean > evaluation = ProviderEvaluation .<Boolean >builder ()
61- .reason (null )
62- .value (true )
63- .build ();
51+ .flagKey (flagKey )
52+ .providerMetadata (providerMetadata )
53+ .type (FlagValueType .BOOLEAN )
54+ .defaultValue (false )
55+ .ctx (new ImmutableContext ())
56+ .build ();
57+
58+ ProviderEvaluation <Boolean > evaluation =
59+ ProviderEvaluation .<Boolean >builder ().reason (null ).value (true ).build ();
6460
6561 EvaluationEvent event = Telemetry .createEvaluationEvent (hookContext , evaluation );
6662
6763 assertEquals (Reason .UNKNOWN .name ().toLowerCase (), event .getAttributes ().get (Telemetry .TELEMETRY_REASON ));
6864 }
6965
7066 @ Test
71- public void testSetsVariantAttributeWhenVariantExists () {
67+ void testSetsVariantAttributeWhenVariantExists () {
7268 HookContext <String > hookContext = HookContext .<String >builder ()
73- .flagKey ("testFlag" )
74- .type (FlagValueType .STRING )
75- .defaultValue ("default" )
76- .ctx (mock (EvaluationContext .class ))
77- .clientMetadata (mock (ClientMetadata .class ))
78- .providerMetadata (mock (Metadata .class ))
79- .build ();
69+ .flagKey ("testFlag" )
70+ .type (FlagValueType .STRING )
71+ .defaultValue ("default" )
72+ .ctx (mock (EvaluationContext .class ))
73+ .clientMetadata (mock (ClientMetadata .class ))
74+ .providerMetadata (mock (Metadata .class ))
75+ .build ();
8076
8177 ProviderEvaluation <String > providerEvaluation = ProviderEvaluation .<String >builder ()
82- .variant ("testVariant" )
83- .flagMetadata (ImmutableMetadata .builder ().build ())
84- .build ();
78+ .variant ("testVariant" )
79+ .flagMetadata (ImmutableMetadata .builder ().build ())
80+ .build ();
8581
8682 EvaluationEvent event = Telemetry .createEvaluationEvent (hookContext , providerEvaluation );
8783
8884 assertEquals ("testVariant" , event .getAttributes ().get (Telemetry .TELEMETRY_VARIANT ));
8985 }
9086
9187 @ Test
92- public void test_sets_value_in_body_when_variant_is_null () {
88+ void test_sets_value_in_body_when_variant_is_null () {
9389 HookContext <String > hookContext = HookContext .<String >builder ()
94- .flagKey ("testFlag" )
95- .type (FlagValueType .STRING )
96- .defaultValue ("default" )
97- .ctx (mock (EvaluationContext .class ))
98- .clientMetadata (mock (ClientMetadata .class ))
99- .providerMetadata (mock (Metadata .class ))
100- .build ();
90+ .flagKey ("testFlag" )
91+ .type (FlagValueType .STRING )
92+ .defaultValue ("default" )
93+ .ctx (mock (EvaluationContext .class ))
94+ .clientMetadata (mock (ClientMetadata .class ))
95+ .providerMetadata (mock (Metadata .class ))
96+ .build ();
10197
10298 ProviderEvaluation <String > providerEvaluation = ProviderEvaluation .<String >builder ()
103- .value ("testValue" )
104- .flagMetadata (ImmutableMetadata .builder ().build ())
105- .build ();
99+ .value ("testValue" )
100+ .flagMetadata (ImmutableMetadata .builder ().build ())
101+ .build ();
106102
107103 EvaluationEvent event = Telemetry .createEvaluationEvent (hookContext , providerEvaluation );
108104
109105 assertEquals ("testValue" , event .getBody ().get (Telemetry .TELEMETRY_BODY ));
110106 }
111107
112108 @ Test
113- public void testAllFieldsPopulated () {
109+ void testAllFieldsPopulated () {
114110 EvaluationContext evaluationContext = mock (EvaluationContext .class );
115111 when (evaluationContext .getTargetingKey ()).thenReturn ("realTargetingKey" );
116112
117113 Metadata providerMetadata = mock (Metadata .class );
118114 when (providerMetadata .getName ()).thenReturn ("realProviderName" );
119115
120116 HookContext <String > hookContext = HookContext .<String >builder ()
121- .flagKey ("realFlag" )
122- .type (FlagValueType .STRING )
123- .defaultValue ("realDefault" )
124- .ctx (evaluationContext )
125- .clientMetadata (mock (ClientMetadata .class ))
126- .providerMetadata (providerMetadata )
127- .build ();
117+ .flagKey ("realFlag" )
118+ .type (FlagValueType .STRING )
119+ .defaultValue ("realDefault" )
120+ .ctx (evaluationContext )
121+ .clientMetadata (mock (ClientMetadata .class ))
122+ .providerMetadata (providerMetadata )
123+ .build ();
128124
129125 ProviderEvaluation <String > providerEvaluation = ProviderEvaluation .<String >builder ()
130126 .flagMetadata (ImmutableMetadata .builder ()
131- .addString ("contextId" , "realContextId" )
132- .addString ("flagSetId" , "realFlagSetId" )
133- .addString ("version" , "realVersion" )
134- .build ())
127+ .addString ("contextId" , "realContextId" )
128+ .addString ("flagSetId" , "realFlagSetId" )
129+ .addString ("version" , "realVersion" )
130+ .build ())
135131 .reason (Reason .DEFAULT .name ())
136132 .variant ("realVariant" )
137133 .build ();
@@ -146,11 +142,10 @@ public void testAllFieldsPopulated() {
146142 assertEquals ("realVersion" , event .getAttributes ().get (Telemetry .TELEMETRY_VERSION ));
147143 assertNull (event .getAttributes ().get (Telemetry .TELEMETRY_ERROR_CODE ));
148144 assertEquals ("realVariant" , event .getAttributes ().get (Telemetry .TELEMETRY_VARIANT ));
149-
150145 }
151146
152147 @ Test
153- public void testErrorEvaluation () {
148+ void testErrorEvaluation () {
154149 EvaluationContext evaluationContext = mock (EvaluationContext .class );
155150 when (evaluationContext .getTargetingKey ()).thenReturn ("realTargetingKey" );
156151
@@ -187,11 +182,10 @@ public void testErrorEvaluation() {
187182 assertEquals (ErrorCode .GENERAL , event .getAttributes ().get (Telemetry .TELEMETRY_ERROR_CODE ));
188183 assertEquals ("realErrorMessage" , event .getAttributes ().get (Telemetry .TELEMETRY_ERROR_MSG ));
189184 assertNull (event .getAttributes ().get (Telemetry .TELEMETRY_VARIANT ));
190-
191185 }
192186
193187 @ Test
194- public void testErrorCodeEvaluation () {
188+ void testErrorCodeEvaluation () {
195189 EvaluationContext evaluationContext = mock (EvaluationContext .class );
196190 when (evaluationContext .getTargetingKey ()).thenReturn ("realTargetingKey" );
197191
@@ -229,7 +223,5 @@ public void testErrorCodeEvaluation() {
229223 assertEquals (ErrorCode .INVALID_CONTEXT , event .getAttributes ().get (Telemetry .TELEMETRY_ERROR_CODE ));
230224 assertEquals ("realErrorMessage" , event .getAttributes ().get (Telemetry .TELEMETRY_ERROR_MSG ));
231225 assertNull (event .getAttributes ().get (Telemetry .TELEMETRY_VARIANT ));
232-
233226 }
234-
235227}
0 commit comments