I am trying to test this (uploaded to pastebin due length) wrapper class. I was trying to follow two previous SFSE's, however I am getting errors. See code below (errors in comments):
@isTest
public class testAddBasketGasQuoteFromMonitor{
static testMethod void validateTestMyClass() {
electricity_meter__c testGasMeter = testUtil.initGasMeter();
String meterNameInner = String.valueOf( testGasMeter.get('Name') );
String meterAQ = String.valueOf('100');
String meterID = String.valueOf('123123123123');
AddBasketGasQuoteFromMonitor.WrapperClassEx testWrapperPack = new AddBasketGasQuoteFromMonitor.WrapperClassEx(testGasMeter,meterNameInner,meterAQ,meterID);
// Error: Constructor not defined: [AddBasketGasQuoteFromMonitor].<Constructor>()
//AddBasketGasQuoteFromMonitor controller = new AddBasketGasQuoteFromMonitor();
// Error: Variable does not exist: getwrapperObj
//for (AddBasketGasQuoteFromMonitor.WrapperClassEx wrap : testWrapperPack.getwrapperObj){}
}
Any ideas on what I am doing wrong?
EDIT: Wrapper class code below
public with sharing class AddBasketGasQuoteFromMonitor{
@TestVisible Public List<WrapperClassEx> WrapperList{get;set;}
public AddBasketGasQuoteFromMonitor(ApexPages.StandardSetController controller) {
mycon = controller;
Selectedmeters = mycon.getSelected();
}
public AddBasketGasQuoteFromMonitor(ApexPages.StandardController controller) {
mycon2 = controller;
}
public List<sobject> Selectedmeters {get; set;}
ApexPages.StandardSetController mycon;
ApexPages.StandardController mycon2;
@TestVisible Public List<WrapperClassEx> getwrapperObj(){
id lineId = mycon2.getId();
//List<Account> accList = [Select id,name from account limit 5];
//List<Line_del__c> SelectedLines = [select Linked_Monitor_Line__r.id from Line_del__c where id in: SelectedMeters];
List<electricity_meter__c> MeterList = [Select id,name,AQ__c,meter_details__c from electricity_meter__c where (Linked_Monitor_Line__c =: lineId)];
WrapperList = New List<WrapperClassEx>();
for(electricity_meter__c met: MeterList){
String meterNameInner = String.valueOf( met.get('Name') );
String meterAQ = String.valueOf( met.get('AQ__c') );
String meterID = String.valueOf( met.get('meter_details__c') );
WrapperList.add(New WrapperClassEx(met,meterNameInner,meterAQ,meterID ));
}
return WrapperList;
}
Public String options{get;set;}
// Get the list of suppliers
public List<SelectOption> getSuppliers(){
List<SelectOption> options = new List<SelectOption>();
Schema.DescribeFieldResult fieldResult =
Electricity_Meter__c.Current_Supplier__c.getDescribe();
List<Schema.PicklistEntry> ple = fieldResult.getPicklistValues();
for( Schema.PicklistEntry f : ple)
{
options.add(new SelectOption(f.getLabel(), f.getValue()));
}
return options;
}
@TestVisible Public Class WrapperClassEx{
Public Account accObj {get;set;}
Public Sobject elecObj {get;set;}
Public Boolean checkBox{get;set;}
Public string meterName{get;set;}
Public double dayrate {get;set;}
Public string meterID {get;set;}
Public double standing{get;set;}
Public string supplier{get;set;}
Public string AQ {get;set;}
Public string AQQ {get;set;}
Public WrapperClassEx(sobject accRec, string meterNameMethodVar, string meterAQ, string meterIDs ){
elecObj = accRec;
meterName = meterNameMethodVar;
AQ=meterAQ;
meterID=meterIDs;
}
}
public List<Quote__C> newQuotes {get; set;}
public void save(){
newQuotes = new list<Quote__c>();
for (WrapperClassEx wrap : WrapperList){
newQuotes.add(new Quote__c(
consumption__c=decimal.valueOf(wrap.AQQ),
Day_rate__c=decimal.valueOf(wrap.dayrate),
Standing_Charge__c=decimal.valueOf(wrap.standing),
Supplier__c=wrap.supplier,
All_Products__c=wrap.elecObj.id
));
}
try {
insert newQuotes;
} catch (DmlException ex){
ApexPages.addMessages(ex);
}
}
}
testGasMeter
,which is electricity_meter__c
. Can you confirm thattestGasMeter, meterNameInner, meterAQ, meterID
are Strings.