33 * Licensed under the MIT License (https://github.com/beyond-the-cloud-dev/soql-lib/blob/main/LICENSE)
44 *
55 * v6.0.0
6- *
6+ *
77 * PMD False Positives:
88 * - CyclomaticComplexity: It is a library and we tried to put everything into ONE test class
99 * - CognitiveComplexity: It is a library and we tried to put everything into ONE test class
@@ -3893,7 +3893,7 @@ private class SOQL_Test {
38933893 SOQL .mock (' mockingQuery' ).thenReturn (1 );
38943894 SOQL .mock (' mockingQuery' ).thenReturn (2 );
38953895 SOQL .mock (' mockingQuery' ).thenReturn (3 );
3896-
3896+
38973897 // Test
38983898 Integer result1 = SOQL .of (Account .SObjectType ).mockId (' mockingQuery' ).count ().toInteger ();
38993899 Integer result2 = SOQL .of (Account .SObjectType ).mockId (' mockingQuery' ).count ().toInteger ();
@@ -3913,7 +3913,7 @@ private class SOQL_Test {
39133913 SOQL .mock (' mockingQuery' ).thenReturn (new Map <String , Object >{ ' LeadSource' = > ' Web' , ' total' = > 10 });
39143914 SOQL .mock (' mockingQuery' ).thenReturn (new Map <String , Object >{ ' LeadSource' = > ' Phone' , ' total' = > 5 });
39153915 SOQL .mock (' mockingQuery' ).thenReturn (new Map <String , Object >{ ' LeadSource' = > ' Email' , ' total' = > 3 });
3916-
3916+
39173917 // Test
39183918 List <SOQL .AggregateResultProxy > result1 = SOQL .of (Lead .SObjectType )
39193919 .with (Lead .LeadSource )
@@ -3974,6 +3974,18 @@ private class SOQL_Test {
39743974 Assert .areEqual (acc .Id , accountId , ' The returned Id should match the expected one.' );
39753975 }
39763976
3977+ @IsTest
3978+ static void toIdWithMocking () {
3979+ // Setup
3980+ SOQL .mock (' mockingQuery' ).thenReturn (new Account (Name = ' Test 1' ));
3981+
3982+ // Test
3983+ Id accountId = SOQL .of (Account .SObjectType ).mockId (' mockingQuery' ).toId ();
3984+
3985+ // Verify
3986+ Assert .isNotNull (accountId , ' The returned Id should match the expected one.' );
3987+ }
3988+
39773989 @IsTest
39783990 static void toIds () {
39793991 // Setup
@@ -3986,6 +3998,21 @@ private class SOQL_Test {
39863998 Assert .areEqual (accounts .size (), accountIds .size (), ' The size of the returned set should be equal to the size of the inserted accounts.' );
39873999 }
39884000
4001+ @IsTest
4002+ static void toIdsWithMocking () {
4003+ // Setup
4004+ SOQL .mock (' mockingQuery' ).thenReturn (new List <SObject >{
4005+ new Account (Name = ' Test 1' ),
4006+ new Account (Name = ' Test 2' )
4007+ });
4008+
4009+ // Test
4010+ Set <Id > accountIds = SOQL .of (Account .SObjectType ).mockId (' mockingQuery' ).toIds ();
4011+
4012+ // Verify
4013+ Assert .areEqual (2 , accountIds .size (), ' The size of the returned set should be equal to the size of the mocked accounts.' );
4014+ }
4015+
39894016 @IsTest
39904017 static void toIdsOf () {
39914018 // Setup
@@ -3998,6 +4025,30 @@ private class SOQL_Test {
39984025 Assert .areEqual (accounts .size (), parentIds .size (), ' The size of the returned set should be equal to the size of the inserted accounts.' );
39994026 }
40004027
4028+ @IsTest
4029+ static void toIdsOfWithMocking () {
4030+ // Setup
4031+ SOQL .mock (' mockingQuery' ).thenReturn (
4032+ (List <AggregateResult >) JSON .deserialize (
4033+ JSON .serialize (new List <Map <String , Object >>{
4034+ new Map <String , Object >{
4035+ ' Id' = > SOQL .IdGenerator .get (Account .SObjectType )
4036+ },
4037+ new Map <String , Object >{
4038+ ' Id' = > SOQL .IdGenerator .get (Account .SObjectType )
4039+ }
4040+ }),
4041+ List <AggregateResult >.class
4042+ )
4043+ );
4044+
4045+ // Test
4046+ Set <Id > parentIds = SOQL .of (Account .SObjectType ).mockId (' mockingQuery' ).toIdsOf (Account .ParentId );
4047+
4048+ // Verify
4049+ Assert .areEqual (2 , parentIds .size (), ' The size of the returned set should be equal to the size of the mocked accounts.' );
4050+ }
4051+
40014052 @IsTest
40024053 static void toIdsOfRelationshipField () {
40034054 // Setup
@@ -4010,6 +4061,25 @@ private class SOQL_Test {
40104061 Assert .areEqual (1 , createdByIds .size (), ' The size of the returned set should be 1, because the same user inserted the accounts.' );
40114062 }
40124063
4064+ @IsTest
4065+ static void toIdsOfRelationshipFieldWithMocking () {
4066+ // Setup
4067+ SOQL .mock (' mockingQuery' ).thenReturn (
4068+ (AggregateResult ) JSON .deserialize (
4069+ JSON .serialize (new Map <String , Object >{
4070+ ' Id' = > SOQL .IdGenerator .get (User .SObjectType )
4071+ }),
4072+ AggregateResult .class
4073+ )
4074+ );
4075+
4076+ // Test
4077+ Set <Id > createdByIds = SOQL .of (Account .SObjectType ).mockId (' mockingQuery' ).toIdsOf (' Parent' , Account .CreatedById );
4078+
4079+ // Verify
4080+ Assert .areEqual (1 , createdByIds .size (), ' The size of the returned set should be 1, because the same user inserted the accounts.' );
4081+ }
4082+
40134083 @IsTest
40144084 static void doExist () {
40154085 // Setup
@@ -4488,7 +4558,7 @@ private class SOQL_Test {
44884558 new Account (Name = ' Test 1' ),
44894559 new Account (Name = ' Test 2' )
44904560 });
4491-
4561+
44924562 // Test
44934563 try {
44944564 Test .startTest ();
@@ -4559,9 +4629,9 @@ private class SOQL_Test {
45594629
45604630 // Test
45614631 Set <Id > accountIds = new SOQL .Converter (' Account' ).transform (accounts ).toIdsOf (Account .ParentId );
4562-
4632+
45634633 // Verify
4564- Assert .areEqual (accounts .size (), accountIds .size (), ' The size of the returned set should be equal to the size of the inserted accounts.' );
4634+ Assert .areEqual (accounts .size (), accountIds .size (), ' The size of the returned set should be equal to the size of the inserted accounts.' );
45654635 }
45664636
45674637 @IsTest
@@ -4574,9 +4644,9 @@ private class SOQL_Test {
45744644
45754645 // Test
45764646 Set <Id > accountIds = new SOQL .Converter (' Account' ).transform (accounts ).toIdsOf (' Parent' , Account .Id );
4577-
4647+
45784648 // Verify
4579- Assert .areEqual (accounts .size (), accountIds .size (), ' The size of the returned set should be equal to the size of the inserted accounts.' );
4649+ Assert .areEqual (accounts .size (), accountIds .size (), ' The size of the returned set should be equal to the size of the inserted accounts.' );
45804650 }
45814651
45824652 @IsTest
@@ -4589,7 +4659,7 @@ private class SOQL_Test {
45894659
45904660 // Test
45914661 Set <String > accountNames = new SOQL .Converter (' Account' ).transform (accounts ).toValuesOf (Account .Name );
4592-
4662+
45934663 // Verify
45944664 Assert .areEqual (accounts .size (), accountNames .size (), ' The size of the returned set should be equal to the size of the inserted accounts.' );
45954665 Assert .isTrue (accountNames .contains (' Test 1' ), ' The returned set should contain the account name "Test 1".' );
0 commit comments