@@ -469,7 +469,69 @@ public void getVariationForFeatureReturnsVariationFromExperimentBeforeRollout()
469469 );
470470 }
471471
472- //========== getVariationForFeatureInRollout tests ==========//
472+ /**
473+ * Verify that when getting a {@link Variation} for a {@link FeatureFlag} in
474+ * {@link DecisionService#getVariationForFeature(FeatureFlag, String, Map)},
475+ * check first if the user is bucketed to an {@link Rollout}
476+ * if the user is not bucketed to an experiment.
477+ */
478+ @ Test
479+ public void getVariationForFeatureReturnsVariationFromRolloutWhenExperimentFails () {
480+ FeatureFlag featureFlag = FEATURE_FLAG_MULTI_VARIATE_FEATURE ;
481+ Experiment featureExperiment = v4ProjectConfig .getExperimentIdMapping ().get (featureFlag .getExperimentIds ().get (0 ));
482+ assertNotNull (featureExperiment );
483+ Rollout featureRollout = v4ProjectConfig .getRolloutIdMapping ().get (featureFlag .getRolloutId ());
484+ Variation experimentVariation = featureExperiment .getVariations ().get (0 );
485+ Variation rolloutVariation = featureRollout .getExperiments ().get (0 ).getVariations ().get (0 );
486+
487+ DecisionService decisionService = spy (new DecisionService (
488+ mock (Bucketer .class ),
489+ mockErrorHandler ,
490+ v4ProjectConfig ,
491+ null
492+ )
493+ );
494+
495+ // return variation for experiment
496+ doReturn (null )
497+ .when (decisionService ).getVariation (
498+ eq (featureExperiment ),
499+ anyString (),
500+ anyMapOf (String .class , String .class )
501+ );
502+
503+ // return variation for rollout
504+ doReturn (rolloutVariation )
505+ .when (decisionService ).getVariationForFeatureInRollout (
506+ eq (featureFlag ),
507+ anyString (),
508+ anyMapOf (String .class , String .class )
509+ );
510+
511+ // make sure we get the right variation back
512+ assertEquals (rolloutVariation ,
513+ decisionService .getVariationForFeature (featureFlag ,
514+ genericUserId ,
515+ Collections .<String , String >emptyMap ()
516+ )
517+ );
518+
519+ // make sure we do not even check for rollout bucketing
520+ verify (decisionService ,times (1 )).getVariationForFeatureInRollout (
521+ any (FeatureFlag .class ),
522+ anyString (),
523+ anyMapOf (String .class , String .class )
524+ );
525+
526+ // make sure we ask for experiment bucketing once
527+ verify (decisionService , times (1 )).getVariation (
528+ any (Experiment .class ),
529+ anyString (),
530+ anyMapOf (String .class , String .class )
531+ );
532+ }
533+
534+ //========== getVariationForFeatureInRollout tests ==========//
473535
474536 /**
475537 * Verify that {@link DecisionService#getVariationForFeatureInRollout(FeatureFlag, String, Map)}
0 commit comments