@@ -2467,6 +2467,294 @@ public void getFeatureVariableStringReturnsWhatInternalReturns() throws ConfigPa
24672467 ));
24682468 }
24692469
2470+ /**
2471+ * Verify {@link Optimizely#getFeatureVariableBoolean(String, String, String)}
2472+ * calls through to {@link Optimizely#getFeatureVariableBoolean(String, String, String, Map<String, String>)}
2473+ * and returns null
2474+ * when {@link Optimizely#getFeatureVariableValueForType(String, String, String, Map, LiveVariable.VariableType)}
2475+ * returns null
2476+ * @throws ConfigParseException
2477+ */
2478+ @ Test
2479+ public void getFeatureVariableBooleanReturnsNullFromInternal () throws ConfigParseException {
2480+ String featureKey = "featureKey" ;
2481+ String variableKey = "variableKey" ;
2482+
2483+ Optimizely spyOptimizely = spy (Optimizely .builder (validDatafile , mockEventHandler )
2484+ .withConfig (validProjectConfig )
2485+ .build ());
2486+
2487+ doReturn (null ).when (spyOptimizely ).getFeatureVariableValueForType (
2488+ eq (featureKey ),
2489+ eq (variableKey ),
2490+ eq (genericUserId ),
2491+ eq (Collections .<String , String >emptyMap ()),
2492+ eq (LiveVariable .VariableType .BOOLEAN )
2493+ );
2494+
2495+ assertNull (spyOptimizely .getFeatureVariableBoolean (
2496+ featureKey ,
2497+ variableKey ,
2498+ genericUserId
2499+ ));
2500+
2501+ verify (spyOptimizely ).getFeatureVariableBoolean (
2502+ eq (featureKey ),
2503+ eq (variableKey ),
2504+ eq (genericUserId ),
2505+ eq (Collections .<String , String >emptyMap ())
2506+ );
2507+ }
2508+
2509+ /**
2510+ * Verify {@link Optimizely#getFeatureVariableBoolean(String, String, String)}
2511+ * calls through to {@link Optimizely#getFeatureVariableBoolean(String, String, String, Map)}
2512+ * and both return a Boolean representation of the value returned from
2513+ * {@link Optimizely#getFeatureVariableValueForType(String, String, String, Map, LiveVariable.VariableType)}.
2514+ * @throws ConfigParseException
2515+ */
2516+ @ Test
2517+ public void getFeatureVariableBooleanReturnsWhatInternalReturns () throws ConfigParseException {
2518+ String featureKey = "featureKey" ;
2519+ String variableKey = "variableKey" ;
2520+ Boolean valueNoAttributes = false ;
2521+ Boolean valueWithAttributes = true ;
2522+ Map <String , String > attributes = Collections .singletonMap ("key" , "value" );
2523+
2524+ Optimizely spyOptimizely = spy (Optimizely .builder (validDatafile , mockEventHandler )
2525+ .withConfig (validProjectConfig )
2526+ .build ());
2527+
2528+
2529+ doReturn (valueNoAttributes .toString ()).when (spyOptimizely ).getFeatureVariableValueForType (
2530+ eq (featureKey ),
2531+ eq (variableKey ),
2532+ eq (genericUserId ),
2533+ eq (Collections .<String , String >emptyMap ()),
2534+ eq (LiveVariable .VariableType .BOOLEAN )
2535+ );
2536+
2537+ doReturn (valueWithAttributes .toString ()).when (spyOptimizely ).getFeatureVariableValueForType (
2538+ eq (featureKey ),
2539+ eq (variableKey ),
2540+ eq (genericUserId ),
2541+ eq (attributes ),
2542+ eq (LiveVariable .VariableType .BOOLEAN )
2543+ );
2544+
2545+ assertEquals (valueNoAttributes , spyOptimizely .getFeatureVariableBoolean (
2546+ featureKey ,
2547+ variableKey ,
2548+ genericUserId
2549+ ));
2550+
2551+ verify (spyOptimizely ).getFeatureVariableBoolean (
2552+ eq (featureKey ),
2553+ eq (variableKey ),
2554+ eq (genericUserId ),
2555+ eq (Collections .<String , String >emptyMap ())
2556+ );
2557+
2558+ assertEquals (valueWithAttributes , spyOptimizely .getFeatureVariableBoolean (
2559+ featureKey ,
2560+ variableKey ,
2561+ genericUserId ,
2562+ attributes
2563+ ));
2564+ }
2565+
2566+ /**
2567+ * Verify {@link Optimizely#getFeatureVariableDouble(String, String, String)}
2568+ * calls through to {@link Optimizely#getFeatureVariableDouble(String, String, String, Map<String, String>)}
2569+ * and returns null
2570+ * when {@link Optimizely#getFeatureVariableValueForType(String, String, String, Map, LiveVariable.VariableType)}
2571+ * returns null
2572+ * @throws ConfigParseException
2573+ */
2574+ @ Test
2575+ public void getFeatureVariableDoubleReturnsNullFromInternal () throws ConfigParseException {
2576+ String featureKey = "featureKey" ;
2577+ String variableKey = "variableKey" ;
2578+
2579+ Optimizely spyOptimizely = spy (Optimizely .builder (validDatafile , mockEventHandler )
2580+ .withConfig (validProjectConfig )
2581+ .build ());
2582+
2583+ doReturn (null ).when (spyOptimizely ).getFeatureVariableValueForType (
2584+ eq (featureKey ),
2585+ eq (variableKey ),
2586+ eq (genericUserId ),
2587+ eq (Collections .<String , String >emptyMap ()),
2588+ eq (LiveVariable .VariableType .DOUBLE )
2589+ );
2590+
2591+ assertNull (spyOptimizely .getFeatureVariableDouble (
2592+ featureKey ,
2593+ variableKey ,
2594+ genericUserId
2595+ ));
2596+
2597+ verify (spyOptimizely ).getFeatureVariableDouble (
2598+ eq (featureKey ),
2599+ eq (variableKey ),
2600+ eq (genericUserId ),
2601+ eq (Collections .<String , String >emptyMap ())
2602+ );
2603+ }
2604+
2605+ /**
2606+ * Verify {@link Optimizely#getFeatureVariableDouble(String, String, String)}
2607+ * calls through to {@link Optimizely#getFeatureVariableDouble(String, String, String, Map)}
2608+ * and both return the parsed Double from the value returned from
2609+ * {@link Optimizely#getFeatureVariableValueForType(String, String, String, Map, LiveVariable.VariableType)}.
2610+ * @throws ConfigParseException
2611+ */
2612+ @ Test
2613+ public void getFeatureVariableDoubleReturnsWhatInternalReturns () throws ConfigParseException {
2614+ String featureKey = "featureKey" ;
2615+ String variableKey = "variableKey" ;
2616+ Double valueNoAttributes = 0.1 ;
2617+ Double valueWithAttributes = 0.2 ;
2618+ Map <String , String > attributes = Collections .singletonMap ("key" , "value" );
2619+
2620+ Optimizely spyOptimizely = spy (Optimizely .builder (validDatafile , mockEventHandler )
2621+ .withConfig (validProjectConfig )
2622+ .build ());
2623+
2624+
2625+ doReturn (valueNoAttributes .toString ()).when (spyOptimizely ).getFeatureVariableValueForType (
2626+ eq (featureKey ),
2627+ eq (variableKey ),
2628+ eq (genericUserId ),
2629+ eq (Collections .<String , String >emptyMap ()),
2630+ eq (LiveVariable .VariableType .DOUBLE )
2631+ );
2632+
2633+ doReturn (valueWithAttributes .toString ()).when (spyOptimizely ).getFeatureVariableValueForType (
2634+ eq (featureKey ),
2635+ eq (variableKey ),
2636+ eq (genericUserId ),
2637+ eq (attributes ),
2638+ eq (LiveVariable .VariableType .DOUBLE )
2639+ );
2640+
2641+ assertEquals (valueNoAttributes , spyOptimizely .getFeatureVariableDouble (
2642+ featureKey ,
2643+ variableKey ,
2644+ genericUserId
2645+ ));
2646+
2647+ verify (spyOptimizely ).getFeatureVariableDouble (
2648+ eq (featureKey ),
2649+ eq (variableKey ),
2650+ eq (genericUserId ),
2651+ eq (Collections .<String , String >emptyMap ())
2652+ );
2653+
2654+ assertEquals (valueWithAttributes , spyOptimizely .getFeatureVariableDouble (
2655+ featureKey ,
2656+ variableKey ,
2657+ genericUserId ,
2658+ attributes
2659+ ));
2660+ }
2661+
2662+ /**
2663+ * Verify {@link Optimizely#getFeatureVariableInteger(String, String, String)}
2664+ * calls through to {@link Optimizely#getFeatureVariableInteger(String, String, String, Map<String, String>)}
2665+ * and returns null
2666+ * when {@link Optimizely#getFeatureVariableValueForType(String, String, String, Map, LiveVariable.VariableType)}
2667+ * returns null
2668+ * @throws ConfigParseException
2669+ */
2670+ @ Test
2671+ public void getFeatureVariableIntegerReturnsNullFromInternal () throws ConfigParseException {
2672+ String featureKey = "featureKey" ;
2673+ String variableKey = "variableKey" ;
2674+
2675+ Optimizely spyOptimizely = spy (Optimizely .builder (validDatafile , mockEventHandler )
2676+ .withConfig (validProjectConfig )
2677+ .build ());
2678+
2679+ doReturn (null ).when (spyOptimizely ).getFeatureVariableValueForType (
2680+ eq (featureKey ),
2681+ eq (variableKey ),
2682+ eq (genericUserId ),
2683+ eq (Collections .<String , String >emptyMap ()),
2684+ eq (LiveVariable .VariableType .INTEGER )
2685+ );
2686+
2687+ assertNull (spyOptimizely .getFeatureVariableInteger (
2688+ featureKey ,
2689+ variableKey ,
2690+ genericUserId
2691+ ));
2692+
2693+ verify (spyOptimizely ).getFeatureVariableInteger (
2694+ eq (featureKey ),
2695+ eq (variableKey ),
2696+ eq (genericUserId ),
2697+ eq (Collections .<String , String >emptyMap ())
2698+ );
2699+ }
2700+
2701+ /**
2702+ * Verify {@link Optimizely#getFeatureVariableInteger(String, String, String)}
2703+ * calls through to {@link Optimizely#getFeatureVariableInteger(String, String, String, Map)}
2704+ * and both return the parsed Integer value from the value returned from
2705+ * {@link Optimizely#getFeatureVariableValueForType(String, String, String, Map, LiveVariable.VariableType)}.
2706+ * @throws ConfigParseException
2707+ */
2708+ @ Test
2709+ public void getFeatureVariableIntegerReturnsWhatInternalReturns () throws ConfigParseException {
2710+ String featureKey = "featureKey" ;
2711+ String variableKey = "variableKey" ;
2712+ Integer valueNoAttributes = 1 ;
2713+ Integer valueWithAttributes = 2 ;
2714+ Map <String , String > attributes = Collections .singletonMap ("key" , "value" );
2715+
2716+ Optimizely spyOptimizely = spy (Optimizely .builder (validDatafile , mockEventHandler )
2717+ .withConfig (validProjectConfig )
2718+ .build ());
2719+
2720+
2721+ doReturn (valueNoAttributes .toString ()).when (spyOptimizely ).getFeatureVariableValueForType (
2722+ eq (featureKey ),
2723+ eq (variableKey ),
2724+ eq (genericUserId ),
2725+ eq (Collections .<String , String >emptyMap ()),
2726+ eq (LiveVariable .VariableType .INTEGER )
2727+ );
2728+
2729+ doReturn (valueWithAttributes .toString ()).when (spyOptimizely ).getFeatureVariableValueForType (
2730+ eq (featureKey ),
2731+ eq (variableKey ),
2732+ eq (genericUserId ),
2733+ eq (attributes ),
2734+ eq (LiveVariable .VariableType .INTEGER )
2735+ );
2736+
2737+ assertEquals (valueNoAttributes , spyOptimizely .getFeatureVariableInteger (
2738+ featureKey ,
2739+ variableKey ,
2740+ genericUserId
2741+ ));
2742+
2743+ verify (spyOptimizely ).getFeatureVariableInteger (
2744+ eq (featureKey ),
2745+ eq (variableKey ),
2746+ eq (genericUserId ),
2747+ eq (Collections .<String , String >emptyMap ())
2748+ );
2749+
2750+ assertEquals (valueWithAttributes , spyOptimizely .getFeatureVariableInteger (
2751+ featureKey ,
2752+ variableKey ,
2753+ genericUserId ,
2754+ attributes
2755+ ));
2756+ }
2757+
24702758 //======== Helper methods ========//
24712759
24722760 private Experiment createUnknownExperiment () {
0 commit comments