You need to sign in to do that
Don't have an account?
reem sharawy
page reference in test class
Hello
I can't have trouble covering my page reference in test class
test class
I can't have trouble covering my page reference in test class
public class AccountInvoiceTabExtension { public ListPaginationBase ConstructionPaginationBaseObject {get; set;} public ListPaginationBase DeltaPaginationBaseObject {get; set;} public ListPaginationBase EnginePowerGenerationPaginationBaseObject {get; set;} public ListPaginationBase MiningPaginationBaseObject {get; set;} public ListPaginationBase ProductSupportPaginationBaseObject {get; set;} public ListPaginationBase SamsungPaginationBaseObject {get; set;} public ListPaginationBase OtherPaginationBaseObject {get; set;} public List<InvoiceWrapper> ConstructionInvoiceList {get; set;} public List<InvoiceWrapper> DeltaInvoiceList {get; set;} public List<InvoiceWrapper> EnginePowerGenerationInvoiceList {get; set;} public List<InvoiceWrapper> MiningInvoiceList {get; set;} public List<InvoiceWrapper> ProductSupportInvoiceList {get; set;} public List<InvoiceWrapper> SamsungInvoiceList {get; set;} public List<InvoiceWrapper> OtherInvoiceList {get; set;} public String constructionInvoiceSort {get; set;} public boolean constructionInvoiceSortDesc {get; set;} public String DeltaInvoiceSort {get; set;} public boolean DeltaInvoiceSortDesc {get; set;} public String EnginePowerGenerationInvoiceSort {get; set;} public boolean EnginePowerGenerationInvoiceSortDesc {get; set;} public String MiningInvoiceSort {get; set;} public boolean MiningInvoiceSortDesc {get; set;} public String ProductSupportInvoiceSort {get; set;} public boolean ProductSupportInvoiceSortDesc {get; set;} public String SamsungInvoiceSort {get; set;} public boolean SamsungInvoiceSortDesc {get; set;} public String OtherInvoiceSort {get; set;} public boolean OtherInvoiceSortDesc {get; set;} public Account currentAccount {get; set;} public AccountInvoiceTabExtension(ApexPages.StandardController controller) { currentAccount = (Account) controller.getRecord(); constructionInvoiceSort = 'Name'; constructionInvoiceSortDesc = false; DeltaInvoiceSort = 'Name'; DeltaInvoiceSortDesc = false; EnginePowerGenerationInvoiceSort = 'Name'; EnginePowerGenerationInvoiceSortDesc = false; MiningInvoiceSort = 'Name'; MiningInvoiceSortDesc = false; ProductSupportInvoiceSort = 'Name'; ProductSupportInvoiceSortDesc = false; SamsungInvoiceSort = 'Name'; SamsungInvoiceSortDesc = false; OtherInvoiceSort = 'Name'; OtherInvoiceSortDesc = false; refreshConstructionInvoiceList(); refreshDeltaInvoiceList (); refreshEnginePowerGenerationInvoiceList(); refreshMiningPaginationList(); refreshProductSupportInvoiceList(); refreshSamsungInvoiceList(); refreshOtherInvoiceList(); } public PageReference sortConstructionPaginationList() { refreshConstructionInvoiceList(); return null; } public PageReference sortDeltaPaginationList() { refreshDeltaInvoiceList(); return null; } public PageReference sortEnginePowerGenerationPaginationList() { refreshEnginePowerGenerationInvoiceList(); return null; } public PageReference sortMiningPaginationList() { refreshMiningPaginationList(); return null; } public PageReference sortProductSupportPaginationList() { refreshProductSupportInvoiceList(); return null; } public PageReference sortSamsungPaginationList() { refreshSamsungInvoiceList(); return null; } public PageReference sortOtherPaginationList() { refreshOtherInvoiceList(); return null; } private void refreshConstructionInvoiceList() { getConstructionInvoiceList(); constructionPaginationBaseObject = new ListPaginationBase(); constructionPaginationBaseObject.initializePagination(ConstructionInvoiceList, 20); } private void refreshDeltaInvoiceList() { getDeltaInvoiceList(); DeltaPaginationBaseObject = new ListPaginationBase(); DeltaPaginationBaseObject.initializePagination(DeltaInvoiceList, 20); } private void refreshEnginePowerGenerationInvoiceList() { getEnginePowerGenerationInvoiceList(); EnginePowerGenerationPaginationBaseObject = new ListPaginationBase(); EnginePowerGenerationPaginationBaseObject.initializePagination(EnginePowerGenerationInvoiceList, 20); } private void refreshMiningPaginationList() { getMiningInvoiceList(); MiningPaginationBaseObject = new ListPaginationBase(); MiningPaginationBaseObject.initializePagination(MiningInvoiceList, 20); } private void refreshProductSupportInvoiceList() { getProductSupportInvoiceList (); ProductSupportPaginationBaseObject = new ListPaginationBase(); ProductSupportPaginationBaseObject.initializePagination(ProductSupportInvoiceList, 20); } private void refreshSamsungInvoiceList() { getSamsungInvoiceList(); SamsungPaginationBaseObject = new ListPaginationBase(); SamsungPaginationBaseObject.initializePagination(SamsungInvoiceList, 20); } private void refreshOtherInvoiceList() { getOtherInvoiceList(); OtherPaginationBaseObject = new ListPaginationBase(); OtherPaginationBaseObject.initializePagination(OtherInvoiceList, 20); } public class InvoiceWrapper { public Id InvoiceId {get; set;} public String orderNumber {get; set;} public Date InvoiceDate {get; set;} public String OrderType {get; set;} public String ModelDescription {get; set;} public String InvoiceType {get; set;} public String OrderTaking {get; set;} public double TotalSellVAT {get; set;} public String CostCenter {get; set;} public String CostCenterDivision {get; set;} public Id ordertakingid {get; set;} } private void getConstructionInvoiceList() { ConstructionInvoiceList = new List<InvoiceWrapper>(); String soqlQuery = 'SELECT Id, Name, Cost_Centre_Main_Division__c, Cost_Center_Division__c, Invoice_Date__c, Order_Type__c, Model_Description__c, Invoice_Type__c, Order_Taking__r.name, Order_Taking__r.id, Total_Price_Net__c, Cost_Center__c'; soqlQuery += ' FROM Order_ManPro__c '; soqlQuery += ' WHERE Account_order__c = \'' + currentAccount.Id + '\''; soqlQuery += ' AND Cost_Centre_Main_Division__c = \'CONSTRUCTION ALL\''; soqlQuery += ' ORDER BY ' + constructionInvoiceSort; if (constructionInvoiceSortDesc) soqlQuery += ' DESC'; for (Order_ManPro__c constInvoice : Database.query(soqlQuery)) { InvoiceWrapper wrapper = new InvoiceWrapper(); wrapper.InvoiceId = constInvoice.Id; wrapper.orderNumber = constInvoice.Name; wrapper.InvoiceDate = constInvoice.Invoice_Date__c; wrapper.OrderType = constInvoice.Order_Type__c; wrapper.ModelDescription = constInvoice.Model_Description__c; wrapper.InvoiceType = constInvoice.Invoice_Type__c; wrapper.OrderTaking = constInvoice.Order_Taking__r.name; wrapper.ordertakingid = constInvoice.Order_Taking__r.id; wrapper.TotalSellVAT = constInvoice.Total_Price_Net__c; wrapper.CostCenter = constInvoice.Cost_Center__c; wrapper.CostCenterDivision = constInvoice.Cost_Center_Division__c; ConstructionInvoiceList.add(wrapper); } } private void getDeltaInvoiceList() { DeltaInvoiceList = new List<InvoiceWrapper>(); String soqlQuery = 'SELECT Id, Name, Cost_Centre_Main_Division__c, Account_order__c, Cost_Center_Division__c, Invoice_Date__c, Order_Type__c, Model_Description__c, Invoice_Type__c, Order_Taking__r.name, Total_Price_Net__c, Cost_Center__c'; soqlQuery += ' FROM Order_ManPro__c '; soqlQuery += ' WHERE Account_order__c = \'' + currentAccount.Id + '\''; soqlQuery += ' AND Cost_Centre_Main_Division__c = \'DELTA\''; soqlQuery += ' ORDER BY ' + DeltaInvoiceSort; if (DeltaInvoiceSortDesc) soqlQuery += ' DESC'; for (Order_ManPro__c DeltaInvoice : Database.query(soqlQuery)) { InvoiceWrapper wrapper = new InvoiceWrapper(); wrapper.InvoiceId = DeltaInvoice.Id; wrapper.orderNumber = DeltaInvoice.Name; wrapper.InvoiceDate = DeltaInvoice.Invoice_Date__c; wrapper.OrderType = DeltaInvoice.Order_Type__c; wrapper.ModelDescription = DeltaInvoice.Model_Description__c; wrapper.InvoiceType = DeltaInvoice.Invoice_Type__c; wrapper.OrderTaking = DeltaInvoice.Order_Taking__r.name; wrapper.ordertakingid = DeltaInvoice.Order_Taking__r.id; wrapper.TotalSellVAT = DeltaInvoice.Total_Price_Net__c; wrapper.CostCenter = DeltaInvoice.Cost_Center__c; wrapper.CostCenterDivision = DeltaInvoice.Cost_Center_Division__c; DeltaInvoiceList.add(wrapper); } } private void getEnginePowerGenerationInvoiceList() { EnginePowerGenerationInvoiceList = new List<InvoiceWrapper>(); String soqlQuery = 'SELECT Id, Name, Cost_Centre_Main_Division__c, Account_order__c, Cost_Center_Division__c, Invoice_Date__c, Order_Type__c, Model_Description__c, Invoice_Type__c, Order_Taking__r.name, Total_Price_Net__c, Cost_Center__c'; soqlQuery += ' FROM Order_ManPro__c '; soqlQuery += ' WHERE Account_order__c = \'' + currentAccount.Id + '\''; soqlQuery += ' AND Cost_Centre_Main_Division__c = \'ENGINE POWER GENERATION\''; soqlQuery += ' ORDER BY ' + EnginePowerGenerationInvoiceSort; if (EnginePowerGenerationInvoiceSortDesc) soqlQuery += ' DESC'; for (Order_ManPro__c EnginePowerGenerationInvoice : Database.query(soqlQuery)) { InvoiceWrapper wrapper = new InvoiceWrapper(); wrapper.InvoiceId = EnginePowerGenerationInvoice.Id; wrapper.orderNumber = EnginePowerGenerationInvoice.Name; wrapper.InvoiceDate = EnginePowerGenerationInvoice.Invoice_Date__c; wrapper.OrderType = EnginePowerGenerationInvoice.Order_Type__c; wrapper.ModelDescription = EnginePowerGenerationInvoice.Model_Description__c; wrapper.InvoiceType = EnginePowerGenerationInvoice.Invoice_Type__c; wrapper.OrderTaking = EnginePowerGenerationInvoice.Order_Taking__r.name; wrapper.ordertakingid = EnginePowerGenerationInvoice.Order_Taking__r.id; wrapper.TotalSellVAT = EnginePowerGenerationInvoice.Total_Price_Net__c; wrapper.CostCenter = EnginePowerGenerationInvoice.Cost_Center__c; wrapper.CostCenterDivision = EnginePowerGenerationInvoice.Cost_Center_Division__c; EnginePowerGenerationInvoiceList.add(wrapper); } } private void getMiningInvoiceList() { MiningInvoiceList = new List<InvoiceWrapper>(); String soqlQuery = 'SELECT Id, Name, Cost_Centre_Main_Division__c, Account_order__c, Cost_Center_Division__c, Invoice_Date__c, Order_Type__c, Model_Description__c, Invoice_Type__c, Order_Taking__r.name, Total_Price_Net__c, Cost_Center__c'; soqlQuery += ' FROM Order_ManPro__c '; soqlQuery += ' WHERE Account_order__c = \'' + currentAccount.Id + '\''; soqlQuery += ' AND Cost_Centre_Main_Division__c = \'MINING\''; soqlQuery += ' ORDER BY ' + MiningInvoiceSort; if (MiningInvoiceSortDesc) soqlQuery += ' DESC'; for (Order_ManPro__c MiningInvoice : Database.query(soqlQuery)) { InvoiceWrapper wrapper = new InvoiceWrapper(); wrapper.InvoiceId = MiningInvoice.Id; wrapper.orderNumber = MiningInvoice.Name; wrapper.InvoiceDate = MiningInvoice.Invoice_Date__c; wrapper.OrderType = MiningInvoice.Order_Type__c; wrapper.ModelDescription = MiningInvoice.Model_Description__c; wrapper.InvoiceType = MiningInvoice.Invoice_Type__c; wrapper.OrderTaking = MiningInvoice.Order_Taking__r.name; wrapper.ordertakingid = MiningInvoice.Order_Taking__r.id; wrapper.TotalSellVAT = MiningInvoice.Total_Price_Net__c; wrapper.CostCenter = MiningInvoice.Cost_Center__c; wrapper.CostCenterDivision = MiningInvoice.Cost_Center_Division__c; MiningInvoiceList.add(wrapper); } } private void getProductSupportInvoiceList() { ProductSupportInvoiceList = new List<InvoiceWrapper>(); String soqlQuery = 'SELECT Id, Name, Cost_Centre_Main_Division__c, Account_order__c, Cost_Center_Division__c, Invoice_Date__c, Order_Type__c, Model_Description__c, Invoice_Type__c, Order_Taking__r.name, Total_Price_Net__c, Cost_Center__c'; soqlQuery += ' FROM Order_ManPro__c '; soqlQuery += ' WHERE Account_order__c = \'' + currentAccount.Id + '\''; soqlQuery += ' AND Cost_Centre_Main_Division__c = \'PRODUCT SUPPORT\''; soqlQuery += ' ORDER BY ' + ProductSupportInvoiceSort; if (ProductSupportInvoiceSortDesc) soqlQuery += ' DESC'; for (Order_ManPro__c ProductSupportInvoice : Database.query(soqlQuery)) { InvoiceWrapper wrapper = new InvoiceWrapper(); wrapper.InvoiceId = ProductSupportInvoice.Id; wrapper.orderNumber = ProductSupportInvoice.Name; wrapper.InvoiceDate = ProductSupportInvoice.Invoice_Date__c; wrapper.OrderType = ProductSupportInvoice.Order_Type__c; wrapper.ModelDescription = ProductSupportInvoice.Model_Description__c; wrapper.InvoiceType = ProductSupportInvoice.Invoice_Type__c; wrapper.OrderTaking = ProductSupportInvoice.Order_Taking__r.name; wrapper.ordertakingid = ProductSupportInvoice.Order_Taking__r.id; wrapper.TotalSellVAT = ProductSupportInvoice.Total_Price_Net__c; wrapper.CostCenter = ProductSupportInvoice.Cost_Center__c; wrapper.CostCenterDivision = ProductSupportInvoice.Cost_Center_Division__c; ProductSupportInvoiceList.add(wrapper); } } private void getSamsungInvoiceList() { SamsungInvoiceList = new List<InvoiceWrapper>(); String soqlQuery = 'SELECT Id, Name, Cost_Centre_Main_Division__c, Account_order__c, Cost_Center_Division__c, Invoice_Date__c, Order_Type__c, Model_Description__c, Invoice_Type__c, Order_Taking__r.name, Total_Price_Net__c, Cost_Center__c'; soqlQuery += ' FROM Order_ManPro__c '; soqlQuery += ' WHERE Account_order__c = \'' + currentAccount.Id + '\''; soqlQuery += ' AND Cost_Centre_Main_Division__c = \'SAMSUNG\''; soqlQuery += ' ORDER BY ' + SamsungInvoiceSort; if (SamsungInvoiceSortDesc) soqlQuery += ' DESC'; for (Order_ManPro__c SamsungInvoice : Database.query(soqlQuery)) { InvoiceWrapper wrapper = new InvoiceWrapper(); wrapper.InvoiceId = SamsungInvoice .Id; wrapper.orderNumber = SamsungInvoice .Name; wrapper.InvoiceDate = SamsungInvoice .Invoice_Date__c; wrapper.OrderType = SamsungInvoice .Order_Type__c; wrapper.ModelDescription = SamsungInvoice .Model_Description__c; wrapper.InvoiceType = SamsungInvoice.Invoice_Type__c; wrapper.OrderTaking = SamsungInvoice.Order_Taking__r.name; wrapper.ordertakingid = SamsungInvoice.Order_Taking__r.id; wrapper.TotalSellVAT = SamsungInvoice.Total_Price_Net__c; wrapper.CostCenter = SamsungInvoice.Cost_Center__c; wrapper.CostCenterDivision = SamsungInvoice.Cost_Center_Division__c; SamsungInvoiceList.add(wrapper); } } private void getOtherInvoiceList() { OtherInvoiceList = new List<InvoiceWrapper>(); String soqlQuery = 'SELECT Id, Name, Cost_Centre_Main_Division__c, Account_order__c, Cost_Center_Division__c, Invoice_Date__c, Order_Type__c, Model_Description__c, Invoice_Type__c, Order_Taking__r.name, Total_Price_Net__c, Cost_Center__c'; soqlQuery += ' FROM Order_ManPro__c '; soqlQuery += ' WHERE Account_order__c = \'' + currentAccount.Id + '\''; soqlQuery += ' AND Cost_Centre_Main_Division__c = \'OTHERS MISC - INTERNAL\''; soqlQuery += ' ORDER BY ' + OtherInvoiceSort; if (OtherInvoiceSortDesc) soqlQuery += ' DESC'; for (Order_ManPro__c OtherInvoice : Database.query(soqlQuery)) { InvoiceWrapper wrapper = new InvoiceWrapper(); wrapper.InvoiceId = OtherInvoice.Id; wrapper.orderNumber = OtherInvoice.Name; wrapper.InvoiceDate = OtherInvoice.Invoice_Date__c; wrapper.OrderType = OtherInvoice.Order_Type__c; wrapper.ModelDescription = OtherInvoice.Model_Description__c; wrapper.InvoiceType = OtherInvoice.Invoice_Type__c; wrapper.OrderTaking = OtherInvoice.Order_Taking__r.name; wrapper.ordertakingid = OtherInvoice.Order_Taking__r.id; wrapper.TotalSellVAT = OtherInvoice.Total_Price_Net__c; wrapper.CostCenter = OtherInvoice.Cost_Center__c; wrapper.CostCenterDivision = OtherInvoice.Cost_Center_Division__c; OtherInvoiceList.add(wrapper); } } public pageReference NewInvoice() { PageReference pageRef = new PageReference('/a0J/e?CF00Nb0000005YEDS_lkid=' + currentAccount.Id + '&CF00Nb0000005YEDS=' + currentAccount.Name); pageRef.setRedirect(true); return pageRef; } }
test class
@isTest (SeeAllData=true) private class TESTAccountInvoiceTabExtension { static testmethod void AccountInvoiceTabExtension_Test (){ test.StartTest(); Account acc = new Account(Name ='icrm testing acc'); insert acc; Order_ManPro__c constInvoice = new Order_ManPro__c ( Name='1234', Account_order__c= acc.Id, Cost_Centre_Main_Division__c ='CONSTRUCTION ALL', Cost_Center_ManPRO__c = 'a0e8E000001OZuM', Cost_Center_Division__c = 'CONSTRUCTION ALL',Cost_Centre_Description__c = 'Machine Rental (Const)',Cost_Center__c = 'CMM', CurrencyIsoCode = 'USD', Invoice_Date__c = System.today().addDays(30),Order_Type__c = 'rergg', Model_Description__c = 'desc', Order_Taking__c = '005b00000010h3o', External_Order_ID__c = '9876000'); insert constInvoice; Order_ManPro__c DeltaInvoice = new Order_ManPro__c ( Name='234' , Account_order__c= acc.Id, Cost_Centre_Main_Division__c ='DELTA', Cost_Center_ManPRO__c = 'a0e8E000001OZuM', Cost_Center_Division__c = 'AGRICULTURE',Cost_Centre_Description__c = 'John Deer',Cost_Center__c = 'NMB', CurrencyIsoCode = 'USD', Invoice_Date__c = System.today().addDays(30),Order_Type__c = 'rergg', Model_Description__c = 'desc', Order_Taking__c = '005b00000010h3o', External_Order_ID__c = '98760900'); insert DeltaInvoice; Order_ManPro__c EnginePowerGenerationInvoice = new Order_ManPro__c (Name='234' , Account_order__c= acc.Id, Cost_Centre_Main_Division__c ='ENGINE POWER GENERATION', Cost_Center_ManPRO__c = 'a0e8E000001OZvj', Cost_Center_Division__c = 'MARINE',Cost_Centre_Description__c = 'Marine Engines',Cost_Center__c = 'CEC', CurrencyIsoCode = 'USD', Invoice_Date__c = System.today().addDays(30),Order_Type__c = 'rergg', Model_Description__c = 'desc', Order_Taking__c = '005b00000010h3o', External_Order_ID__c = '1'); insert EnginePowerGenerationInvoice; Order_ManPro__c MiningInvoice = new Order_ManPro__c (Name='234' , Account_order__c= acc.Id, Cost_Centre_Main_Division__c ='MINING', Cost_Center_ManPRO__c = 'a0e8E000001OZw8', Cost_Center_Division__c = 'MINING',Cost_Centre_Description__c = 'Rental machines Mining',Cost_Center__c = 'CMI', CurrencyIsoCode = 'USD', Invoice_Date__c = System.today().addDays(30),Order_Type__c = 'rergg', Model_Description__c = 'desc', Order_Taking__c = '005b00000010h3o', External_Order_ID__c = '9'); insert MiningInvoice; Order_ManPro__c ProductSupportInvoice = new Order_ManPro__c (Name='234' , Account_order__c= acc.Id, Cost_Centre_Main_Division__c ='PRODUCT SUPPORT', Cost_Center_ManPRO__c = 'a0e8E000001OZvV', Cost_Center_Division__c = 'PRODUCT SUPPORT',Cost_Centre_Description__c = 'Service Admin Mining',Cost_Center__c = 'CS2', CurrencyIsoCode = 'USD', Invoice_Date__c = System.today().addDays(30),Order_Type__c = 'rergg', Model_Description__c = 'desc', Order_Taking__c = '005b00000010h3o', External_Order_ID__c = '2'); insert ProductSupportInvoice; Order_ManPro__c SamsungInvoice = new Order_ManPro__c (Name='234' , Account_order__c= acc.Id, Cost_Centre_Main_Division__c ='SAMSUNG', Cost_Center_ManPRO__c = 'a0e8E000001OZxo', Cost_Center_Division__c = 'SAMSUNG',Cost_Centre_Description__c = 'Audio and Video Products',Cost_Center__c = 'TEC', CurrencyIsoCode = 'USD', Invoice_Date__c = System.today().addDays(30),Order_Type__c = 'rergg', Model_Description__c = 'desc', Order_Taking__c = '005b00000010h3o', External_Order_ID__c = '4'); insert SamsungInvoice; Order_ManPro__c OtherInvoice = new Order_ManPro__c (Name='234' , Account_order__c= acc.Id, Cost_Centre_Main_Division__c ='OTHERS MISC - INTERNAL', Cost_Center_ManPRO__c = 'a0e8E000001OZuZ', Cost_Center_Division__c = 'OTHERS MISC - INTERNAL',Cost_Centre_Description__c = 'Internal Sales Reps',Cost_Center__c = 'ZSR', CurrencyIsoCode = 'USD', Invoice_Date__c = System.today().addDays(30),Order_Type__c = 'rergg', Model_Description__c = 'desc', Order_Taking__c = '005b00000010h3o', External_Order_ID__c = '6'); insert OtherInvoice; PageReference pref = Page.Invoice_Tabs; pref.getParameters().put('id', acc.id); Test.setCurrentPage(pref); ApexPages.StandardController sc = new ApexPages.StandardController(acc); AccountInvoiceTabExtension mc = new AccountInvoiceTabExtension(sc); PageReference result = AccountInvoiceTabExtension.autoRun(); System.assertNotEquals(null, result); test.stopTest(); } }
All Answers
It is working now.
But I have another issue with my apex class for pagination, it is only covered by 19%
really appreciated