@@ -31,19 +31,10 @@ private with sharing class fflib_SObjectSelectorTest
31
31
static testMethod void testGetFieldListString ()
32
32
{
33
33
Testfflib_SObjectSelector selector = new Testfflib_SObjectSelector ();
34
- List <String > fieldList = selector .getFieldListString ().split (' ,' );
35
- Set <String > fieldSet = new Set <String >(fieldList );
36
- system .assertEquals (Userinfo .isMultiCurrencyOrganization () ? 5 : 4 , fieldSet .size ());
37
- system .assert (fieldSet .contains (' Name' ));
38
- system .assert (fieldSet .contains (' Id' ));
39
- system .assert (fieldSet .contains (' AccountNumber' ));
40
- system .assert (fieldSet .contains (' AnnualRevenue' ));
41
- if (UserInfo .isMultiCurrencyOrganization ())
42
- system .assert (fieldSet .contains (' CurrencyIsoCode' ));
43
-
44
- String relatedFieldListString = Userinfo .isMultiCurrencyOrganization () ? ' myprefix.AccountNumber,myprefix.CurrencyIsoCode,myprefix.AnnualRevenue,myprefix.Id,myprefix.Name'
45
- : ' myprefix.AccountNumber,myprefix.AnnualRevenue,myprefix.Id,myprefix.Name' ;
46
- system .assertEquals (relatedFieldListString , selector .getRelatedFieldListString (' myprefix' ));
34
+ String fieldListString = selector .getFieldListString ();
35
+ assertFieldListString (fieldListString , null );
36
+ String relatedFieldListString = selector .getRelatedFieldListString (' myprefix' );
37
+ assertFieldListString (relatedFieldListString , ' myprefix' );
47
38
}
48
39
49
40
static testMethod void testGetSObjectName ()
@@ -168,9 +159,13 @@ private with sharing class fflib_SObjectSelectorTest
168
159
static testMethod void testSOQL ()
169
160
{
170
161
Testfflib_SObjectSelector selector = new Testfflib_SObjectSelector ();
171
- String soql = Userinfo .isMultiCurrencyOrganization () ? ' SELECT AccountNumber, CurrencyIsoCode, AnnualRevenue, Id, Name FROM Account ORDER BY Name DESC NULLS FIRST , AnnualRevenue ASC NULLS FIRST '
172
- : ' SELECT AccountNumber, AnnualRevenue, Id, Name FROM Account ORDER BY Name DESC NULLS FIRST , AnnualRevenue ASC NULLS FIRST ' ;
173
- System .assertEquals (soql , selector .newQueryFactory ().toSOQL ());
162
+ String soql = selector .newQueryFactory ().toSOQL ();
163
+ Pattern p = Pattern .compile (' SELECT (.*) FROM Account ORDER BY Name DESC NULLS FIRST , AnnualRevenue ASC NULLS FIRST ' );
164
+ Matcher m = p .matcher (soql );
165
+ System .assert (m .matches (), ' Generated SOQL does not match expected pattern. Here is the generated SOQL: ' + soql );
166
+ System .assertEquals (1 , m .groupCount (), ' Unexpected number of groups captured.' );
167
+ String fieldListString = m .group (1 );
168
+ assertFieldListString (fieldListString , null );
174
169
}
175
170
176
171
static testMethod void testDefaultConfig ()
@@ -180,19 +175,36 @@ private with sharing class fflib_SObjectSelectorTest
180
175
System .assertEquals (true , selector .isEnforcingCRUD ());
181
176
System .assertEquals (false , selector .isIncludeFieldSetFields ());
182
177
183
- String fieldListString = Userinfo .isMultiCurrencyOrganization () ? ' AccountNumber,CurrencyIsoCode,AnnualRevenue,Id,Name'
184
- : ' AccountNumber,AnnualRevenue,Id,Name' ;
185
- System .assertEquals (fieldListString , selector .getFieldListBuilder ().getStringValue ());
186
- System .assertEquals (fieldListString , selector .getFieldListString ());
178
+ String fieldListString = selector .getFieldListString ();
179
+ assertFieldListString (fieldListString , null );
187
180
188
- String relatedFieldListString = Userinfo .isMultiCurrencyOrganization () ? ' LookupField__r.AccountNumber,LookupField__r.CurrencyIsoCode,LookupField__r.AnnualRevenue,LookupField__r.Id,LookupField__r.Name'
189
- : ' LookupField__r.AccountNumber,LookupField__r.AnnualRevenue,LookupField__r.Id,LookupField__r.Name' ;
190
- System .assertEquals (relatedFieldListString , selector .getRelatedFieldListString (' LookupField__r' ));
181
+ String relatedFieldListString = selector .getRelatedFieldListString (' LookupField__r' );
182
+ assertFieldListString (relatedFieldListString , ' LookupField__r' );
191
183
192
184
System .assertEquals (' Account' , selector .getSObjectName ());
193
185
System .assertEquals (Account .SObjectType , selector .getSObjectType2 ());
194
186
}
195
187
188
+ private static void assertFieldListString (String fieldListString , String prefix ) {
189
+ String prefixString = (! String .isBlank (prefix )) ? prefix + ' .' : ' ' ;
190
+ List <String > fieldList = fieldListString .split (' ,{1}\\ s?' );
191
+ System .assertEquals (UserInfo .isMultiCurrencyOrganization () ? 5 : 4 , fieldList .size ());
192
+ Set <String > fieldSet = new Set <String >();
193
+ fieldSet .addAll (fieldList );
194
+ String expected = prefixString + ' AccountNumber' ;
195
+ System .assert (fieldSet .contains (expected ), expected + ' missing from field list string: ' + fieldListString );
196
+ expected = prefixString + ' AnnualRevenue' ;
197
+ System .assert (fieldSet .contains (expected ), expected + ' missing from field list string: ' + fieldListString );
198
+ expected = prefixString + ' Id' ;
199
+ System .assert (fieldSet .contains (expected ), expected + ' missing from field list string: ' + fieldListString );
200
+ expected = prefixString + ' Name' ;
201
+ System .assert (fieldSet .contains (expected ), expected + ' missing from field list string: ' + fieldListString );
202
+ if (UserInfo .isMultiCurrencyOrganization ()) {
203
+ expected = prefixString + ' CurrencyIsoCode' ;
204
+ System .assert (fieldSet .contains (expected ), expected + ' missing from field list string: ' + fieldListString );
205
+ }
206
+ }
207
+
196
208
private class Testfflib_SObjectSelector extends fflib_SObjectSelector
197
209
{
198
210
public Testfflib_SObjectSelector ()
0 commit comments