-
Notifications
You must be signed in to change notification settings - Fork 18
/
Copy pathDateFormulaTest.cls
276 lines (224 loc) · 10.6 KB
/
DateFormulaTest.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
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
@IsTest
private class DateFormulaTest {
private static testmethod void test_ILLEGAL_STATE(){
Boolean exceptionCaught = false;
try{
new DateFormula().toSoql();
}catch(IllegalStateException e){
exceptionCaught = true;
}
System.assert(exceptionCaught == true,'IllegalStateException not thrown');
}
private static testmethod void test_INVALID_N(){
Boolean exceptionCaught = false;
try{
new DateFormula().next(-1,UnitOfTime.Year).toSoql();
}catch(IllegalArgumentException e){
exceptionCaught = true;
}
System.assert(exceptionCaught == true,'IllegalArgumentException not thrown');
}
private static testmethod void test_YESTERDAY(){
System.assertEquals('YESTERDAY',new DateFormula().yesterdayx().toSoql());
}
private static testmethod void test_TODAY(){
System.assertEquals('TODAY',new DateFormula().todayx().toSoql());
}
private static testmethod void test_TOMORROW(){
System.assertEquals('TOMORROW',new DateFormula().tomorrowx().toSoql());
}
private static testmethod void test_LAST_90_DAYS(){
System.assertEquals('LAST_90_DAYS',new DateFormula().last90Days().toSoql());
}
private static testmethod void test_NEXT_90_DAYS(){
System.assertEquals('NEXT_90_DAYS',new DateFormula().next90Days().toSoql());
}
private static testmethod void test_NEXT_DAY(){
System.assertEquals('NEXT_N_DAYS:1',new DateFormula().next(UnitOfTime.Day).toSoql());
System.assertEquals('NEXT_N_DAYS:1',new DateFormula().next(1,UnitOfTime.Day).toSoql());
}
private static testmethod void test_NEXT_WEEK(){
System.assertEquals('NEXT_WEEK',new DateFormula().next(UnitOfTime.Week).toSoql());
System.assertEquals('NEXT_WEEK',new DateFormula().next(1,UnitOfTime.Week).toSoql());
}
private static testmethod void test_NEXT_MONTH(){
System.assertEquals('NEXT_MONTH',new DateFormula().next(UnitOfTime.Month).toSoql());
System.assertEquals('NEXT_MONTH',new DateFormula().next(1,UnitOfTime.Month).toSoql());
}
private static testmethod void test_NEXT_QUARTER(){
System.assertEquals('NEXT_QUARTER',new DateFormula().next(UnitOfTime.Quarter).toSoql());
System.assertEquals('NEXT_QUARTER',new DateFormula().next(1,UnitOfTime.Quarter).toSoql());
}
private static testmethod void test_NEXT_YEAR(){
System.assertEquals('NEXT_YEAR',new DateFormula().next(UnitOfTime.Year).toSoql());
System.assertEquals('NEXT_YEAR',new DateFormula().next(1,UnitOfTime.Year).toSoql());
}
private static testmethod void test_NEXT_FISCAL_QUARTER(){
System.assertEquals('NEXT_FISCAL_QUARTER',new DateFormula().next(UnitOfTime.FiscalQuarter).toSoql());
System.assertEquals('NEXT_FISCAL_QUARTER',new DateFormula().next(1,UnitOfTime.FiscalQuarter).toSoql());
}
private static testmethod void test_NEXT_FISCAL_YEAR(){
System.assertEquals('NEXT_FISCAL_YEAR',new DateFormula().next(UnitOfTime.FiscalYear).toSoql());
System.assertEquals('NEXT_FISCAL_YEAR',new DateFormula().next(1,UnitOfTime.FiscalYear).toSoql());
}
private static testmethod void test_LAST_DAY(){
System.assertEquals('LAST_N_DAYS:1',new DateFormula().last(UnitOfTime.Day).toSoql());
System.assertEquals('LAST_N_DAYS:1',new DateFormula().last(1,UnitOfTime.Day).toSoql());
}
private static testmethod void test_LAST_WEEK(){
System.assertEquals('LAST_WEEK',new DateFormula().last(UnitOfTime.Week).toSoql());
System.assertEquals('LAST_WEEK',new DateFormula().last(1,UnitOfTime.Week).toSoql());
}
private static testmethod void test_LAST_MONTH(){
System.assertEquals('LAST_MONTH',new DateFormula().last(UnitOfTime.Month).toSoql());
System.assertEquals('LAST_MONTH',new DateFormula().last(1,UnitOfTime.Month).toSoql());
}
private static testmethod void test_LAST_QUARTER(){
System.assertEquals('LAST_QUARTER',new DateFormula().last(UnitOfTime.Quarter).toSoql());
System.assertEquals('LAST_QUARTER',new DateFormula().last(1,UnitOfTime.Quarter).toSoql());
}
private static testmethod void test_LAST_YEAR(){
System.assertEquals('LAST_YEAR',new DateFormula().last(UnitOfTime.Year).toSoql());
System.assertEquals('LAST_YEAR',new DateFormula().last(1,UnitOfTime.Year).toSoql());
}
private static testmethod void test_LAST_FISCAL_QUARTER(){
System.assertEquals('LAST_FISCAL_QUARTER',new DateFormula().last(UnitOfTime.FiscalQuarter).toSoql());
System.assertEquals('LAST_FISCAL_QUARTER',new DateFormula().last(1,UnitOfTime.FiscalQuarter).toSoql());
}
private static testmethod void test_LAST_FISCAL_YEAR(){
System.assertEquals('LAST_FISCAL_YEAR',new DateFormula().last(UnitOfTime.FiscalYear).toSoql());
System.assertEquals('LAST_FISCAL_YEAR',new DateFormula().last(1,UnitOfTime.FiscalYear).toSoql());
}
private static testmethod void test_THIS_DAY(){
System.assertEquals('TODAY',new DateFormula().thisx(UnitOfTime.Day).toSoql());
}
private static testmethod void test_THIS_WEEK(){
System.assertEquals('THIS_WEEK',new DateFormula().thisx(UnitOfTime.Week).toSoql());
}
private static testmethod void test_THIS_MONTH(){
System.assertEquals('THIS_MONTH',new DateFormula().thisx(UnitOfTime.Month).toSoql());
}
private static testmethod void test_THIS_QUARTER(){
System.assertEquals('THIS_QUARTER',new DateFormula().thisx(UnitOfTime.Quarter).toSoql());
}
private static testmethod void test_THIS_YEAR(){
System.assertEquals('THIS_YEAR',new DateFormula().thisx(UnitOfTime.Year).toSoql());
}
private static testmethod void test_THIS_FISCAL_QUARTER(){
System.assertEquals('THIS_FISCAL_QUARTER',new DateFormula().thisx(UnitOfTime.FiscalQuarter).toSoql());
}
private static testmethod void test_THIS_FISCAL_YEAR(){
System.assertEquals('THIS_FISCAL_YEAR',new DateFormula().thisx(UnitOfTime.FiscalYear).toSoql());
}
private static testmethod void test_NEXT_N_DAYS(){
System.assertEquals('NEXT_N_DAYS:0',new DateFormula().next(0,UnitOfTime.Day).toSoql());
System.assertEquals('NEXT_N_DAYS:1',new DateFormula().next(1,UnitOfTime.Day).toSoql());
System.assertEquals('NEXT_N_DAYS:2',new DateFormula().next(2,UnitOfTime.Day).toSoql());
}
private static testmethod void test_NEXT_N_WEEKS(){
Boolean exceptionCaught = false;
try{
new DateFormula().next(2,UnitOfTime.Week);
}catch(IllegalArgumentException e){
exceptionCaught = true;
}
System.assert(exceptionCaught == true,'IllegalArgumentException not thrown');
}
private static testmethod void test_NEXT_N_MONTHS(){
Boolean exceptionCaught = false;
try{
new DateFormula().next(2,UnitOfTime.Month);
}catch(IllegalArgumentException e){
exceptionCaught = true;
}
System.assert(exceptionCaught == true,'IllegalArgumentException not thrown');
}
private static testmethod void test_NEXT_N_QUARTERS(){
System.assertEquals('NEXT_N_QUARTERS:2',new DateFormula().next(2,UnitOfTime.Quarter).toSoql());
}
private static testmethod void test_NEXT_N_YEARS(){
System.assertEquals('NEXT_N_YEARS:2',new DateFormula().next(2,UnitOfTime.Year).toSoql());
}
private static testmethod void test_NEXT_N_FISCAL_QUARTERS(){
System.assertEquals('NEXT_N_FISCAL_QUARTERS:2',new DateFormula().next(2,UnitOfTime.FiscalQuarter).toSoql());
}
private static testmethod void test_NEXT_N_FISCAL_YEARS(){
System.assertEquals('NEXT_N_FISCAL_YEARS:2',new DateFormula().next(2,UnitOfTime.FiscalYear).toSoql());
}
private static testmethod void test_LAST_N_DAYS(){
System.assertEquals('LAST_N_DAYS:0',new DateFormula().last(0,UnitOfTime.Day).toSoql());
System.assertEquals('LAST_N_DAYS:1',new DateFormula().last(1,UnitOfTime.Day).toSoql());
System.assertEquals('LAST_N_DAYS:2',new DateFormula().last(2,UnitOfTime.Day).toSoql());
}
private static testmethod void test_LAST_N_WEEKS(){
Boolean exceptionCaught = false;
try{
new DateFormula().last(2,UnitOfTime.Week);
}catch(IllegalArgumentException e){
exceptionCaught = true;
}
System.assert(exceptionCaught == true,'IllegalArgumentException not thrown');
}
private static testmethod void test_LAST_N_MONTHS(){
Boolean exceptionCaught = false;
try{
new DateFormula().last(2,UnitOfTime.Month);
}catch(IllegalArgumentException e){
exceptionCaught = true;
}
System.assert(exceptionCaught == true,'IllegalArgumentException not thrown');
}
private static testmethod void test_LAST_N_QUARTERS(){
System.assertEquals('LAST_N_QUARTERS:2',new DateFormula().last(2,UnitOfTime.Quarter).toSoql());
}
private static testmethod void test_LAST_N_YEARS(){
System.assertEquals('LAST_N_YEARS:2',new DateFormula().last(2,UnitOfTime.Year).toSoql());
}
private static testmethod void test_LAST_N_FISCAL_QUARTERS(){
System.assertEquals('LAST_N_FISCAL_QUARTERS:2',new DateFormula().last(2,UnitOfTime.FiscalQuarter).toSoql());
}
private static testmethod void test_LAST_N_FISCAL_YEARS(){
System.assertEquals('LAST_N_FISCAL_YEARS:2',new DateFormula().last(2,UnitOfTime.FiscalYear).toSoql());
}
/*
+----------------+-----+----------------+
+ TYPE + N + THIS|NEXT|LAST +
+----------------+----------------------+
+ DAYS + YES + NO +
+ WEEK + NO + YES +
+ MONTH + NO + YES +
+ QUARTER + YES + YES +
+ YEAR + YES + YES +
+ FISCAL_QUARTER + YES + YES +
+ FISCAL_YEAR + YES + YES +
+----------------------+----------------+
NEXT_WEEK
NEXT_MONTH
NEXT_QUARTER
NEXT_YEAR
NEXT_FISCAL_QUARTER
NEXT_FISCAL_YEAR
LAST_WEEK
LAST_MONTH
LAST_QUARTER
LAST_YEAR
LAST_FISCAL_QUARTER
LAST_FISCAL_YEAR
THIS_WEEK
THIS_MONTH
THIS_QUERTER
THIS_YEAR
THIS_FISCAL_QUARTER
THIS_FISCAL_YEAR
NEXT_N_DAYS ':' INTEGER
NEXT_N_QUARTERS ':'INTEGER
NEXT_N_YEARS ':' INTEGER
NEXT_N_FISCAL_QUARTERS ':' INTEGER
NEXT_N_FISCAL_YEARS ':' INTEGER
LAST_N_DAYS ':' INTEGER
LAST_N_QUARTERS ':' INTEGER
LAST_N_YEARS ':' INTEGER
LAST_N_FISCAL_QUARTERS ':' INTEGER
LAST_N_FISCAL_YEARS ':' INTEGER
*/
}