@@ -59,43 +59,46 @@ private class AccountSloganRelatedTest
5959 static void givenNewAccountWhenCreatedWithFishNameThenSelectorMethodInjection ()
6060 {
6161 // given
62+ fflib_ApexMocks mocks = new fflib_ApexMocks ();
63+
6264 String slogan = ' The Big Blue Fish is a fishy business' ;
6365
66+ // Setup the test record to be returned by the mock selector
6467 Account bluefishAccount = new Account ();
65-
6668 bluefishAccount .Id = fflib_IDGenerator .generate ( Account .SObjectType );
6769 bluefishAccount .name = ' bluefish' ;
6870 bluefishAccount .slogan__c = slogan ;
6971
70- fflib_ApexMocks mocks = new fflib_ApexMocks ();
72+ List <Account > testRecords = new List <Account >();
73+ testRecords .add (bluefishAccount );
7174
75+ // Setup the mocks needed for the test
7276 IAccountsSelector mockAccountsSelector = (IAccountsSelector ) mocks .mock ( IAccountsSelector .class );
7377
78+ // Setup the injection parameter class
79+ SelectBySloganSelectorMethod .Parameters queryParams = new SelectBySloganSelectorMethod .Parameters ();
80+ queryParams .sloganNameSet = new Set <String >{ slogan };
81+
82+ // Stub the mocks
7483 mocks .startStubbing ();
7584
76- SelectBySloganSelectorMethod .Parameters queryParams = new SelectBySloganSelectorMethod .Parameters ();
85+ fflib_MethodReturnValue mockAccountsSelectorMethodReturnValue = mocks .when (mockAccountsSelector .selectInjection (SelectBySloganSelectorMethod .class , queryParams ));
86+ mockAccountsSelectorMethodReturnValue .thenReturn (testRecords );
87+ mocks .when (mockAccountsSelector .sObjectType ()).thenReturn (Account .SObjectType );
7788
78- queryParams . sloganNameSet = new Set < String >{ slogan } ;
89+ mocks . stopStubbing () ;
7990
91+ Application .Selector .setMock (mockAccountsSelector );
92+
8093 // when
8194 Test .startTest ();
8295
83- system . debug ( AccountsSelector .newInstance ().selectInjection ( SelectBySloganSelectorMethod .class , queryParams ) );
96+ List < Account > accountsQueried = AccountsSelector .newInstance ().selectInjection ( SelectBySloganSelectorMethod .class , queryParams );
8497
8598 Test .stopTest ();
8699
87100 // then
88-
89- // list<Account> accountRecordsQueried = AccountsSelector.newInstance().selectById( new Set<id>{ bluefishAccount.Id } );
90-
91- // System.assert( ! accountRecordsQueried.isEmpty() );
92- // System.assert( accountRecordsQueried.size() == 1 );
93-
94- // Account accountRecordQueried = accountRecordsQueried[0];
95-
96- // System.assert( String.isNotBlank( accountRecordQueried.Slogan__c ) );
101+ System .debug (' accountsQueried size: ' + accountsQueried .size ());
102+ ((IAccountsSelector )mocks .verify (mockAccountsSelector )).selectInjection ( SelectBySloganSelectorMethod .class , queryParams );
97103 }
98-
99-
100-
101104}
0 commit comments