You need to sign in to do that
Don't have an account?
Pavel Bandarenka
I am a newbie do not help me with the StandardSetController test.
Controller:public class AppointmentsViewController {
public List<Doctor__c> doctorList {get;set;}
public List<SelectOption> doctorSelectOptionList{get;set;}
public List<Appointment__c> apointmentList{get;set;}
public String doctorId {get;set;}
public List<Patient__c> patientList{get;set;}
public List<SelectOption> patientSelectOptionList{get;set;}
public Integer noOfRecords{get; set;}
public Integer size{get;set;}
public AppointmentsViewController() {
doctorList = [
SELECT Id, Name, Working_Hours_Start__c, Working_Hours_End__c
FROM Doctor__c
ORDER BY Name ASC
];
patientList = [
SELECT Id, Name
FROM Patient__c
];
patientSelectOptionList = new List<SelectOption>();
for(Patient__c item :patientList)
{
patientSelectOptionList.add(new SelectOption(item.Id, item.Name));
}
doctorId = doctorList.isEmpty() == FALSE ? doctorList[0].Id : NULL;
doctorSelectOptionList = new List<SelectOption>();
for(Doctor__c item :doctorList) {
doctorSelectOptionList.add(new SelectOption(item.Id, item.Name));
}
getAppointments();
}
public void getAppointments () {
apointmentList = [
SELECT Id, Name, Doctor__c, Patient__c, Appointment_Date__c, Duration_in_minutes__c
FROM Appointment__c
WHERE Doctor__r.Id = :doctorId
];
}
public List<Appointment__c> Appointment { get{
return (List<Appointment__c>)setCon.getRecords();
} set; }
public ApexPages.StandardSetController setCon {
get{
if(setCon == null){
size = 20;
List<Appointment__c> Appointment = [
SELECT Id, Name, Doctor__c, Patient__c, Appointment_Date__c, Duration_in_minutes__c
FROM Appointment__c];
setCon = new ApexPages.StandardSetController(Appointment);
setCon.setPageSize(size);
noOfRecords = setCon.getResultSize();
}
return setCon;
}set;
}
}
Test:
@isTest
private class AppointmentsViewControllerTest {
@isTest static void AppointmentsViewControllerTest1() {
Doctor__c doctor = new Doctor__c(
);
insert doctor;
AppointmentsViewController controller = new AppointmentsViewController();
Appointment__c Appointment = new Appointment__c(
);
insert Appointment;
ApexPages.standardSetController sc = new ApexPages.standardSetController(doctor
// ApexPages.StandardSetController standardSetController = new ApexPages.StandardSetController(doctor);
}
}
public List<Doctor__c> doctorList {get;set;}
public List<SelectOption> doctorSelectOptionList{get;set;}
public List<Appointment__c> apointmentList{get;set;}
public String doctorId {get;set;}
public List<Patient__c> patientList{get;set;}
public List<SelectOption> patientSelectOptionList{get;set;}
public Integer noOfRecords{get; set;}
public Integer size{get;set;}
public AppointmentsViewController() {
doctorList = [
SELECT Id, Name, Working_Hours_Start__c, Working_Hours_End__c
FROM Doctor__c
ORDER BY Name ASC
];
patientList = [
SELECT Id, Name
FROM Patient__c
];
patientSelectOptionList = new List<SelectOption>();
for(Patient__c item :patientList)
{
patientSelectOptionList.add(new SelectOption(item.Id, item.Name));
}
doctorId = doctorList.isEmpty() == FALSE ? doctorList[0].Id : NULL;
doctorSelectOptionList = new List<SelectOption>();
for(Doctor__c item :doctorList) {
doctorSelectOptionList.add(new SelectOption(item.Id, item.Name));
}
getAppointments();
}
public void getAppointments () {
apointmentList = [
SELECT Id, Name, Doctor__c, Patient__c, Appointment_Date__c, Duration_in_minutes__c
FROM Appointment__c
WHERE Doctor__r.Id = :doctorId
];
}
public List<Appointment__c> Appointment { get{
return (List<Appointment__c>)setCon.getRecords();
} set; }
public ApexPages.StandardSetController setCon {
get{
if(setCon == null){
size = 20;
List<Appointment__c> Appointment = [
SELECT Id, Name, Doctor__c, Patient__c, Appointment_Date__c, Duration_in_minutes__c
FROM Appointment__c];
setCon = new ApexPages.StandardSetController(Appointment);
setCon.setPageSize(size);
noOfRecords = setCon.getResultSize();
}
return setCon;
}set;
}
}
Test:
@isTest
private class AppointmentsViewControllerTest {
@isTest static void AppointmentsViewControllerTest1() {
Doctor__c doctor = new Doctor__c(
);
insert doctor;
AppointmentsViewController controller = new AppointmentsViewController();
Appointment__c Appointment = new Appointment__c(
);
insert Appointment;
ApexPages.standardSetController sc = new ApexPages.standardSetController(doctor
// ApexPages.StandardSetController standardSetController = new ApexPages.StandardSetController(doctor);
}
}
Sorry for the late reply.
Please use the belpw updated code:
t.setCon.getRecords(); ==> needs to be added
Thanks,
Maharajan.C
All Answers
Please try the below code :
Thanks,
Maharajan.C
Everything worked, thank you very much, but the test coverage code is 63% and needs at least 75%. Can you tell me what needs to be done?
Sorry for the late reply.
Please use the belpw updated code:
t.setCon.getRecords(); ==> needs to be added
Thanks,
Maharajan.C