2222import org .junit .Before ;
2323import org .junit .Rule ;
2424import org .junit .Test ;
25+ import org .mockito .internal .matchers .Or ;
2526
2627import java .math .BigInteger ;
2728import java .util .*;
@@ -56,6 +57,21 @@ public void initialize() {
5657 testTypedUserAttributes .put ("null_val" , null );
5758 }
5859
60+ @ Test
61+ public void nullConditionTest () throws Exception {
62+ NullCondition nullCondition = new NullCondition ();
63+ assertEquals (null , nullCondition .toJson ());
64+ assertEquals (null , nullCondition .getOperandOrId ());
65+ }
66+
67+ @ Test
68+ public void emptyConditionTest () throws Exception {
69+ EmptyCondition emptyCondition = new EmptyCondition ();
70+ assertEquals (null , emptyCondition .toJson ());
71+ assertEquals (null , emptyCondition .getOperandOrId ());
72+ assertEquals (true , emptyCondition .evaluate (null , null ));
73+ }
74+
5975 /**
6076 * Verify that UserAttribute.toJson returns a json represented string of conditions.
6177 */
@@ -66,6 +82,41 @@ public void userAttributeConditionsToJson() throws Exception {
6682 assertEquals (testInstance .toJson (), expectedConditionJsonString );
6783 }
6884
85+ /**
86+ * Verify that AndCondition.toJson returns a json represented string of conditions.
87+ */
88+ @ Test
89+ public void andConditionsToJsonWithComma () throws Exception {
90+ UserAttribute testInstance1 = new UserAttribute ("browser_type" , "custom_attribute" , "true" , "safari" );
91+ UserAttribute testInstance2 = new UserAttribute ("browser_type" , "custom_attribute" , "true" , "safari" );
92+ String expectedConditionJsonString = "[\" and\" , [\" or\" , {\" name\" :\" browser_type\" , \" type\" :\" custom_attribute\" , \" match\" :\" true\" , \" value\" :\" safari\" }, {\" name\" :\" browser_type\" , \" type\" :\" custom_attribute\" , \" match\" :\" true\" , \" value\" :\" safari\" }]]" ;
93+ List <Condition > userConditions = new ArrayList <>();
94+ userConditions .add (testInstance1 );
95+ userConditions .add (testInstance2 );
96+ OrCondition orCondition = new OrCondition (userConditions );
97+ List <Condition > orConditions = new ArrayList <>();
98+ orConditions .add (orCondition );
99+ AndCondition andCondition = new AndCondition (orConditions );
100+ assertEquals (andCondition .toJson (), expectedConditionJsonString );
101+ }
102+
103+ /**
104+ * Verify that orCondition.toJson returns a json represented string of conditions.
105+ */
106+ @ Test
107+ public void orConditionsToJsonWithComma () throws Exception {
108+ UserAttribute testInstance1 = new UserAttribute ("browser_type" , "custom_attribute" , "true" , "safari" );
109+ UserAttribute testInstance2 = new UserAttribute ("browser_type" , "custom_attribute" , "true" , "safari" );
110+ String expectedConditionJsonString = "[\" or\" , [\" and\" , {\" name\" :\" browser_type\" , \" type\" :\" custom_attribute\" , \" match\" :\" true\" , \" value\" :\" safari\" }, {\" name\" :\" browser_type\" , \" type\" :\" custom_attribute\" , \" match\" :\" true\" , \" value\" :\" safari\" }]]" ;
111+ List <Condition > userConditions = new ArrayList <>();
112+ userConditions .add (testInstance1 );
113+ userConditions .add (testInstance2 );
114+ AndCondition andCondition = new AndCondition (userConditions );
115+ List <Condition > andConditions = new ArrayList <>();
116+ andConditions .add (andCondition );
117+ OrCondition orCondition = new OrCondition (andConditions );
118+ assertEquals (orCondition .toJson (), expectedConditionJsonString );
119+ }
69120
70121 /**
71122 * Verify that UserAttribute.evaluate returns true on exact-matching visitor attribute data.
0 commit comments