22
22
import org .junit .Before ;
23
23
import org .junit .Rule ;
24
24
import org .junit .Test ;
25
+ import org .mockito .internal .matchers .Or ;
25
26
26
27
import java .math .BigInteger ;
27
28
import java .util .*;
@@ -56,6 +57,21 @@ public void initialize() {
56
57
testTypedUserAttributes .put ("null_val" , null );
57
58
}
58
59
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
+
59
75
/**
60
76
* Verify that UserAttribute.toJson returns a json represented string of conditions.
61
77
*/
@@ -66,6 +82,41 @@ public void userAttributeConditionsToJson() throws Exception {
66
82
assertEquals (testInstance .toJson (), expectedConditionJsonString );
67
83
}
68
84
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
+ }
69
120
70
121
/**
71
122
* Verify that UserAttribute.evaluate returns true on exact-matching visitor attribute data.
0 commit comments