SHARE
TWEET

ContactsMockTest

a guest Mar 12th, 2015 221 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. @isTest
  2. private class ContactsMockTest
  3. {
  4.         @isTest
  5.     private static void contactConversionTest()
  6.     {
  7.         // Create Mocks
  8.         fflib_ApexMocks mocks = new fflib_ApexMocks();
  9.         fflib_ISObjectUnitOfWork uowMock = new fflib_SObjectMocks.SObjectUnitOfWork(mocks);
  10.         IContacts domainMock = new Mocks.Contacts(mocks);
  11.         IAccountsSelector selectorMock = new Mocks.AccountsSelector(mocks);
  12.        
  13.         // Given
  14.         mocks.startStubbing();
  15.        
  16.         List<Account> myAccounts = new List<Account>();
  17.         myAccounts.add(new Account(Id = fflib_IDGenerator.generate(Account.SObjectType), Name = 'Old Account'));
  18.         myAccounts.add(new Account(Id = fflib_IDGenerator.generate(Account.SObjectType), Name = 'New Account'));
  19.        
  20.         Id contactId = fflib_IDGenerator.generate(Contact.SObjectType);
  21.         Contact oldCon = new Contact(
  22.                 Id = contactId,
  23.             AccountId = myAccounts[0].Id,
  24.             FirstName = 'OldTest',
  25.             LastName = 'Contact'
  26.         );
  27.         Contact con = new Contact(
  28.                 Id = contactId,
  29.             AccountId = myAccounts[1].Id,
  30.             FirstName = 'NewTest',
  31.             LastName = 'Contact'
  32.         );
  33.        
  34.         mocks.when(selectorMock.selectById(new Set<Id>{myAccounts[0].Id})).thenReturn(myAccounts[0]);
  35.         mocks.when(selectorMock.selectById(new Set<Id>{myAccounts[1].Id})).thenReturn(myAccounts[1]);
  36.        
  37.         mocks.stopStubbing();
  38.        
  39.         Application.UnitOfWork.setMock(uowMock);
  40.                 Application.Domain.setMock(domainMock);
  41.                 Application.Selector.setMock(selectorMock);
  42.        
  43.         // When
  44.         IContacts contactsInstance = Contacts.newInstance(new List<Contact>{con});
  45.         contactsInstance.conversion(new Map<Id, Contact>(new List<Contact>{oldCon}), uowMock, FALSE);
  46.     }
  47. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top