1
1
@IsTest
2
2
private class RollupIntegrationTests {
3
- private static final Map <String , RollupCurrencyInfo > CURRENCY_TYPES = RollupCurrencyInfo .getCurrencyMap ();
4
-
5
3
@TestSetup
6
4
static void setup () {
7
5
Account acc = new Account (Name = RollupIntegrationTests .class .getName ());
@@ -18,7 +16,7 @@ private class RollupIntegrationTests {
18
16
AccountIdText__c = acc .Id ,
19
17
AccountId = acc .Id
20
18
);
21
- setCurrencyIsoCode (opp , ' USD' );
19
+ RollupCurrencyInfo . setCurrencyIsoCode (opp , ' USD' );
22
20
23
21
insert opp ;
24
22
upsert new RollupSettings__c (IsEnabled__c = true );
@@ -165,16 +163,16 @@ private class RollupIntegrationTests {
165
163
Account acc = (Account ) RollupTestUtils .queryRecord (' Account' , new List <String >{ ' AnnualRevenue' });
166
164
System .assertEquals (null , acc .AnnualRevenue , ' Test has started under the wrong conditions!' );
167
165
System .assertEquals (' USD' , getCurrencyIsoCode (acc ), ' Test has started under the wrong conditions!' );
168
- setCurrencyIsoCode (acc , ' EUR' );
166
+ RollupCurrencyInfo . setCurrencyIsoCode (acc , ' EUR' );
169
167
update acc ;
170
168
171
169
Opportunity usdOpp = (Opportunity ) RollupTestUtils .queryRecord (' Opportunity' , new List <String >{ ' StageName' , ' CloseDate' , ' Amount' , ' AccountId' });
172
170
173
171
Opportunity eurOpp = usdOpp .clone (false , true );
174
- setCurrencyIsoCode (eurOpp , ' EUR' );
172
+ RollupCurrencyInfo . setCurrencyIsoCode (eurOpp , ' EUR' );
175
173
eurOpp .Amount = .95 ;
176
174
Opportunity jpyOpp = eurOpp .clone (false , true );
177
- setCurrencyIsoCode (jpyOpp , ' JPY' );
175
+ RollupCurrencyInfo . setCurrencyIsoCode (jpyOpp , ' JPY' );
178
176
jpyOpp .Amount = 100 ;
179
177
insert new List <Opportunity >{ eurOpp , jpyOpp };
180
178
@@ -198,10 +196,10 @@ private class RollupIntegrationTests {
198
196
Test .stopTest ();
199
197
200
198
acc = (Account ) RollupTestUtils .queryRecord (acc .Id , new List <String >{ ' AnnualRevenue' , ' MaxAmountRollupSummary__c' });
201
- Integer scaleSize = CURRENCY_TYPES . containsKey (getCurrencyIsoCode (acc )) ? CURRENCY_TYPES . get ( getCurrencyIsoCode ( acc )). DecimalPlaces : 2 ;
199
+ RollupCurrencyInfo currencyInfo = RollupCurrencyInfo . getCurrencyInfo (getCurrencyIsoCode (acc ));
202
200
System .assertEquals (
203
- acc .MaxAmountRollupSummary__c .setScale (scaleSize ),
204
- acc .AnnualRevenue .setScale (scaleSize ),
201
+ acc .MaxAmountRollupSummary__c .setScale (currencyInfo . DecimalPlaces ),
202
+ acc .AnnualRevenue .setScale (currencyInfo . DecimalPlaces ),
205
203
' Multi-currency MAX rollup not calculated correctly!'
206
204
);
207
205
}
@@ -211,16 +209,16 @@ private class RollupIntegrationTests {
211
209
Account acc = (Account ) RollupTestUtils .queryRecord (' Account' , new List <String >{ ' AnnualRevenue' });
212
210
System .assertEquals (null , acc .AnnualRevenue , ' Test has started under the wrong conditions!' );
213
211
System .assertEquals (' USD' , getCurrencyIsoCode (acc ), ' Test has started under the wrong conditions!' );
214
- setCurrencyIsoCode (acc , ' EUR' );
212
+ RollupCurrencyInfo . setCurrencyIsoCode (acc , ' EUR' );
215
213
update acc ;
216
214
217
215
Opportunity usdOpp = (Opportunity ) RollupTestUtils .queryRecord (' Opportunity' , new List <String >{ ' StageName' , ' CloseDate' , ' Amount' , ' AccountId' });
218
216
219
217
Opportunity eurOpp = usdOpp .clone (false , true );
220
- setCurrencyIsoCode (eurOpp , ' EUR' );
218
+ RollupCurrencyInfo . setCurrencyIsoCode (eurOpp , ' EUR' );
221
219
eurOpp .Amount = .95 ;
222
220
Opportunity jpyOpp = eurOpp .clone (false , true );
223
- setCurrencyIsoCode (jpyOpp , ' JPY' );
221
+ RollupCurrencyInfo . setCurrencyIsoCode (jpyOpp , ' JPY' );
224
222
jpyOpp .Amount = 100 ;
225
223
insert new List <Opportunity >{ eurOpp , jpyOpp };
226
224
@@ -245,10 +243,10 @@ private class RollupIntegrationTests {
245
243
Test .stopTest ();
246
244
247
245
acc = (Account ) RollupTestUtils .queryRecord (acc .Id , new List <String >{ ' AnnualRevenue' , ' MinAmountRollupSummary__c' });
248
- Integer scaleSize = CURRENCY_TYPES . containsKey (getCurrencyIsoCode (acc )) ? CURRENCY_TYPES . get ( getCurrencyIsoCode ( acc )). DecimalPlaces : 2 ;
246
+ RollupCurrencyInfo currencyInfo = RollupCurrencyInfo . getCurrencyInfo (getCurrencyIsoCode (acc ));
249
247
System .assertEquals (
250
- acc .MinAmountRollupSummary__c .setScale (scaleSize ),
251
- acc .AnnualRevenue .setScale (scaleSize ),
248
+ acc .MinAmountRollupSummary__c .setScale (currencyInfo . DecimalPlaces ),
249
+ acc .AnnualRevenue .setScale (currencyInfo . DecimalPlaces ),
252
250
' Multi-currency MIN rollup not calculated correctly!'
253
251
);
254
252
}
@@ -258,16 +256,16 @@ private class RollupIntegrationTests {
258
256
Account acc = (Account ) RollupTestUtils .queryRecord (' Account' , new List <String >{ ' AnnualRevenue' });
259
257
System .assertEquals (null , acc .AnnualRevenue , ' Test has started under the wrong conditions!' );
260
258
System .assertEquals (' USD' , getCurrencyIsoCode (acc ), ' Test has started under the wrong conditions!' );
261
- setCurrencyIsoCode (acc , ' EUR' );
259
+ RollupCurrencyInfo . setCurrencyIsoCode (acc , ' EUR' );
262
260
update acc ;
263
261
264
262
Opportunity usdOpp = (Opportunity ) RollupTestUtils .queryRecord (' Opportunity' , new List <String >{ ' StageName' , ' CloseDate' , ' Amount' , ' AccountId' });
265
263
266
264
Opportunity eurOpp = usdOpp .clone (false , true );
267
- setCurrencyIsoCode (eurOpp , ' EUR' );
265
+ RollupCurrencyInfo . setCurrencyIsoCode (eurOpp , ' EUR' );
268
266
eurOpp .Amount = .95 ;
269
267
Opportunity jpyOpp = eurOpp .clone (false , true );
270
- setCurrencyIsoCode (jpyOpp , ' JPY' );
268
+ RollupCurrencyInfo . setCurrencyIsoCode (jpyOpp , ' JPY' );
271
269
jpyOpp .Amount = 100 ;
272
270
insert new List <Opportunity >{ eurOpp , jpyOpp };
273
271
@@ -292,10 +290,10 @@ private class RollupIntegrationTests {
292
290
Test .stopTest ();
293
291
294
292
acc = (Account ) RollupTestUtils .queryRecord (acc .Id , new List <String >{ ' AnnualRevenue' , ' SumAmountRollupSummary__c' });
295
- Integer scaleSize = CURRENCY_TYPES . containsKey (getCurrencyIsoCode (acc )) ? CURRENCY_TYPES . get ( getCurrencyIsoCode ( acc )). DecimalPlaces : 2 ;
293
+ RollupCurrencyInfo currencyInfo = RollupCurrencyInfo . getCurrencyInfo (getCurrencyIsoCode (acc ));
296
294
System .assertEquals (
297
- acc .SumAmountRollupSummary__c .setScale (scaleSize ),
298
- acc .AnnualRevenue .setScale (scaleSize ),
295
+ acc .SumAmountRollupSummary__c .setScale (currencyInfo . DecimalPlaces ),
296
+ acc .AnnualRevenue .setScale (currencyInfo . DecimalPlaces ),
299
297
' Multi-currency SUM rollup not calculated correctly!'
300
298
);
301
299
}
@@ -305,16 +303,16 @@ private class RollupIntegrationTests {
305
303
Account acc = (Account ) RollupTestUtils .queryRecord (' Account' , new List <String >{ ' AnnualRevenue' });
306
304
System .assertEquals (null , acc .AnnualRevenue , ' Test has started under the wrong conditions!' );
307
305
System .assertEquals (' USD' , getCurrencyIsoCode (acc ), ' Test has started under the wrong conditions!' );
308
- setCurrencyIsoCode (acc , ' EUR' );
306
+ RollupCurrencyInfo . setCurrencyIsoCode (acc , ' EUR' );
309
307
update acc ;
310
308
311
309
Opportunity usdOpp = (Opportunity ) RollupTestUtils .queryRecord (' Opportunity' , new List <String >{ ' StageName' , ' CloseDate' , ' Amount' , ' AccountId' });
312
310
313
311
Opportunity eurOpp = usdOpp .clone (false , true );
314
- setCurrencyIsoCode (eurOpp , ' EUR' );
312
+ RollupCurrencyInfo . setCurrencyIsoCode (eurOpp , ' EUR' );
315
313
eurOpp .Amount = .95 ;
316
314
Opportunity jpyOpp = eurOpp .clone (false , true );
317
- setCurrencyIsoCode (jpyOpp , ' JPY' );
315
+ RollupCurrencyInfo . setCurrencyIsoCode (jpyOpp , ' JPY' );
318
316
jpyOpp .Amount = 100 ;
319
317
insert new List <Opportunity >{ eurOpp , jpyOpp };
320
318
@@ -344,14 +342,13 @@ private class RollupIntegrationTests {
344
342
for (SObject opp : opportunities ) {
345
343
convertedAmountSum += (Decimal ) opp .get (' ConvertedAmount' );
346
344
}
347
- Decimal conversionRate = CURRENCY_TYPES . containsKey (getCurrencyIsoCode (acc )) ? CURRENCY_TYPES . get ( getCurrencyIsoCode ( acc )). ConversionRate : 1 ;
348
- Decimal expectedAverage = (convertedAmountSum / opportunities .size ()) * conversionRate ;
345
+ RollupCurrencyInfo currencyInfo = RollupCurrencyInfo . getCurrencyInfo (getCurrencyIsoCode (acc ));
346
+ Decimal expectedAverage = (convertedAmountSum / opportunities .size ()) * currencyInfo . ConversionRate ;
349
347
350
- Integer scaleSize = CURRENCY_TYPES .containsKey (getCurrencyIsoCode (acc )) ? CURRENCY_TYPES .get (getCurrencyIsoCode (acc )).DecimalPlaces : 2 ;
351
348
acc = (Account ) RollupTestUtils .queryRecord (acc .Id , new List <String >{ ' AnnualRevenue' });
352
349
System .assertEquals (
353
- expectedAverage .setScale (scaleSize ),
354
- acc .AnnualRevenue .setScale (scaleSize ),
350
+ expectedAverage .setScale (currencyInfo . DecimalPlaces ),
351
+ acc .AnnualRevenue .setScale (currencyInfo . DecimalPlaces ),
355
352
' Multi-currency AVERAGE rollup not calculated correctly! Records: ' + opportunities
356
353
);
357
354
}
@@ -361,16 +358,16 @@ private class RollupIntegrationTests {
361
358
Account acc = (Account ) RollupTestUtils .queryRecord (' Account' , new List <String >{ ' AnnualRevenue' });
362
359
System .assertEquals (null , acc .AnnualRevenue , ' Test has started under the wrong conditions!' );
363
360
System .assertEquals (' USD' , getCurrencyIsoCode (acc ), ' Test has started under the wrong conditions!' );
364
- setCurrencyIsoCode (acc , ' EUR' );
361
+ RollupCurrencyInfo . setCurrencyIsoCode (acc , ' EUR' );
365
362
update acc ;
366
363
367
364
Opportunity usdOpp = (Opportunity ) RollupTestUtils .queryRecord (' Opportunity' , new List <String >{ ' StageName' , ' CloseDate' , ' Amount' , ' AccountId' });
368
365
369
366
Opportunity eurOpp = usdOpp .clone (false , true );
370
- setCurrencyIsoCode (eurOpp , ' EUR' );
367
+ RollupCurrencyInfo . setCurrencyIsoCode (eurOpp , ' EUR' );
371
368
eurOpp .Amount = .95 ;
372
369
Opportunity jpyOpp = eurOpp .clone (false , true );
373
- setCurrencyIsoCode (jpyOpp , ' JPY' );
370
+ RollupCurrencyInfo . setCurrencyIsoCode (jpyOpp , ' JPY' );
374
371
jpyOpp .Amount = 100 ;
375
372
insert new List <Opportunity >{ eurOpp , jpyOpp };
376
373
@@ -416,16 +413,16 @@ private class RollupIntegrationTests {
416
413
Account acc = (Account ) RollupTestUtils .queryRecord (' Account' , new List <String >{ ' AnnualRevenue' });
417
414
System .assertEquals (null , acc .AnnualRevenue , ' Test has started under the wrong conditions!' );
418
415
System .assertEquals (' USD' , getCurrencyIsoCode (acc ), ' Test has started under the wrong conditions!' );
419
- setCurrencyIsoCode (acc , ' EUR' );
416
+ RollupCurrencyInfo . setCurrencyIsoCode (acc , ' EUR' );
420
417
update acc ;
421
418
422
419
Opportunity usdOpp = (Opportunity ) RollupTestUtils .queryRecord (' Opportunity' , new List <String >{ ' StageName' , ' CloseDate' , ' Amount' , ' AccountId' });
423
420
424
421
Opportunity eurOpp = usdOpp .clone (false , true );
425
- setCurrencyIsoCode (eurOpp , ' EUR' );
422
+ RollupCurrencyInfo . setCurrencyIsoCode (eurOpp , ' EUR' );
426
423
eurOpp .Amount = .95 ;
427
424
Opportunity jpyOpp = eurOpp .clone (false , true );
428
- setCurrencyIsoCode (jpyOpp , ' JPY' );
425
+ RollupCurrencyInfo . setCurrencyIsoCode (jpyOpp , ' JPY' );
429
426
jpyOpp .Amount = 100 ;
430
427
insert new List <Opportunity >{ eurOpp , jpyOpp };
431
428
@@ -506,9 +503,9 @@ private class RollupIntegrationTests {
506
503
// The CurrencyIsoCode field isn't directly used here, but the field will be automatically included by Rollup's queries,
507
504
// so include it on the accounts so the asserts below show that the accounts do, in fact, match
508
505
Account greatGrandparent = new Account (Name = ' Great-grandparent' );
509
- setCurrencyISoCode (greatGrandparent , ' USD' );
506
+ RollupCurrencyInfo . setCurrencyIsoCode (greatGrandparent , ' USD' );
510
507
Account secondGreatGrandparent = new Account (Name = ' Second great-grandparent' );
511
- setCurrencyISoCode (secondGreatGrandparent , ' USD' );
508
+ RollupCurrencyInfo . setCurrencyIsoCode (secondGreatGrandparent , ' USD' );
512
509
insert new List <Account >{ greatGrandparent , secondGreatGrandparent };
513
510
514
511
ParentApplication__c grandParent = new ParentApplication__c (Name = ' Grandparent' , Account__c = greatGrandparent .Id );
@@ -1684,13 +1681,7 @@ private class RollupIntegrationTests {
1684
1681
System .assertNotEquals (null , jobId );
1685
1682
}
1686
1683
1687
- private static void setCurrencyISoCode (SObject record , String isoCode ) {
1688
- if (UserInfo .isMultiCurrencyOrganization ()) {
1689
- record .put (' CurrencyIsoCode' , isoCode );
1690
- }
1691
- }
1692
-
1693
1684
private static String getCurrencyIsoCode (SObject record ) {
1694
- return UserInfo .isMultiCurrencyOrganization () ? (String ) record .get (' CurrencyIsoCode ' ) : ' USD' ;
1685
+ return UserInfo .isMultiCurrencyOrganization () ? (String ) record .get (RollupCurrencyInfo . CURRENCY_ISO_CODE_FIELD_NAME ) : ' USD' ;
1695
1686
}
1696
1687
}
0 commit comments