+ Start a Discussion
BridgetreeBridgetree 

Test class for this class

Can anyone help me out in writing the test class for the following class??

I am new to this!!!

 

public class MyPagingController {
    private List<BC_Products__c> accounts;
    private List<BC_Products__c> pageAccounts;
    private Integer pageNumber;
    private Integer pageSize;
    private Integer totalPageNumber;
    public boolean testBool {get; set;}
    public string chkText {get; set;}
    public List<BC_Products__c> PDTS {get; set;}
    public BC_Products__c JEPS;
    public string selectedOptions {get;set;}
    BC_Products__c products;
   
    public Integer getPageNumber()
    {
        return pageNumber;
    }

    public BC_Products__c getProducts()
    {
        if(products == null) products = new BC_Products__c();
        return products;
    }

    public List<BC_Products__c> getAccounts()
    {
        return pageAccounts;
    }

    public Integer getPageSize()
    {
        return pageSize;
    }

    public Boolean getPreviousButtonEnabled()
    {
        return !(pageNumber > 1);
    }

    public Boolean getNextButtonDisabled()
    {
        if (accounts == null)
            return true;
        else
            return ((pageNumber * pageSize) >= accounts.size());
    }

    public Integer getTotalPageNumber()
    {
        if (totalPageNumber == 0 && accounts !=null)
        {
            totalPageNumber = accounts.size() / pageSize;
            Integer mod = accounts.size() - (totalPageNumber * pageSize);   
            if (mod > 0)
                totalPageNumber++;
        }
        return totalPageNumber;

    }

    public MyPagingController()
    {   
        pageNumber = 0;
        totalPageNumber = 0;
        pageSize = 75;
        ViewData();
        JEPS = new BC_Products__c();
        PDTS = new List<BC_Products__c>();
        PDTS.add(new BC_Products__c());
        testBool = false;
    }

    public PageReference ViewData()
    {
        accounts = null;
        totalPageNumber = 0;
        BindData(1);
        return null;
    }

    private void BindData(Integer newPageIndex)
    {
        try
        {
        if (accounts == null)
            accounts = [select b.name,b.Product_Description__c,b.Status__c,b.JEP__c,b.Disconnect_request_Sent_to_Vendor__c,b.Vendor_Bill_Start_Date__c,
            b.Actual_Disconnect_Date__c,b.Date_Entered_Provisioing__c,b.CR_Install_Date__c,b.Customer_Commit_Date__c,b.Vendor_CDD__c,
            b.SUP_Date__c,b.Actual_Install_Date__c,b.Cancel_Request_Recieved__c,b.CR_Disconnect_Date__c,b.Disconnect_Date__c,b.Disconnect_Reason__c,b.Disconnect_Reason_Notes__c from BC_Products__c b where AccountName__c=:System.currentPageReference().getParameters().get('id') order by name];
       
            pageAccounts = new List<BC_Products__c>();
            Transient Integer counter = 0;
            Transient Integer min = 0;
            Transient Integer max = 0;
            if (newPageIndex > pageNumber)
            {
                min = pageNumber * pageSize;
                max = newPageIndex * pageSize;
            }
            else
            {
                max = newPageIndex * pageSize;
                min = max - pageSize;
            }
            for(BC_Products__c a : accounts)
            {  
                counter++;
                if (counter > min && counter <= max)
                    pageAccounts.add(a);
            }
   
            pageNumber = newPageIndex;
            if (pageAccounts == null || pageAccounts.size() <= 0)
                ApexPages.addmessage(new ApexPages.message(ApexPages.severity.INFO,'Data not available for this view.'));
        }catch(Exception ex)
        {
            ApexPages.addmessage(new ApexPages.message(ApexPages.severity.FATAL,ex.getMessage()));
        }
    }

    public PageReference nextBtnClick()
    {
        BindData(pageNumber + 1);
        return null;
    }

    public PageReference previousBtnClick()
    {
        BindData(pageNumber - 1);
        return null;
    }
   
    public PageReference Save()
    {
        update pageAccounts;
        return ApexPages.currentPage();
    }

    public BC_Products__c getJEPS()
    {
       return JEPS;
    }

    public void setJEPS(BC_Products__c Value)
    {
       JEPS = Value;
    }

    public PageReference showSelected()
    {   
       if (JEPS.JEP__c == null || JEPS.JEP__c == '')
       {
          apexPages.addmessage(new ApexPages.message(ApexPages.severity.INFO, 'Please select one or more products.'));
          return null;
       }
       // read the values into an array
       string[] regions = JEPS.JEP__c.split(',',0);
       if (regions != null && regions.size() > 0)
       {
          Boolean addSeperater = false;
          for(String le : regions)
            {
                if(addSeperater)
                  selectedOptions = selectedOptions + ',' + le;
                else
                  {
                   selectedOptions = le;
                   addSeperater = true;
                  }
            }
       }
       return ApexPages.currentPage();
   }
}

 

 

 

 

Thanks in advance!!!!

BridgeTree