Skip to content

Instantly share code, notes, and snippets.

@liuxiachanghong
Last active January 27, 2021 06:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save liuxiachanghong/146599eae9420d13f1cdd0a62685d900 to your computer and use it in GitHub Desktop.
Save liuxiachanghong/146599eae9420d13f1cdd0a62685d900 to your computer and use it in GitHub Desktop.
Following the AccountSearchController
@isTest
public with sharing class AccountSearchControllerTest {
@isTest
public static void testAccountSearchController() {
Account acct = new Account(Name ='Test ');
acct.BillingPostalCode = '106-0044';
acct.BillingCountry = 'JP';
acct.BillingState = '東京都';
acct.BillingCity = '港区';
acct.BillingStreet = '芝公園3-1-1';
acct.BillingLatitude = 35.661;
acct.BillingLongitude = 139.748;
insert acct;
List<Lead> leads = new List<Lead>();
Lead lead = new Lead (LastName ='Test ');
lead.PostalCode = '106-0044';
lead.Country = 'JP';
lead.State = '東京都';
lead.City = '港区';
lead.Street = '芝公園3-1-1';
lead.Latitude = 35.661;
lead.Longitude = 139.748;
insert lead;
Test.startTest();
Id [] fixedSearchResults= new Id[1];
fixedSearchResults[0] = acct.Id;
Test.setFixedSearchResults(fixedSearchResults);
List<Account> searchAccounts = AccountSearchController.searchAccounts(acct.BillingState,'option1',25,6);
System.assertEquals(false,searchAccounts.isEmpty());
Id [] fixedSearchResults1= new Id[1];
fixedSearchResults1[0] = acct.Id;
Test.setFixedSearchResults(fixedSearchResults1);
List<Account> searchAccounts1 = AccountSearchController.searchAccounts(null,'option1',25,6);
System.assertEquals('東京都',searchAccounts1[0].BillingState);
Id [] fixedSearchResults2= new Id[1];
fixedSearchResults2[0] = lead.Id;
Test.setFixedSearchResults(fixedSearchResults2);
List<Lead> searchLeads = AccountSearchController.searchLeads('東京都','option2',25,6);
System.assertEquals(false,searchLeads.isEmpty());
Id [] fixedSearchResults4= new Id[1];
fixedSearchResults4[0] = lead.Id;
Test.setFixedSearchResults(fixedSearchResults4);
List<Lead> searchLeads1 = AccountSearchController.searchLeads(null,'option2',25,6);
System.assertEquals('東京都',searchLeads1[0].State);
Test.stopTest();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment