+ Start a Discussion
LuckyLucky 

Test Class Help!!!

Hi I created a visualforce page for selecting certain recordtypes to over write standard record type selecting page. For that controller I got stuck with writing test class. Please help anybody for this.
public with sharing class SelectSORRecordTypeCntrl{
Public List<RecordType> RecList{get; set;}
public Id recordTypes1{get;set;}
public string AcName{get; set;}
public string AcId{get; set;}

    public SelectSORRecordTypeCntrl() {
RecList=[SELECT id,Name, DeveloperName FROM RecordType 
                        WHERE DeveloperName in('Address_Changes_MMI','Billing_Terms_ETS','Billing_Terms_MMI','Billing_Terms_WMI8Credits_ETS','Credits_MMI','Credits_WMI','Customer_Service_General_ETS','Customer_Service_General_MMI','Customer_Service_General_WMI','Insurance_Forms_ETS','Insurance_Forms_MMI','Insurance_Forms_WMI','Lein_Release_Request_ETS','Lein_Release_Request_MMI','PO_Request_MMI','Pickup_Request_MMI','Tax_Exemption_MMI')];
AcName = ApexPages.currentPage().getParameters().get('Name');
AcId = ApexPages.currentPage().getParameters().get('id');
}
String[] ps= new String[]{};
 public String[] getrecordTypes() {
    return ps;
  }

  public void setrecordTypes(String[] ps) {
    this.ps = ps;
  }
  

  public List<SelectOption> getItems() {
    List<SelectOption> op = new List<SelectOption>();
    for(RecordType p : [SELECT id,Name, DeveloperName FROM RecordType 
                        WHERE DeveloperName in('Address_Changes_MMI','Billing_Terms_ETS','Billing_Terms_MMI','Billing_Terms_WMI8Credits_ETS','Credits_MMI','Credits_WMI','Customer_Service_General_ETS','Customer_Service_General_MMI','Customer_Service_General_WMI','Insurance_Forms_ETS','Insurance_Forms_MMI','Insurance_Forms_WMI','Lein_Release_Request_ETS','Lein_Release_Request_MMI','PO_Request_MMI','Pickup_Request_MMI','Tax_Exemption_MMI')])
    op.add(new SelectOption(p.Id, p.Name));
    return op;
    }
  public Pagereference navigate()
  {
   Pagereference  p = new Pagereference('/a0d/e?retURL=%2Fa0d%2Fo&ent=01I80000000lLBL&RecordType='+recordTypes1+'&CF00N80000004mJY7='+AcName);
   P.setRedirect(true);
   return p;
  }
public Pagereference NavBack()
  {
   Pagereference  b = new Pagereference('/apex/AccountDashboard?id='+AcId);
   b.setRedirect(true);
   return b;
  }

}
Thanks in Advance
 
Best Answer chosen by Lucky
AshlekhAshlekh
Hi,

Here is code which cover code.
 
@isTest
private class SelectSORRecordTypeCntrlTest{

static testMethod void Test1()
{
	Account a = new Account(name = 'test');
	insert a;
	Test.setCurrentPageReference(new PageReference('Page.YourPAGENAME')); 
    System.currentPageReference().getParameters().put('id', a.id);
	System.currentPageReference().getParameters().put('name', a.name);
	Test.StartTest();
	SelectSORRecordTypeCntrl cont = new SelectSORRecordTypeCntrl();
	cont.getItems();
	cont.navigate();
	cont.NavBack();
	System.assertNotEquals(cont.getrecordTypes(),null);//Comment this line if you get error
	cont.setrecordTypes(null);
	System.assertEquals(cont.getrecordTypes(),null);
	Test.StopTest();	
}


}

-Thanks
Ashlekh Gera