Search in sources :

Example 16 with FeatureDecision

use of com.optimizely.ab.bucketing.FeatureDecision in project java-sdk by optimizely.

the class OptimizelyTest method isFeatureEnabledReturnsFalseWhenUserIsNotBucketedIntoAnyVariation.

/**
 * Verify {@link Optimizely#isFeatureEnabled(String, String)} calls into
 * {@link Optimizely#isFeatureEnabled(String, String, Map)} and they both
 * return False
 * when the user is not bucketed into any variation for the feature.
 */
@Test
public void isFeatureEnabledReturnsFalseWhenUserIsNotBucketedIntoAnyVariation() throws Exception {
    assumeTrue(datafileVersion >= Integer.parseInt(ProjectConfig.Version.V4.toString()));
    String validFeatureKey = FEATURE_MULTI_VARIATE_FEATURE_KEY;
    Optimizely optimizely = optimizelyBuilder.withDecisionService(mockDecisionService).build();
    FeatureDecision featureDecision = new FeatureDecision(null, null, null);
    doReturn(DecisionResponse.responseNoReasons(featureDecision)).when(mockDecisionService).getVariationForFeature(any(FeatureFlag.class), any(OptimizelyUserContext.class), any(ProjectConfig.class));
    assertFalse(optimizely.isFeatureEnabled(validFeatureKey, genericUserId));
    logbackVerifier.expectMessage(Level.INFO, "Feature \"" + validFeatureKey + "\" is enabled for user \"" + genericUserId + "\"? false");
    eventHandler.expectImpression(null, "", genericUserId);
    verify(mockDecisionService).getVariationForFeature(eq(FEATURE_FLAG_MULTI_VARIATE_FEATURE), eq(optimizely.createUserContext(genericUserId, Collections.emptyMap())), eq(validProjectConfig));
}
Also used : FeatureDecision(com.optimizely.ab.bucketing.FeatureDecision) Test(org.junit.Test)

Aggregations

FeatureDecision (com.optimizely.ab.bucketing.FeatureDecision)16 Test (org.junit.Test)10 OptimizelyJSON (com.optimizely.ab.optimizelyjson.OptimizelyJSON)3 VisibleForTesting (com.optimizely.ab.annotations.VisibleForTesting)2 FeatureFlag (com.optimizely.ab.config.FeatureFlag)2 LiveVariable (com.optimizely.ab.config.LiveVariable)2 Nonnull (javax.annotation.Nonnull)2 Experiment (com.optimizely.ab.config.Experiment)1 LiveVariableUsageInstance (com.optimizely.ab.config.LiveVariableUsageInstance)1 Nullable (javax.annotation.Nullable)1 Matchers.anyString (org.mockito.Matchers.anyString)1