forked from apex-commons/SoqlBuilder
-
Notifications
You must be signed in to change notification settings - Fork 0
/
SetConditionTest.cls
194 lines (168 loc) · 8.04 KB
/
SetConditionTest.cls
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
@IsTest
private class SetConditionTest {
private static testmethod void testInvalidField(){
Boolean exceptionCaught = false;
try{
new SetCondition(' ');
}catch(IllegalArgumentException e){
exceptionCaught = true;
}
System.assert(
exceptionCaught == true,
'empty field param to FieldCondition constructor did not throw IllegalArgumentException');
}
private static testmethod void testInvalidOperator_EQUALS(){
Boolean exceptionCaught = false;
try{
new SetCondition('x',Operator.EQUALS,new List<Object>{1,2});
}catch(IllegalArgumentException e){
exceptionCaught = true;
}
System.assert(exceptionCaught == true,'IllegalArgumentException not thrown');
}
private static testmethod void testNullValue_List(){
Boolean exceptionCaught = false;
List<Object> value = null;
try{
new SetCondition('x',Operator.INCLUDES,value);
}catch(IllegalArgumentException e){
exceptionCaught = true;
}
System.assert(exceptionCaught == true,'IllegalArgumentException not thrown');
}
private static testmethod void testNullValue_SoqlBuilder(){
Boolean exceptionCaught = false;
SoqlBuilder value = null;
try{
new SetCondition('x',Operator.NOT_IN,value);
}catch(IllegalArgumentException e){
exceptionCaught = true;
}
System.assert(exceptionCaught == true,'IllegalArgumentException not thrown');
}
private static testmethod void testEmptyValue(){
Boolean exceptionCaught = false;
try{
new SetCondition('x',Operator.INCLUDES,new List<Object>{});
}catch(IllegalArgumentException e){
exceptionCaught = true;
}
System.assert(exceptionCaught == true,'IllegalArgumentException not thrown');
}
private static testmethod void testNameNotDefined(){
Boolean exceptionCaught = false;
try{
new SetCondition().toSoql();
}catch(IllegalStateException e){
exceptionCaught = true;
}
System.assert(exceptionCaught == true,'IllegalStateException not thrown');
}
private static testmethod void testOperationNotDefined(){
Boolean exceptionCaught = false;
try{
new SetCondition('name').toSoql();
}catch(IllegalStateException e){
exceptionCaught = true;
}
System.assert(exceptionCaught == true,'IllegalStateException not thrown');
}
private static testmethod void testInvalidValue(){
Boolean exceptionCaught = false;
try{
new SetCondition('name').includes(new List<Object>{new DecimalRange(0,1)}).toSoql();
}catch(IllegalArgumentException e){
exceptionCaught = true;
}
System.assert(exceptionCaught == true,'IllegalArgumentException not thrown');
}
private static testmethod void testNullValuesList(){
Boolean exceptionCaught = false;
List<Object> value = null;
try{
new SetCondition('name').includes(value);
}catch(IllegalArgumentException e){
exceptionCaught = true;
}
System.assert(exceptionCaught == true,'IllegalArgumentException not thrown');
}
private static testmethod void testEmptyValuesList(){
Boolean exceptionCaught = false;
try{
new SetCondition('name').includes(new List<Object>());
}catch(IllegalArgumentException e){
exceptionCaught = true;
}
System.assert(exceptionCaught == true,'IllegalArgumentException not thrown');
}
private static testmethod void testIncludes(){
System.assertEquals(
'name INCLUDES (\'test\',123)',
new SetCondition('name').includes(new List<Object>{'test',123}).toSoql());
}
private static testmethod void testExcludes(){
System.assertEquals(
'name EXCLUDES (\'test\',123)',
new SetCondition('name').excludes(new List<Object>{'test',123}).toSoql());
}
private static testmethod void testIn(){
System.assertEquals(
'name IN (\'test\',123)',
new SetCondition('name').inx(new List<Object>{'test',123}).toSoql());
}
private static testmethod void testNotIn(){
System.assertEquals(
'name NOT IN (\'test\',123)',
new SetCondition('name').notIn(new List<Object>{'test',123}).toSoql());
}
private static testmethod void testOperatorMethod_includes(){
System.assertEquals('x INCLUDES (1,2)',new SetCondition().field('x').includes(new List<Object>{1,2}).toSoql());
System.assertEquals('x INCLUDES (1,2)',new SetCondition('x').includes(new List<Object>{1,2}).toSoql());
System.assertEquals('x INCLUDES (1,2)',new SetCondition('x',Operator.INCLUDES,new List<Object>{1,2}).toSoql());
}
private static testmethod void testOperatorMethod_excludes(){
System.assertEquals('x EXCLUDES (1,2)',new SetCondition().field('x').excludes(new List<Object>{1,2}).toSoql());
System.assertEquals('x EXCLUDES (1,2)',new SetCondition('x').excludes(new List<Object>{1,2}).toSoql());
System.assertEquals('x EXCLUDES (1,2)',new SetCondition('x',Operator.excludes,new List<Object>{1,2}).toSoql());
}
private static testmethod void testOperatorMethod_inx(){
System.assertEquals('x IN (1,2)',new SetCondition().field('x').inx(new List<Object>{1,2}).toSoql());
System.assertEquals('x IN (1,2)',new SetCondition('x').inx(new List<Object>{1,2}).toSoql());
System.assertEquals('x IN (1,2)',new SetCondition('x',Operator.INX,new List<Object>{1,2}).toSoql());
}
private static testmethod void testOperatorMethod_notIn(){
System.assertEquals('x NOT IN (1,2)',new SetCondition().field('x').notIn(new List<Object>{1,2}).toSoql());
System.assertEquals('x NOT IN (1,2)',new SetCondition('x').notIn(new List<Object>{1,2}).toSoql());
System.assertEquals('x NOT IN (1,2)',new SetCondition('x',Operator.NOT_IN,new List<Object>{1,2}).toSoql());
}
private static testmethod void testBasicSemiJoin_Constructor(){
System.assertEquals('ID IN (SELECT AccountId FROM Opportunity WHERE StageName = \'Closed Lost\')',
new SetCondition('ID', Operator.INX,
new SoqlBuilder().selectx('AccountId').fromx('Opportunity').wherex(new FieldCondition('StageName','Closed Lost'))
).toSoql());
}
private static testmethod void testBasicSemiJoin_1(){
System.assertEquals('ID IN (SELECT AccountId FROM Opportunity WHERE StageName = \'Closed Lost\')',
new SetCondition('ID').inx(
new SoqlBuilder().selectx('AccountId').fromx('Opportunity').wherex(new FieldCondition('StageName','Closed Lost'))
).toSoql());
}
private static testmethod void testBasicSemiJoin_2(){
System.assertEquals('ID NOT IN (SELECT AccountId FROM Opportunity WHERE StageName = \'Closed Lost\')',
new SetCondition('ID').notIn(
new SoqlBuilder().selectx('AccountId').fromx('Opportunity').wherex(new FieldCondition('StageName','Closed Lost'))
).toSoql());
}
private static testmethod void testBasicSemiJoin_3(){
System.assertEquals('ID INCLUDES (SELECT AccountId FROM Opportunity WHERE StageName = \'Closed Lost\')',
new SetCondition('ID').includes(
new SoqlBuilder().selectx('AccountId').fromx('Opportunity').wherex(new FieldCondition('StageName','Closed Lost'))
).toSoql());
}
private static testmethod void testBasicSemiJoin_4(){
System.assertEquals('ID EXCLUDES (SELECT AccountId FROM Opportunity WHERE StageName = \'Closed Lost\')',
new SetCondition('ID').excludes(
new SoqlBuilder().selectx('AccountId').fromx('Opportunity').wherex(new FieldCondition('StageName','Closed Lost'))
).toSoql());
}
}