0

My code coverage is on 48%. below is my class with testmethod. I use API 27.0.

public with sharing class CommonController {

      public static testmethod void test1()
      {           
            String strGUID1 = ApexPages.CurrentPage().getParameters().put('GUID','00000000');
            String strPage1 = ApexPages.CurrentPage().getParameters().put('page','abcd');
            CommonController objCreateServiceOrder = new CommonController();
            objCreateServiceOrder.option = 'A';
            objCreateServiceOrder.strError = 'NO ERROR';
            objCreateServiceOrder.strGUID = strGUID1;
            objCreateServiceOrder.strPage = strPage1;
            objCreateServiceOrder.ID = 'abcd';
            objCreateServiceOrder.pass();
      }

      public String option {get;set;}   
      public String strError {get; set;}
      public  String strGUID;
      public String strPage;
      public String ID;
      public String preGUID;
      String [] GUID;

    public CommonController () {

        strGUID = System.currentPageReference().getParameters().get('GUID');
        strPage = System.currentPageReference().getParameters().get('page');
        ID = System.currentPageReference().getParameters().get('id');

        if(StrPage != null){
        if(strPage.contains('CreateCustomer')){

         List<CommercientSF3__CommercientURL__c> lstUserInfo =          CommercientSF3__Com![enter image description here][2]mercientURL__c.getAll().values();
      String URL = lstUserInfo[0].CommercientSF3__URL__c;


      if(URL.contains('@')){
      String [] SplittedURLs = URL.split(',');
      String [] counts = new String[SplittedURLs.size()];

      for(integer i = 0 ; i < SplittedURLs.size() ; i++){


          String [] Pref = SplittedURLs[i].split('@');
          counts[i] = Pref[0];
          }
          this.prefixOptions = new SelectOption[]{};


        for (String c: counts) {
            this.prefixOptions.add(new SelectOption(c,c));
          }
      }

      }
      else{

        GUID  = strGUID.split(','); 
            String[] countries = new String[GUID.size()];

        for (integer i = 0 ; i <  GUID.size() ; i++ )
        {
            String [] Prefixes =  GUID[i].split('@');
            countries [i] = Prefixes[0];
        }

        this.prefixOptions = new SelectOption[]{};


        for (String c: countries) {
            this.prefixOptions.add(new SelectOption(c,c));
        }
        }
        }
    }

    public PageReference pass()
    {

        if(strPage != 'CreateCustomer'){
        for (integer i = 0 ; i <  GUID.size() ; i++   )
        {
            if (GUID[i].contains(option))
            {

                 if (GUID[i].contains('@'))
                 {
                            String [] Prefixess =  GUID[i].split('@');

                            if(Prefixess[0] == option){
                            preGUID = Prefixess[1];
                            break;
                            }
                 }
                 else
                 {
                            preGUID = GUID[i];

                            break;
                 }

            }
            }
        }

        PageReference pg;

        if (strPage.contains('ViewQuote'))
        {
             pg = new PageReference('/apex/ViewQuote?val=' + option+'&GUID='+preGUID+'&id='+ID);
        }
        else if (strPage.contains('InstantOrder'))
        {    
           pg = new PageReference('/apex/InstantOrder?val=' + option+'&GUID='+preGUID+'&id='+ID);
        }
        else if (strPage.contains('NewOrderNewQuote'))
        {
            pg = new PageReference('/apex/NewOrderNewQuote?val=' + option+'&GUID='+preGUID+'&id='+ID);
        }
        else if (strPage.contains('ViewOrderHistory'))
        {
            pg = new PageReference('/apex/ViewOrderHistory?val=' + option+'&GUID='+preGUID+'&id='+ID);
        }
        else if(strPage.contains('CreateCustomer')){

        if(option != null || option != ''){
        pg = new PageReference('/apex/SyncAccount?val=' + option + '&id=' + ID);
        }
        }
        pg.setRedirect(true);
        return pg;
    }


    public SelectOption[] prefixOptions { //this is where we're going to pull the list
        public get;
        private set;
    }
}

enter image description here

2
  • I am also getting red lines on on PageReference statements. For app pages i.e ViewQuote , InstantOrder , NewOrderNewQuote etc.
    – Mehul
    Commented Sep 26, 2014 at 5:47
  • 2
    In your test method, you set the 'page' parameter to 'abcd'. Try setting that to 'CreateCustomer' or one of the other values you check for. Also use the Test.SetCurrentPage(); function to set the page reference in your test. See this post for some more pointers on testing controllers: salesforce.stackexchange.com/questions/104/… Commented Sep 26, 2014 at 6:41

0

You must log in to answer this question.

Browse other questions tagged .