Skip to content

Commit f5cf449

Browse files
committed
Refactoring
1 parent 870450f commit f5cf449

File tree

1 file changed

+29
-5
lines changed

1 file changed

+29
-5
lines changed

force-app/main/default/classes/main/cached-soql/SOQLCache_Test.cls

Lines changed: 29 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ private class SOQLCache_Test {
2020
new Profile(Name = 'System Administrator'),
2121
new Profile(Name = 'Standard User')
2222
};
23-
SOQL.setMock(INITIAL_QUERY_MOCK_ID, mockedProfiles);
23+
SOQL.mock(INITIAL_QUERY_MOCK_ID).thenReturn(mockedProfiles);
2424

2525
// Test
2626
new SOQL_ProfileCache().whereEqual('Name', 'System Administrator').toObject(); // initial query will be executed
@@ -406,7 +406,7 @@ private class SOQLCache_Test {
406406
@IsTest
407407
static void mockId() {
408408
// Setup
409-
SOQLCache.setMock('ProfileQuery', new Profile(Id = '00e3V000000Nme3QAC', Name = 'System Administrator'));
409+
SOQLCache.mock('ProfileQuery').thenReturn(new Profile(Id = '00e3V000000Nme3QAC', Name = 'System Administrator'));
410410

411411
// Test
412412
Profile profile = (Profile) new SOQL_ProfileCache().query()
@@ -419,6 +419,30 @@ private class SOQLCache_Test {
419419
Assert.areEqual('System Administrator', profile.Name, 'The profile name should be the same as the name assigned to the profile cache.');
420420
}
421421

422+
@IsTest
423+
static void mockStack() {
424+
// Setup
425+
SOQL.mock('mockingQuery').thenReturn(new Profile(Name = 'Test 1'));
426+
SOQL.mock('mockingQuery').thenReturn(new Profile(Name = 'Test 2'));
427+
SOQL.mock('mockingQuery').thenReturn(new Profile(Name = 'Test 3'));
428+
429+
// Test
430+
SOQLCache.Cacheable query = SOQLCache.of(Profile.SObjectType)
431+
.mockId('mockingQuery')
432+
.whereEqual(Profile.Name, 'System Administrator');
433+
434+
Profile profile1 = (Profile) query.toObject();
435+
Profile profile2 = (Profile) query.toObject();
436+
Profile profile3 = (Profile) query.toObject();
437+
Profile profile4 = (Profile) query.toObject();
438+
439+
// Verify
440+
Assert.areEqual('Test 1', profile1.Name, 'The profile name should be the same as the name assigned to the profile cache.');
441+
Assert.areEqual('Test 2', profile2.Name, 'The profile name should be the same as the name assigned to the profile cache.');
442+
Assert.areEqual('Test 3', profile3.Name, 'The profile name should be the same as the name assigned to the profile cache.');
443+
Assert.areEqual('Test 3', profile4.Name, 'The profile name should be the same as the name assigned to the profile cache.');
444+
}
445+
422446
@SuppressWarnings('PMD.ApexUnitTestClassShouldHaveAsserts')
423447
@IsTest
424448
static void preview() {
@@ -510,7 +534,7 @@ private class SOQLCache_Test {
510534
@IsTest
511535
static void toObjectWithMultipleRows() {
512536
// Setup
513-
SOQL.setMock('ProfileQuery', new List<Profile>{
537+
SOQL.mock('ProfileQuery').thenReturn(new List<Profile>{
514538
new Profile(Id = '00e3V000000Nme3QAC', Name = 'System Administrator'),
515539
new Profile(Id = '00e3V000000Nme3QAC', Name = 'System Administrator')
516540
});
@@ -535,7 +559,7 @@ private class SOQLCache_Test {
535559
@IsTest
536560
static void recordNotFoundInCache() {
537561
// Setup
538-
SOQL.setMock('ProfileQuery', new Profile(Id = '00e3V000000Nbc3QAC', Name = 'Guest User'));
562+
SOQL.mock('ProfileQuery').thenReturn(new Profile(Id = '00e3V000000Nbc3QAC', Name = 'Guest User'));
539563

540564
// Test
541565
Profile profile = (Profile) SOQLCache.of(Profile.SObjectType)
@@ -552,7 +576,7 @@ private class SOQLCache_Test {
552576
@IsTest
553577
static void recordNotFoundInCacheAndNotExistInDatabase() {
554578
// Setup
555-
SOQL.setMock('ProfileQuery', new List<Profile>());
579+
SOQL.mock('ProfileQuery').thenReturn(new List<Profile>());
556580

557581
// Test
558582
Profile profile = (Profile) SOQLCache.of(Profile.SObjectType)

0 commit comments

Comments
 (0)