@@ -151,7 +151,7 @@ private with sharing class fflib_SObjectSelectorTest
151151 {
152152 Testfflib_SObjectSelector selector = new Testfflib_SObjectSelector ();
153153 String soql = selector .newQueryFactory ().toSOQL ();
154- Pattern p = Pattern .compile (' SELECT (.*) FROM Account ORDER BY Name DESC NULLS FIRST , AnnualRevenue ASC NULLS FIRST ' );
154+ Pattern p = Pattern .compile (' SELECT (.*) FROM Account ORDER BY Name DESC NULLS FIRST , AnnualRevenue ASC NULLS LAST ' );
155155 Matcher m = p .matcher (soql );
156156 System .assert (m .matches (), ' Generated SOQL does not match expected pattern. Here is the generated SOQL: ' + soql );
157157 System .assertEquals (1 , m .groupCount (), ' Unexpected number of groups captured.' );
@@ -208,13 +208,37 @@ private with sharing class fflib_SObjectSelectorTest
208208 String soql = qf .toSOQL ();
209209
210210 // Then
211- Pattern soqlPattern = Pattern .compile (' SELECT (.*) FROM Account ORDER BY Name DESC NULLS FIRST , AnnualRevenue ASC NULLS FIRST ' );
211+ Pattern soqlPattern = Pattern .compile (' SELECT (.*) FROM Account ORDER BY Name DESC NULLS FIRST , AnnualRevenue ASC NULLS LAST ' );
212212 Matcher soqlMatcher = soqlPattern .matcher (soql );
213213 soqlMatcher .matches ();
214214
215215 List <String > actualSelectFields = soqlMatcher .group (1 ).deleteWhiteSpace ().split (' ,' );
216216 System .assertEquals (expectedSelectFields , new Set <String >(actualSelectFields ));
217217 }
218+
219+ // Test case of ordering with NULLS LAST option passed into the ordering method
220+ @isTest
221+ static void testWithOrderingNullsLast ()
222+ {
223+ // Build the selector to test with
224+ Testfflib_SObjectSelector selector = new Testfflib_SObjectSelector (false , false , false , false );
225+ fflib_QueryFactory qf = selector .newQueryFactory ();
226+
227+ // Add in the expected fields
228+ Set <String > expectedSelectFields = new Set <String >{ ' Name' , ' Id' , ' AccountNumber' , ' AnnualRevenue' };
229+ if (UserInfo .isMultiCurrencyOrganization ())
230+ {
231+ expectedSelectFields .add (' CurrencyIsoCode' );
232+ }
233+
234+ // Generate the SOQL string
235+ String soql = qf .toSOQL ();
236+
237+ // Assert that the
238+ Pattern soqlPattern = Pattern .compile (' SELECT (.*) FROM Account ORDER BY Name DESC NULLS FIRST , AnnualRevenue ASC NULLS LAST ' );
239+ Matcher soqlMatcher = soqlPattern .matcher (soql );
240+ system .assert (soqlMatcher .matches (), ' The SOQL should have that expected.' );
241+ }
218242
219243 private static void assertEqualsSelectFields (String expectedSelectFields , String actualSelectFields )
220244 {
@@ -253,7 +277,7 @@ private with sharing class fflib_SObjectSelectorTest
253277
254278 public override String getOrderBy ()
255279 {
256- return ' Name DESC, AnnualRevenue ASC' ;
280+ return ' Name DESC, AnnualRevenue ASC NULLS LAST ' ;
257281 }
258282 }
259283
0 commit comments