You need to sign in to do that
Don't have an account?
reem sharawy
how to cover page reference in test class
my apex class for pagination is only covered by 19%
Test Class
public class ListPaginationBase { public Integer listSize {get; set;} public Integer pageSize {get; set;} public Integer currentPageIndex {get; set;} public List<Object> fullList {get; set;} public void initializePagination(Integer listTotalSize, Integer singlePageSize) { fullList = new List<Object>(); listSize = listTotalSize; pageSize = singlePageSize; currentPageIndex = 0; } public void initializePagination(List<Object> objectList, Integer singlePageSize) { fullList = ObjectList; listSize = fullList.size(); pageSize = singlePageSize; currentPageIndex = 0; } public Integer getPageCount() { //Returns the number of pages required to show all data given a page limit //if page limit is not set or is equal to zero, then return 1; dont divide by zero //is empty list then return 1 if (pageSize <= 0 || listSize <= 0) return 1; else return (Integer) Math.ceil((Decimal)listSize / (Decimal)pageSize); } public Boolean getHasNext() { //Returns true if the list has next pages return currentPageIndex < (getPageCount() - 1); } public Boolean getHasPrevious() { //Returns true if the list has previous pages return currentPageIndex > 0; } public Integer getfirstRowIndex() { //Returns the index of the first row to show in the PageBlockTable using the first attribute return currentPageIndex * pageSize; } public List<Object> getObjectPageList() { List<Object> returnList = new List<Object>(); for(Integer index = getFirstRowIndex(); index < getFirstRowIndex() + pageSize; index++) { if (index < fullList.size()) { returnList.add(fullList.get(index)); } } return returnList; } public PageReference firstAction() { //Action fired when the user click the First Button //Set the Page Index to Zero if(getHasPrevious()) currentPageIndex = 0; return null; } public PageReference lastAction() { //Action fired when the user click the Last Button //Set the Page Index to pages count - 1 if(getHasNext()) currentPageIndex = getPageCount() - 1; return null; } public PageReference nextAction() { //Action fired when the user click the Next Button //increment the current page index by 1 if(getHasNext()) currentPageIndex++; return null; } public PageReference previousAction() { //Action fired when the user click the Last Button //decrement the current page index by 1 if(getHasPrevious()) currentPageIndex--; return null; } }
Test Class
@isTest (SeeAllData=true) private class TESTAccountOpportunityTabExtension { static testmethod void AccountOpportunityTabExtension_Test (){ test.StartTest(); Account acc = new Account(Name ='icrm testing acc'); insert acc; opportunity opp = new opportunity ( Name='testing DIE 4/6/2015' , AccountId= acc.Id,StageName = 'Prospecting', type= 'parts', Description= 'describe', Inconterms__c = 'FCA', CloseDate = System.today().addDays(30)); insert opp; opportunity opps = new opportunity ( id = '0068E0000060EhbQAE', Name='testing DIE 4/6/2015' , AccountId= acc.Id,StageName = 'Prospecting', type= 'Sales', Opportunity_Division__c = 'PRODUCT SUPPORT', Description= 'describe', Inconterms__c = 'FCA', CloseDate = System.today().addDays(30)); update opps; opportunity Deltaopp = new opportunity ( id = '0068E000009BCivQAG', Name='testing DIE 4/6/2015' , AccountId= acc.Id,StageName = 'Prospecting', type= 'Sales', Opportunity_Division__c = 'POWER SYSTEM-DELTA(PERKINS)', Description= 'describe', Inconterms__c = 'FCA', CloseDate = System.today().addDays(30)); update Deltaopp; opportunity EnginePowerGenerationaopp = new opportunity ( id = '0068E000008Myy4QAC', Name='testing DIE 4/6/2015' , AccountId= acc.Id,StageName = 'Prospecting', type= 'Sales', Opportunity_Division__c = 'ENGINE POWER GENERATION', Description= 'describe', Inconterms__c = 'FCA', CloseDate = System.today().addDays(30)); update EnginePowerGenerationaopp ; opportunity Otheropp = new opportunity ( id = '0068E000009BDvgQAG', Name='testing DIE 4/6/2015' , AccountId= acc.Id,StageName = 'Prospecting', type= 'Sales', Opportunity_Division__c = 'OTHERS MISC - INTERNAL', Description= 'describe', Inconterms__c = 'FCA', CloseDate = System.today().addDays(30)); update Otheropp ; PageReference pref = Page.Opp_Tabs; pref.getParameters().put('id', acc.id); Test.setCurrentPage(pref); ApexPages.StandardController sc = new ApexPages.StandardController(acc); AccountOpportunityTabExtension mc = new AccountOpportunityTabExtension(sc); PageReference result = mc.NewOpp(); System.assertNotEquals(null, result); PageReference result2 = mc.sortConstructionPaginationList(); System.assertNotEquals(null, result); PageReference result3 = mc.sortProductSupportPaginationList(); System.assertNotEquals(null, result); PageReference result4 = mc.sortPowerSystemPaginationList(); System.assertNotEquals(null, result); PageReference result5 = mc.sortDeltaPaginationList(); System.assertNotEquals(null, result); PageReference result6 = mc.sortOtherPaginationList(); System.assertNotEquals(null, result); test.stopTest(); } }