@@ -2630,6 +2630,294 @@ public void getFeatureVariableStringReturnsWhatInternalReturns() throws ConfigPa
26302630 ));
26312631 }
26322632
2633+ /**
2634+ * Verify {@link Optimizely#getFeatureVariableBoolean(String, String, String)}
2635+ * calls through to {@link Optimizely#getFeatureVariableBoolean(String, String, String, Map<String, String>)}
2636+ * and returns null
2637+ * when {@link Optimizely#getFeatureVariableValueForType(String, String, String, Map, LiveVariable.VariableType)}
2638+ * returns null
2639+ * @throws ConfigParseException
2640+ */
2641+ @ Test
2642+ public void getFeatureVariableBooleanReturnsNullFromInternal () throws ConfigParseException {
2643+ String featureKey = "featureKey" ;
2644+ String variableKey = "variableKey" ;
2645+
2646+ Optimizely spyOptimizely = spy (Optimizely .builder (validDatafile , mockEventHandler )
2647+ .withConfig (validProjectConfig )
2648+ .build ());
2649+
2650+ doReturn (null ).when (spyOptimizely ).getFeatureVariableValueForType (
2651+ eq (featureKey ),
2652+ eq (variableKey ),
2653+ eq (genericUserId ),
2654+ eq (Collections .<String , String >emptyMap ()),
2655+ eq (LiveVariable .VariableType .BOOLEAN )
2656+ );
2657+
2658+ assertNull (spyOptimizely .getFeatureVariableBoolean (
2659+ featureKey ,
2660+ variableKey ,
2661+ genericUserId
2662+ ));
2663+
2664+ verify (spyOptimizely ).getFeatureVariableBoolean (
2665+ eq (featureKey ),
2666+ eq (variableKey ),
2667+ eq (genericUserId ),
2668+ eq (Collections .<String , String >emptyMap ())
2669+ );
2670+ }
2671+
2672+ /**
2673+ * Verify {@link Optimizely#getFeatureVariableBoolean(String, String, String)}
2674+ * calls through to {@link Optimizely#getFeatureVariableBoolean(String, String, String, Map)}
2675+ * and both return a Boolean representation of the value returned from
2676+ * {@link Optimizely#getFeatureVariableValueForType(String, String, String, Map, LiveVariable.VariableType)}.
2677+ * @throws ConfigParseException
2678+ */
2679+ @ Test
2680+ public void getFeatureVariableBooleanReturnsWhatInternalReturns () throws ConfigParseException {
2681+ String featureKey = "featureKey" ;
2682+ String variableKey = "variableKey" ;
2683+ Boolean valueNoAttributes = false ;
2684+ Boolean valueWithAttributes = true ;
2685+ Map <String , String > attributes = Collections .singletonMap ("key" , "value" );
2686+
2687+ Optimizely spyOptimizely = spy (Optimizely .builder (validDatafile , mockEventHandler )
2688+ .withConfig (validProjectConfig )
2689+ .build ());
2690+
2691+
2692+ doReturn (valueNoAttributes .toString ()).when (spyOptimizely ).getFeatureVariableValueForType (
2693+ eq (featureKey ),
2694+ eq (variableKey ),
2695+ eq (genericUserId ),
2696+ eq (Collections .<String , String >emptyMap ()),
2697+ eq (LiveVariable .VariableType .BOOLEAN )
2698+ );
2699+
2700+ doReturn (valueWithAttributes .toString ()).when (spyOptimizely ).getFeatureVariableValueForType (
2701+ eq (featureKey ),
2702+ eq (variableKey ),
2703+ eq (genericUserId ),
2704+ eq (attributes ),
2705+ eq (LiveVariable .VariableType .BOOLEAN )
2706+ );
2707+
2708+ assertEquals (valueNoAttributes , spyOptimizely .getFeatureVariableBoolean (
2709+ featureKey ,
2710+ variableKey ,
2711+ genericUserId
2712+ ));
2713+
2714+ verify (spyOptimizely ).getFeatureVariableBoolean (
2715+ eq (featureKey ),
2716+ eq (variableKey ),
2717+ eq (genericUserId ),
2718+ eq (Collections .<String , String >emptyMap ())
2719+ );
2720+
2721+ assertEquals (valueWithAttributes , spyOptimizely .getFeatureVariableBoolean (
2722+ featureKey ,
2723+ variableKey ,
2724+ genericUserId ,
2725+ attributes
2726+ ));
2727+ }
2728+
2729+ /**
2730+ * Verify {@link Optimizely#getFeatureVariableDouble(String, String, String)}
2731+ * calls through to {@link Optimizely#getFeatureVariableDouble(String, String, String, Map<String, String>)}
2732+ * and returns null
2733+ * when {@link Optimizely#getFeatureVariableValueForType(String, String, String, Map, LiveVariable.VariableType)}
2734+ * returns null
2735+ * @throws ConfigParseException
2736+ */
2737+ @ Test
2738+ public void getFeatureVariableDoubleReturnsNullFromInternal () throws ConfigParseException {
2739+ String featureKey = "featureKey" ;
2740+ String variableKey = "variableKey" ;
2741+
2742+ Optimizely spyOptimizely = spy (Optimizely .builder (validDatafile , mockEventHandler )
2743+ .withConfig (validProjectConfig )
2744+ .build ());
2745+
2746+ doReturn (null ).when (spyOptimizely ).getFeatureVariableValueForType (
2747+ eq (featureKey ),
2748+ eq (variableKey ),
2749+ eq (genericUserId ),
2750+ eq (Collections .<String , String >emptyMap ()),
2751+ eq (LiveVariable .VariableType .DOUBLE )
2752+ );
2753+
2754+ assertNull (spyOptimizely .getFeatureVariableDouble (
2755+ featureKey ,
2756+ variableKey ,
2757+ genericUserId
2758+ ));
2759+
2760+ verify (spyOptimizely ).getFeatureVariableDouble (
2761+ eq (featureKey ),
2762+ eq (variableKey ),
2763+ eq (genericUserId ),
2764+ eq (Collections .<String , String >emptyMap ())
2765+ );
2766+ }
2767+
2768+ /**
2769+ * Verify {@link Optimizely#getFeatureVariableDouble(String, String, String)}
2770+ * calls through to {@link Optimizely#getFeatureVariableDouble(String, String, String, Map)}
2771+ * and both return the parsed Double from the value returned from
2772+ * {@link Optimizely#getFeatureVariableValueForType(String, String, String, Map, LiveVariable.VariableType)}.
2773+ * @throws ConfigParseException
2774+ */
2775+ @ Test
2776+ public void getFeatureVariableDoubleReturnsWhatInternalReturns () throws ConfigParseException {
2777+ String featureKey = "featureKey" ;
2778+ String variableKey = "variableKey" ;
2779+ Double valueNoAttributes = 0.1 ;
2780+ Double valueWithAttributes = 0.2 ;
2781+ Map <String , String > attributes = Collections .singletonMap ("key" , "value" );
2782+
2783+ Optimizely spyOptimizely = spy (Optimizely .builder (validDatafile , mockEventHandler )
2784+ .withConfig (validProjectConfig )
2785+ .build ());
2786+
2787+
2788+ doReturn (valueNoAttributes .toString ()).when (spyOptimizely ).getFeatureVariableValueForType (
2789+ eq (featureKey ),
2790+ eq (variableKey ),
2791+ eq (genericUserId ),
2792+ eq (Collections .<String , String >emptyMap ()),
2793+ eq (LiveVariable .VariableType .DOUBLE )
2794+ );
2795+
2796+ doReturn (valueWithAttributes .toString ()).when (spyOptimizely ).getFeatureVariableValueForType (
2797+ eq (featureKey ),
2798+ eq (variableKey ),
2799+ eq (genericUserId ),
2800+ eq (attributes ),
2801+ eq (LiveVariable .VariableType .DOUBLE )
2802+ );
2803+
2804+ assertEquals (valueNoAttributes , spyOptimizely .getFeatureVariableDouble (
2805+ featureKey ,
2806+ variableKey ,
2807+ genericUserId
2808+ ));
2809+
2810+ verify (spyOptimizely ).getFeatureVariableDouble (
2811+ eq (featureKey ),
2812+ eq (variableKey ),
2813+ eq (genericUserId ),
2814+ eq (Collections .<String , String >emptyMap ())
2815+ );
2816+
2817+ assertEquals (valueWithAttributes , spyOptimizely .getFeatureVariableDouble (
2818+ featureKey ,
2819+ variableKey ,
2820+ genericUserId ,
2821+ attributes
2822+ ));
2823+ }
2824+
2825+ /**
2826+ * Verify {@link Optimizely#getFeatureVariableInteger(String, String, String)}
2827+ * calls through to {@link Optimizely#getFeatureVariableInteger(String, String, String, Map<String, String>)}
2828+ * and returns null
2829+ * when {@link Optimizely#getFeatureVariableValueForType(String, String, String, Map, LiveVariable.VariableType)}
2830+ * returns null
2831+ * @throws ConfigParseException
2832+ */
2833+ @ Test
2834+ public void getFeatureVariableIntegerReturnsNullFromInternal () throws ConfigParseException {
2835+ String featureKey = "featureKey" ;
2836+ String variableKey = "variableKey" ;
2837+
2838+ Optimizely spyOptimizely = spy (Optimizely .builder (validDatafile , mockEventHandler )
2839+ .withConfig (validProjectConfig )
2840+ .build ());
2841+
2842+ doReturn (null ).when (spyOptimizely ).getFeatureVariableValueForType (
2843+ eq (featureKey ),
2844+ eq (variableKey ),
2845+ eq (genericUserId ),
2846+ eq (Collections .<String , String >emptyMap ()),
2847+ eq (LiveVariable .VariableType .INTEGER )
2848+ );
2849+
2850+ assertNull (spyOptimizely .getFeatureVariableInteger (
2851+ featureKey ,
2852+ variableKey ,
2853+ genericUserId
2854+ ));
2855+
2856+ verify (spyOptimizely ).getFeatureVariableInteger (
2857+ eq (featureKey ),
2858+ eq (variableKey ),
2859+ eq (genericUserId ),
2860+ eq (Collections .<String , String >emptyMap ())
2861+ );
2862+ }
2863+
2864+ /**
2865+ * Verify {@link Optimizely#getFeatureVariableInteger(String, String, String)}
2866+ * calls through to {@link Optimizely#getFeatureVariableInteger(String, String, String, Map)}
2867+ * and both return the parsed Integer value from the value returned from
2868+ * {@link Optimizely#getFeatureVariableValueForType(String, String, String, Map, LiveVariable.VariableType)}.
2869+ * @throws ConfigParseException
2870+ */
2871+ @ Test
2872+ public void getFeatureVariableIntegerReturnsWhatInternalReturns () throws ConfigParseException {
2873+ String featureKey = "featureKey" ;
2874+ String variableKey = "variableKey" ;
2875+ Integer valueNoAttributes = 1 ;
2876+ Integer valueWithAttributes = 2 ;
2877+ Map <String , String > attributes = Collections .singletonMap ("key" , "value" );
2878+
2879+ Optimizely spyOptimizely = spy (Optimizely .builder (validDatafile , mockEventHandler )
2880+ .withConfig (validProjectConfig )
2881+ .build ());
2882+
2883+
2884+ doReturn (valueNoAttributes .toString ()).when (spyOptimizely ).getFeatureVariableValueForType (
2885+ eq (featureKey ),
2886+ eq (variableKey ),
2887+ eq (genericUserId ),
2888+ eq (Collections .<String , String >emptyMap ()),
2889+ eq (LiveVariable .VariableType .INTEGER )
2890+ );
2891+
2892+ doReturn (valueWithAttributes .toString ()).when (spyOptimizely ).getFeatureVariableValueForType (
2893+ eq (featureKey ),
2894+ eq (variableKey ),
2895+ eq (genericUserId ),
2896+ eq (attributes ),
2897+ eq (LiveVariable .VariableType .INTEGER )
2898+ );
2899+
2900+ assertEquals (valueNoAttributes , spyOptimizely .getFeatureVariableInteger (
2901+ featureKey ,
2902+ variableKey ,
2903+ genericUserId
2904+ ));
2905+
2906+ verify (spyOptimizely ).getFeatureVariableInteger (
2907+ eq (featureKey ),
2908+ eq (variableKey ),
2909+ eq (genericUserId ),
2910+ eq (Collections .<String , String >emptyMap ())
2911+ );
2912+
2913+ assertEquals (valueWithAttributes , spyOptimizely .getFeatureVariableInteger (
2914+ featureKey ,
2915+ variableKey ,
2916+ genericUserId ,
2917+ attributes
2918+ ));
2919+ }
2920+
26332921 //======== Helper methods ========//
26342922
26352923 private Experiment createUnknownExperiment () {
0 commit comments