@@ -3158,7 +3158,7 @@ private class SOQL_Test {
31583158 @IsTest
31593159 static void byId () {
31603160 // Setup
3161- Id fakeAccountId = SOQL .IdGenerator .get (' 001 ' );
3161+ Id fakeAccountId = SOQL .IdGenerator .get (Account . SObjectType );
31623162
31633163 // Test
31643164 SOQL .Queryable builder = SOQL .of (Account .SObjectType ).byId (fakeAccountId );
@@ -3190,7 +3190,7 @@ private class SOQL_Test {
31903190 @IsTest
31913191 static void byIdsSet () {
31923192 // Verify
3193- Set <Id > accountIds = new Set <Id >{ SOQL .IdGenerator .get (' 001 ' ) };
3193+ Set <Id > accountIds = new Set <Id >{ SOQL .IdGenerator .get (Account . SObjectType ) };
31943194
31953195 // Test
31963196 SOQL .Queryable builder = SOQL .of (Account .SObjectType ).byIds (accountIds );
@@ -3206,7 +3206,7 @@ private class SOQL_Test {
32063206 @IsTest
32073207 static void byIdsList () {
32083208 // Setup
3209- List <Id > accountIds = new List <Id >{ SOQL .IdGenerator .get (' 001 ' ) };
3209+ List <Id > accountIds = new List <Id >{ SOQL .IdGenerator .get (Account . SObjectType ) };
32103210
32113211 // Test
32123212 SOQL .Queryable builder = SOQL .of (Account .SObjectType ).byIds (accountIds );
@@ -3568,8 +3568,8 @@ private class SOQL_Test {
35683568 static void mockWithManyPlainFieldsWithId () {
35693569 // Setup
35703570 List <Account > accounts = new List <Account >{
3571- new Account (Id = SOQL .IdGenerator .get (' 001 ' ), Name = ' Test 1' , Description = ' Test 1 Description' , Website = ' www.beyondthecloud.dev' ),
3572- new Account (Id = SOQL .IdGenerator .get (' 001 ' ), Name = ' Test 2' , Description = ' Test 2 Description' , Website = ' www.beyondthecloud.dev' )
3571+ new Account (Id = SOQL .IdGenerator .get (Account . SObjectType ), Name = ' Test 1' , Description = ' Test 1 Description' , Website = ' www.beyondthecloud.dev' ),
3572+ new Account (Id = SOQL .IdGenerator .get (Account . SObjectType ), Name = ' Test 2' , Description = ' Test 2 Description' , Website = ' www.beyondthecloud.dev' )
35733573 };
35743574
35753575 // Test
@@ -3866,7 +3866,7 @@ private class SOQL_Test {
38663866 }
38673867
38683868 @IsTest
3869- static void mockStack () {
3869+ static void sObjectsMockStack () {
38703870 // Setup
38713871 SOQL .mock (' mockingQuery' ).thenReturn (new Account (Name = ' Test 1' ));
38723872 SOQL .mock (' mockingQuery' ).thenReturn (new Account (Name = ' Test 2' ));
@@ -3887,6 +3887,80 @@ private class SOQL_Test {
38873887 Assert .areEqual (' Test 3' , acc4 .Name , ' The returned account name should match the expected one.' );
38883888 }
38893889
3890+ @IsTest
3891+ static void countMockStack () {
3892+ // Setup
3893+ SOQL .mock (' mockingQuery' ).thenReturn (1 );
3894+ SOQL .mock (' mockingQuery' ).thenReturn (2 );
3895+ SOQL .mock (' mockingQuery' ).thenReturn (3 );
3896+
3897+ // Test
3898+ Integer result1 = SOQL .of (Account .SObjectType ).mockId (' mockingQuery' ).count ().toInteger ();
3899+ Integer result2 = SOQL .of (Account .SObjectType ).mockId (' mockingQuery' ).count ().toInteger ();
3900+ Integer result3 = SOQL .of (Account .SObjectType ).mockId (' mockingQuery' ).count ().toInteger ();
3901+ Integer result4 = SOQL .of (Account .SObjectType ).mockId (' mockingQuery' ).count ().toInteger ();
3902+
3903+ // Verify
3904+ Assert .areEqual (1 , result1 , ' The returned count should match the expected one.' );
3905+ Assert .areEqual (2 , result2 , ' The returned count should match the expected one.' );
3906+ Assert .areEqual (3 , result3 , ' The returned count should match the expected one.' );
3907+ Assert .areEqual (3 , result4 , ' The returned count should match the expected one.' );
3908+ }
3909+
3910+ @IsTest
3911+ static void aggregatedMockStack () {
3912+ // Setup
3913+ SOQL .mock (' mockingQuery' ).thenReturn (new Map <String , Object >{ ' LeadSource' = > ' Web' , ' total' = > 10 });
3914+ SOQL .mock (' mockingQuery' ).thenReturn (new Map <String , Object >{ ' LeadSource' = > ' Phone' , ' total' = > 5 });
3915+ SOQL .mock (' mockingQuery' ).thenReturn (new Map <String , Object >{ ' LeadSource' = > ' Email' , ' total' = > 3 });
3916+
3917+ // Test
3918+ List <SOQL .AggregateResultProxy > result1 = SOQL .of (Lead .SObjectType )
3919+ .with (Lead .LeadSource )
3920+ .COUNT (Lead .Id , ' total' )
3921+ .groupBy (Lead .LeadSource )
3922+ .mockId (' mockingQuery' )
3923+ .toAggregatedProxy ();
3924+
3925+ List <SOQL .AggregateResultProxy > result2 = SOQL .of (Lead .SObjectType )
3926+ .with (Lead .LeadSource )
3927+ .COUNT (Lead .Id , ' total' )
3928+ .groupBy (Lead .LeadSource )
3929+ .mockId (' mockingQuery' )
3930+ .toAggregatedProxy ();
3931+
3932+ List <SOQL .AggregateResultProxy > result3 = SOQL .of (Lead .SObjectType )
3933+ .with (Lead .LeadSource )
3934+ .COUNT (Lead .Id , ' total' )
3935+ .groupBy (Lead .LeadSource )
3936+ .mockId (' mockingQuery' )
3937+ .toAggregatedProxy ();
3938+
3939+ List <SOQL .AggregateResultProxy > result4 = SOQL .of (Lead .SObjectType )
3940+ .with (Lead .LeadSource )
3941+ .COUNT (Lead .Id , ' total' )
3942+ .groupBy (Lead .LeadSource )
3943+ .mockId (' mockingQuery' )
3944+ .toAggregatedProxy ();
3945+
3946+ // Verify
3947+ Assert .areEqual (1 , result1 .size (), ' The size of the aggregate results should match the mocked size.' );
3948+ Assert .areEqual (10 , result1 [0 ].get (' total' ), ' The total should match the expected one.' );
3949+ Assert .areEqual (' Web' , result1 [0 ].get (' LeadSource' ), ' The LeadSource should match the expected one.' );
3950+
3951+ Assert .areEqual (1 , result2 .size (), ' The size of the aggregate results should match the mocked size.' );
3952+ Assert .areEqual (5 , result2 [0 ].get (' total' ), ' The total should match the expected one.' );
3953+ Assert .areEqual (' Phone' , result2 [0 ].get (' LeadSource' ), ' The LeadSource should match the expected one.' );
3954+
3955+ Assert .areEqual (1 , result3 .size (), ' The size of the aggregate results should match the mocked size.' );
3956+ Assert .areEqual (3 , result3 [0 ].get (' total' ), ' The total should match the expected one.' );
3957+ Assert .areEqual (' Email' , result3 [0 ].get (' LeadSource' ), ' The LeadSource should match the expected one.' );
3958+
3959+ Assert .areEqual (1 , result4 .size (), ' The size of the aggregate results should match the mocked size.' );
3960+ Assert .areEqual (3 , result4 [0 ].get (' total' ), ' The total should match the expected one.' );
3961+ Assert .areEqual (' Email' , result4 [0 ].get (' LeadSource' ), ' The LeadSource should match the expected one.' );
3962+ }
3963+
38903964 @IsTest
38913965 static void toId () {
38923966 // Setup
@@ -4208,8 +4282,8 @@ private class SOQL_Test {
42084282 static void toMapWithMockingWhenOtherFieldsAreSpecified () {
42094283 // Setup
42104284 List <Account > accounts = new List <Account >{
4211- new Account (Id = SOQL .IdGenerator .get (' 001 ' ), Name = ' Test 1' , Description = ' Test 1 Description' , Website = ' www.beyondthecloud.dev' ),
4212- new Account (Id = SOQL .IdGenerator .get (' 001 ' ), Name = ' Test 2' , Description = ' Test 2 Description' , Website = ' www.beyondthecloud.dev' )
4285+ new Account (Id = SOQL .IdGenerator .get (Account . SObjectType ), Name = ' Test 1' , Description = ' Test 1 Description' , Website = ' www.beyondthecloud.dev' ),
4286+ new Account (Id = SOQL .IdGenerator .get (Account . SObjectType ), Name = ' Test 2' , Description = ' Test 2 Description' , Website = ' www.beyondthecloud.dev' )
42134287 };
42144288
42154289 // Test
@@ -4475,6 +4549,53 @@ private class SOQL_Test {
44754549 Assert .areEqual (' Too many SOQL queries.' , queryException .getMessage (), ' The synchronous query should have been exceeded.' );
44764550 }
44774551
4552+ @IsTest
4553+ static void queryConverterToIdsOf () {
4554+ // Setup
4555+ List <Account > accounts = new List <Account >{
4556+ new Account (Id = SOQL .IdGenerator .get (Account .SObjectType ), ParentId = SOQL .IdGenerator .get (Account .SObjectType )),
4557+ new Account (Id = SOQL .IdGenerator .get (Account .SObjectType ), ParentId = SOQL .IdGenerator .get (Account .SObjectType ))
4558+ };
4559+
4560+ // Test
4561+ Set <Id > accountIds = new SOQL .Converter (' Account' ).transform (accounts ).toIdsOf (Account .ParentId );
4562+
4563+ // Verify
4564+ Assert .areEqual (accounts .size (), accountIds .size (), ' The size of the returned set should be equal to the size of the inserted accounts.' );
4565+ }
4566+
4567+ @IsTest
4568+ static void queryConverterToIdsOfRelationshipField () {
4569+ // Setup
4570+ List <Account > accounts = new List <Account >{
4571+ new Account (Id = SOQL .IdGenerator .get (Account .SObjectType ), Parent = new Account (Id = SOQL .IdGenerator .get (Account .SObjectType ))),
4572+ new Account (Id = SOQL .IdGenerator .get (Account .SObjectType ), Parent = new Account (Id = SOQL .IdGenerator .get (Account .SObjectType )))
4573+ };
4574+
4575+ // Test
4576+ Set <Id > accountIds = new SOQL .Converter (' Account' ).transform (accounts ).toIdsOf (' Parent' , Account .Id );
4577+
4578+ // Verify
4579+ Assert .areEqual (accounts .size (), accountIds .size (), ' The size of the returned set should be equal to the size of the inserted accounts.' );
4580+ }
4581+
4582+ @IsTest
4583+ static void queryConverterToValuesOf () {
4584+ // Setup
4585+ List <Account > accounts = new List <Account >{
4586+ new Account (Id = SOQL .IdGenerator .get (Account .SObjectType ), Name = ' Test 1' ),
4587+ new Account (Id = SOQL .IdGenerator .get (Account .SObjectType ), Name = ' Test 2' )
4588+ };
4589+
4590+ // Test
4591+ Set <String > accountNames = new SOQL .Converter (' Account' ).transform (accounts ).toValuesOf (Account .Name );
4592+
4593+ // Verify
4594+ Assert .areEqual (accounts .size (), accountNames .size (), ' The size of the returned set should be equal to the size of the inserted accounts.' );
4595+ Assert .isTrue (accountNames .contains (' Test 1' ), ' The returned set should contain the account name "Test 1".' );
4596+ Assert .isTrue (accountNames .contains (' Test 2' ), ' The returned set should contain the account name "Test 2".' );
4597+ }
4598+
44784599 @SuppressWarnings('PMD.ApexUnitTestClassShouldHaveAsserts')
44794600 @IsTest
44804601 static void preview () {
0 commit comments