@@ -56,6 +56,9 @@ public void swapDelivery() {
5656 originalSessionDelivery = bugsnag .getSessionDelivery ();
5757 sessionDelivery = new StubSessionDelivery ();
5858 bugsnag .setSessionDelivery (sessionDelivery );
59+
60+ // Clear any feature flags from previous tests
61+ appender .clearFeatureFlags ();
5962 }
6063
6164 /**
@@ -414,4 +417,98 @@ private SessionTracker getSessionTracker(Bugsnag bugsnag) {
414417 private Map <String , Object > getMetadataMap (Notification notification , String key ) {
415418 return ((Map <String , Object >) notification .getEvents ().get (0 ).getMetadata ().get (key ));
416419 }
420+
421+ @ Test
422+ public void testFeatureFlagConfiguration () {
423+ // Add feature flags programmatically (XML configuration will be tested separately)
424+ appender .addFeatureFlag ("sample_group" , "a" );
425+ appender .addFeatureFlag ("another_feature" );
426+
427+ // Send a log message
428+ LOGGER .warn ("Exception with feature flags" , new RuntimeException ("test" ));
429+
430+ // Check that a report was sent to Bugsnag
431+ assertEquals (1 , delivery .getNotifications ().size ());
432+
433+ Notification notification = delivery .getNotifications ().get (0 );
434+ List <FeatureFlag > featureFlags = notification .getEvents ().get (0 ).getFeatureFlags ();
435+
436+ // Check that feature flags are present
437+ assertEquals (2 , featureFlags .size ());
438+
439+ // Check first feature flag
440+ assertEquals ("sample_group" , featureFlags .get (0 ).getName ());
441+ assertEquals ("a" , featureFlags .get (0 ).getVariant ());
442+
443+ // Check second feature flag
444+ assertEquals ("another_feature" , featureFlags .get (1 ).getName ());
445+ assertEquals (null , featureFlags .get (1 ).getVariant ());
446+ }
447+
448+ @ Test
449+ public void testAddFeatureFlagProgrammatically () {
450+ // Add a feature flag programmatically
451+ appender .addFeatureFlag ("runtime_feature" , "variant_b" );
452+
453+ // Send a log message
454+ LOGGER .warn ("Exception with runtime feature flag" , new RuntimeException ("test" ));
455+
456+ // Check that a report was sent to Bugsnag
457+ assertEquals (1 , delivery .getNotifications ().size ());
458+
459+ Notification notification = delivery .getNotifications ().get (0 );
460+ List <FeatureFlag > featureFlags = notification .getEvents ().get (0 ).getFeatureFlags ();
461+
462+ // Should have 1 programmatic feature flag
463+ assertEquals (1 , featureFlags .size ());
464+
465+ // Check the programmatically added flag is present
466+ assertEquals ("runtime_feature" , featureFlags .get (0 ).getName ());
467+ assertEquals ("variant_b" , featureFlags .get (0 ).getVariant ());
468+ }
469+
470+ @ Test
471+ public void testClearFeatureFlag () {
472+ // Add some feature flags first
473+ appender .addFeatureFlag ("sample_group" , "a" );
474+ appender .addFeatureFlag ("another_feature" );
475+
476+ // Clear a specific feature flag
477+ appender .clearFeatureFlag ("sample_group" );
478+
479+ // Send a log message
480+ LOGGER .warn ("Exception after clearing feature flag" , new RuntimeException ("test" ));
481+
482+ // Check that a report was sent to Bugsnag
483+ assertEquals (1 , delivery .getNotifications ().size ());
484+
485+ Notification notification = delivery .getNotifications ().get (0 );
486+ List <FeatureFlag > featureFlags = notification .getEvents ().get (0 ).getFeatureFlags ();
487+
488+ // Should only have 1 feature flag (another_feature) remaining
489+ assertEquals (1 , featureFlags .size ());
490+ assertEquals ("another_feature" , featureFlags .get (0 ).getName ());
491+ }
492+
493+ @ Test
494+ public void testClearAllFeatureFlags () {
495+ // Add some feature flags first
496+ appender .addFeatureFlag ("sample_group" , "a" );
497+ appender .addFeatureFlag ("another_feature" );
498+
499+ // Clear all feature flags
500+ appender .clearFeatureFlags ();
501+
502+ // Send a log message
503+ LOGGER .warn ("Exception after clearing all feature flags" , new RuntimeException ("test" ));
504+
505+ // Check that a report was sent to Bugsnag
506+ assertEquals (1 , delivery .getNotifications ().size ());
507+
508+ Notification notification = delivery .getNotifications ().get (0 );
509+ List <FeatureFlag > featureFlags = notification .getEvents ().get (0 ).getFeatureFlags ();
510+
511+ // Should have no feature flags
512+ assertEquals (0 , featureFlags .size ());
513+ }
417514}
0 commit comments