-
Notifications
You must be signed in to change notification settings - Fork 18
/
Copy pathFieldConditionTest.cls
138 lines (116 loc) · 7.59 KB
/
FieldConditionTest.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
@IsTest
private class FieldConditionTest {
private static testmethod void testInvalidField(){
Boolean exceptionCaught = false;
try{
new FieldCondition(' ',null,null);
}catch(IllegalArgumentException e){
exceptionCaught = true;
}
System.assert(
exceptionCaught == true,
'empty field param to FieldCondition constructor did not throw IllegalArgumentException');
}
private static testmethod void testInvalidOperator_INCLUDES(){
Boolean exceptionCaught = false;
try{
new FieldCondition('x',Operator.INCLUDES,null);
}catch(IllegalArgumentException e){
exceptionCaught = true;
}
System.assert(exceptionCaught == true,'IllegalArgumentException not thrown');
}
private static testmethod void testInvalidOperator_EXCLUDES(){
Boolean exceptionCaught = false;
try{
new FieldCondition('x',Operator.EXCLUDES,null);
}catch(IllegalArgumentException e){
exceptionCaught = true;
}
System.assert(exceptionCaught == true,'IllegalArgumentException not thrown');
}
private static testmethod void testInvalidValue(){
Boolean exceptionCaught = false;
try{
new FieldCondition('x',new DecimalRange(0,1)).toSoql();
}catch(IllegalArgumentException e){
exceptionCaught = true;
}
System.assert(exceptionCaught == true,'IllegalArgumentException not thrown');
}
private static testmethod void testNullValue(){
System.assertEquals('name = null',new FieldCondition('name',Operator.EQUALS,null).toSoql());
}
private static testmethod void testStringValue(){
System.assertEquals('name = \'acme\'',new FieldCondition().field('name').equals('acme').toSoql());
System.assertEquals('name = \'acme\'',new FieldCondition('name').equals('acme').toSoql());
System.assertEquals('name = \'acme\'',new FieldCondition('name',Operator.EQUALS,'acme').toSoql());
System.assertEquals('name like \'%acme%\'',new FieldCondition().field('name').likex('%acme%').toSoql());
System.assertEquals('name like \'%acme%\'',new FieldCondition('name').likex('%acme%').toSoql());
System.assertEquals('name like \'%acme%\'',new FieldCondition('name',Operator.LIKEX,'%acme%').toSoql());
}
private static testmethod void testBooleanValue(){
System.assertEquals('ispartner = true',new FieldCondition('ispartner',Operator.EQUALS,true).toSoql());
System.assertEquals('ispartner = false',new FieldCondition('ispartner',Operator.EQUALS,false).toSoql());
}
private static testmethod void testIntegerValue(){
System.assertEquals('employees = 1',new FieldCondition('employees',Operator.EQUALS,1).toSoql());
System.assertEquals('employees != 1',new FieldCondition('employees',Operator.NOT_EQUALS,1).toSoql());
System.assertEquals('employees < 1',new FieldCondition('employees',Operator.LESS_THAN,1).toSoql());
System.assertEquals('employees > 1',new FieldCondition('employees',Operator.GREATER_THAN ,1).toSoql());
System.assertEquals('employees <= 1',new FieldCondition('employees',Operator.LESS_THAN_OR_EQUAL_TO,1).toSoql());
System.assertEquals('employees >= 1',new FieldCondition('employees',Operator.GREATER_THAN_OR_EQUAL_TO,1).toSoql());
}
private static testmethod void testDoubleValue(){
System.assertEquals('employees = 1.1',new FieldCondition('employees',Operator.EQUALS,1.1).toSoql());
System.assertEquals('employees != 1.1',new FieldCondition('employees',Operator.NOT_EQUALS,1.1).toSoql());
System.assertEquals('employees < 1.1',new FieldCondition('employees',Operator.LESS_THAN,1.1).toSoql());
System.assertEquals('employees > 1.1',new FieldCondition('employees',Operator.GREATER_THAN ,1.1).toSoql());
System.assertEquals('employees <= 1.1',new FieldCondition('employees',Operator.LESS_THAN_OR_EQUAL_TO,1.1).toSoql());
System.assertEquals('employees >= 1.1',new FieldCondition('employees',Operator.GREATER_THAN_OR_EQUAL_TO,1.1).toSoql());
}
private static testmethod void testDateValue(){
System.assertEquals('createddate < 1960-02-17',new FieldCondition('createddate',Operator.LESS_THAN,Date.newinstance(1960, 2, 17)).toSoql());
}
private static testmethod void testDatetimeValue(){
System.assertEquals('createddate >= 2008-12-01T12:00:00Z',new FieldCondition('createddate',Operator.GREATER_THAN_OR_EQUAL_TO,Datetime.newInstance(2008, 12, 1)).toSoql());
}
private static testmethod void testOperatorMethod_equals(){
System.assertEquals('x = 1',new FieldCondition().field('x').equals(1).toSoql());
System.assertEquals('x = 1',new FieldCondition('x').equals(1).toSoql());
System.assertEquals('x = 1',new FieldCondition('x',Operator.EQUALS,1).toSoql());
}
private static testmethod void testOperatorMethod_notEquals(){
System.assertEquals('x != 1',new FieldCondition().field('x').notEquals(1).toSoql());
System.assertEquals('x != 1',new FieldCondition('x').notEquals(1).toSoql());
System.assertEquals('x != 1',new FieldCondition('x',Operator.NOT_EQUALS,1).toSoql());
}
private static testmethod void testOperatorMethod_lessThan(){
System.assertEquals('x < 1',new FieldCondition().field('x').lessThan(1).toSoql());
System.assertEquals('x < 1',new FieldCondition('x').lessThan(1).toSoql());
System.assertEquals('x < 1',new FieldCondition('x',Operator.LESS_THAN,1).toSoql());
}
private static testmethod void testOperatorMethod_lessThanOrEqualTo(){
System.assertEquals('x <= 1',new FieldCondition().field('x').lessThanOrEqualTo(1).toSoql());
System.assertEquals('x <= 1',new FieldCondition('x').lessThanOrEqualTo(1).toSoql());
System.assertEquals('x <= 1',new FieldCondition('x',Operator.LESS_THAN_OR_EQUAL_TO,1).toSoql());
}
private static testmethod void testOperatorMethod_greaterThan(){
System.assertEquals('x > 1',new FieldCondition().field('x').greaterThan(1).toSoql());
System.assertEquals('x > 1',new FieldCondition('x').greaterThan(1).toSoql());
System.assertEquals('x > 1',new FieldCondition('x',Operator.GREATER_THAN,1).toSoql());
}
private static testmethod void testOperatorMethod_greaterThanOrEqualTo(){
System.assertEquals('x >= 1',new FieldCondition().field('x').greaterThanOrEqualTo(1).toSoql());
System.assertEquals('x >= 1',new FieldCondition('x').greaterThanOrEqualTo(1).toSoql());
System.assertEquals('x >= 1',new FieldCondition('x',Operator.GREATER_THAN_OR_EQUAL_TO,1).toSoql());
}
private static testmethod void testOperatorMethod_likex(){
System.assertEquals('x like \'acme\'',new FieldCondition().field('x').likex('acme').toSoql());
System.assertEquals('x like \'acme\'',new FieldCondition('x').likex('acme').toSoql());
System.assertEquals('x like \'acme\'',new FieldCondition('x',Operator.LIKEX,'acme').toSoql());
System.assertEquals('x like \'%acme%\'',new FieldCondition().field('x').likex('acme').toSoql(new SoqlOptions().wildcardStringsInLikeOperators()));
System.assertEquals('x like \'%acme%\'',new FieldCondition('x').likex('acme').toSoql(new SoqlOptions().wildcardStringsInLikeOperators()));
System.assertEquals('x like \'%acme%\'',new FieldCondition('x',Operator.LIKEX,'acme').toSoql(new SoqlOptions().wildcardStringsInLikeOperators()));
}
}