@@ -353,12 +353,8 @@ private static List<TestCase<?>> evaluateTestCases() {
353353 new Result <>("tracked-value" )
354354 .reason (TARGETING_MATCH .name ())
355355 .variant ("tracked" )
356- .flagMetadata ("allocationKey" , "exposure-alloc" )),
357- new TestCase <>("default" )
358- .flag ("double-comparison-flag" )
359- .targetingKey ("user-123" )
360- .context ("score" , 3.14159 )
361- .result (new Result <>("exact-match" ).reason (TARGETING_MATCH .name ()).variant ("exact" )),
356+ .flagMetadata ("allocationKey" , "exposure-alloc" )
357+ .flagMetadata ("doLog" , true )),
362358 new TestCase <>("default" )
363359 .flag ("exposure-logging-flag" )
364360 .targetingKey ("user-exposure" )
@@ -367,7 +363,13 @@ private static List<TestCase<?>> evaluateTestCases() {
367363 new Result <>("logged-value" )
368364 .reason (TARGETING_MATCH .name ())
369365 .variant ("logged" )
370- .flagMetadata ("allocationKey" , "logged-alloc" )),
366+ .flagMetadata ("allocationKey" , "logged-alloc" )
367+ .flagMetadata ("doLog" , true )),
368+ new TestCase <>("default" )
369+ .flag ("double-comparison-flag" )
370+ .targetingKey ("user-123" )
371+ .context ("score" , 3.14159 )
372+ .result (new Result <>("exact-match" ).reason (TARGETING_MATCH .name ()).variant ("exact" )),
371373 new TestCase <>("default" )
372374 .flag ("numeric-one-of-flag" )
373375 .targetingKey ("user-123" )
@@ -484,12 +486,16 @@ public <E> void testEvaluate(final TestCase<E> testCase) {
484486 assertThat (details .getReason (), oneOf (expected .reason ));
485487 assertThat (details .getVariant (), equalTo (expected .variant ));
486488 assertThat (details .getErrorCode (), equalTo (expected .errorCode ));
487- if (details .getFlagMetadata ().getString ("allocationKey" ) != null ) {
489+ assertThat (details .getErrorCode (), equalTo (expected .errorCode ));
490+ final String expectedAllocation = (String ) expected .flagMetadata .get ("allocationKey" );
491+ if (expectedAllocation != null ) {
492+ assertThat (details .getFlagMetadata ().getString ("allocationKey" ), equalTo (expectedAllocation ));
493+ }
494+ if (shouldDispatchExposure (expected )) {
488495 verify (exposureListener , times (1 )).accept (exposureEventCaptor .capture ());
489496 final ExposureEvent capturedEvent = exposureEventCaptor .getValue ();
490497 assertThat (capturedEvent .flag .key , equalTo (testCase .flag ));
491- assertThat (
492- capturedEvent .allocation .key , equalTo (testCase .result .flagMetadata .get ("allocationKey" )));
498+ assertThat (capturedEvent .allocation .key , equalTo (expectedAllocation ));
493499 assertThat (capturedEvent .variant .key , equalTo (testCase .result .variant ));
494500 assertThat (capturedEvent .subject .id , equalTo (testCase .context .getTargetingKey ()));
495501 for (final Map .Entry <String , Object > entry : testCase .context .asObjectMap ().entrySet ()) {
@@ -500,6 +506,11 @@ public <E> void testEvaluate(final TestCase<E> testCase) {
500506 }
501507 }
502508
509+ private static boolean shouldDispatchExposure (final Result <?> result ) {
510+ final Boolean doLog = (Boolean ) result .flagMetadata .get ("doLog" );
511+ return doLog != null && doLog ;
512+ }
513+
503514 private ServerConfiguration createTestConfiguration () {
504515 final Map <String , Flag > flags = new HashMap <>();
505516 flags .put (
@@ -526,8 +537,8 @@ private ServerConfiguration createTestConfiguration() {
526537 flags .put ("double-equals-flag" , createDoubleEqualsFlag ());
527538 flags .put ("nested-attr-flag" , createNestedAttributeFlag ());
528539 flags .put ("exposure-flag" , createExposureFlag ());
529- flags .put ("double-comparison-flag" , createDoubleComparisonFlag ());
530540 flags .put ("exposure-logging-flag" , createExposureLoggingFlag ());
541+ flags .put ("double-comparison-flag" , createDoubleComparisonFlag ());
531542 flags .put ("numeric-one-of-flag" , createNumericOneOfFlag ());
532543 flags .put ("numeric-not-one-of-flag" , createNumericNotOneOfFlag ());
533544 flags .put ("is-null-false-flag" , createIsNullFalseFlag ());
0 commit comments