@@ -3480,6 +3480,103 @@ private class SOQL_Test {
34803480 }
34813481 }
34823482
3483+ @IsTest
3484+ static void querySynchronousCloseToLimitWithMocking () {
3485+ // Setup
3486+ Exception queryException = null ;
3487+
3488+ SOQL .setMock (' mockingQuery' , new List <Account >{
3489+ new Account (Name = ' Test 1' ),
3490+ new Account (Name = ' Test 2' )
3491+ });
3492+
3493+ // Test
3494+ try {
3495+ Test .startTest ();
3496+ for (Integer i = 0 ; i < 100 ; i ++ ) {
3497+ SOQL .of (Account .SObjectType ).mockId (' mockingQuery' ).toList ();
3498+ }
3499+ Test .stopTest ();
3500+ } catch (QueryException e ) {
3501+ queryException = e ;
3502+ }
3503+
3504+ // Verify
3505+ Assert .isNull (queryException , ' The synchronous query should not have exceeded the limit.' );
3506+ }
3507+
3508+ @IsTest
3509+ static void querySynchronousLimitExceptionWithMocking () {
3510+ // Setup
3511+ Exception queryException = null ;
3512+
3513+ SOQL .setMock (' mockingQuery' , new List <Account >{
3514+ new Account (Name = ' Test 1' ),
3515+ new Account (Name = ' Test 2' )
3516+ });
3517+
3518+ // Test
3519+ try {
3520+ Test .startTest ();
3521+ for (Integer i = 0 ; i < 101 ; i ++ ) {
3522+ SOQL .of (Account .SObjectType ).mockId (' mockingQuery' ).toList ();
3523+ }
3524+ Test .stopTest ();
3525+ } catch (QueryException e ) {
3526+ queryException = e ;
3527+ }
3528+
3529+ // Verify
3530+ Assert .isNotNull (queryException , ' The synchronous query should have exceeded the limit.' );
3531+ Assert .areEqual (' Too many SOQL queries.' , queryException .getMessage (), ' The synchronous query should not have been exceeded.' );
3532+ }
3533+
3534+ @IsTest
3535+ static void querySynchronousLimitExceptionWithoutMocking () {
3536+ // Setup
3537+ Exception queryException = null ;
3538+
3539+ // Test
3540+ try {
3541+ for (Integer i = 0 ; i < 102 ; i ++ ) {
3542+ SOQL .of (Account .SObjectType ).toList ();
3543+ }
3544+ } catch (QueryException e ) {
3545+ queryException = e ;
3546+ }
3547+
3548+ // Verify
3549+ Assert .isNotNull (queryException , ' The synchronous query should have exceeded the limit.' );
3550+ Assert .areEqual (' Too many SOQL queries.' , queryException .getMessage (), ' The synchronous query should have been exceeded.' );
3551+ }
3552+
3553+ @SuppressWarnings('PMD.ApexUnitTestClassShouldHaveAsserts')
3554+ @IsTest
3555+ static void preview () {
3556+ // Test
3557+ SOQL .of (Account .SObjectType ).preview ().toList ();
3558+ }
3559+
3560+ @SuppressWarnings('PMD.ApexUnitTestClassShouldHaveAsserts')
3561+ @IsTest
3562+ static void previewWithConditions () {
3563+ // Test
3564+ SOQL .of (Account .SObjectType )
3565+ .whereAre (SOQL .FilterGroup
3566+ .add (SOQL .Filter .with (Account .Name ).equal (' Test' ))
3567+ .add (SOQL .Filter .with (Account .Industry ).equal (' IT' ))
3568+ )
3569+ .preview ()
3570+ .toList ();
3571+ }
3572+
3573+ @SuppressWarnings('PMD.ApexUnitTestClassShouldHaveAsserts')
3574+ @IsTest
3575+ static void previewCount () {
3576+ // Test
3577+ SOQL .of (Account .SObjectType ).count ().preview ().toInteger ();
3578+ }
3579+
34833580 static List <Account > insertAccounts () {
34843581 List <Account > accounts = new List <Account >{
34853582 new Account (Name = ' Test 1' ),
@@ -3534,31 +3631,4 @@ private class SOQL_Test {
3534363135353632 );
35363633 }
3537-
3538- @SuppressWarnings('PMD.ApexUnitTestClassShouldHaveAsserts')
3539- @IsTest
3540- static void preview () {
3541- // Test
3542- SOQL .of (Account .SObjectType ).preview ().toList ();
3543- }
3544-
3545- @SuppressWarnings('PMD.ApexUnitTestClassShouldHaveAsserts')
3546- @IsTest
3547- static void previewWithConditions () {
3548- // Test
3549- SOQL .of (Account .SObjectType )
3550- .whereAre (SOQL .FilterGroup
3551- .add (SOQL .Filter .with (Account .Name ).equal (' Test' ))
3552- .add (SOQL .Filter .with (Account .Industry ).equal (' IT' ))
3553- )
3554- .preview ()
3555- .toList ();
3556- }
3557-
3558- @SuppressWarnings('PMD.ApexUnitTestClassShouldHaveAsserts')
3559- @IsTest
3560- static void previewCount () {
3561- // Test
3562- SOQL .of (Account .SObjectType ).count ().preview ().toInteger ();
3563- }
35643634}
0 commit comments