-3

please provide the test class for the below custom controller. my code coverage is 58% with this test code:

@isTest(seealldata=true)
public with sharing class TestOpportunityController1 {

   static testmethod void MyTest(){

        //List<Account> acclist = new List<Account>();
        Account acc = new Account();
        acc.name = 'saif';
        acc.Billing_Entity_Name__c = 'india';
        acc.RecordTypeId = Schema.SObjectType.Account.getRecordTypeInfosByName().get('Internal').getRecordTypeId();
         insert acc;


        Id oppRecordTypeId = [Select Id From RecordType Where SobjectType = 'Opportunity__c' and DeveloperName = 'Platform_Solution_Opportunity'].Id;

        List<Opportunity__c> Opplist = new List<Opportunity__c>();
        Opportunity__c opp1= new Opportunity__c();
        opp1.name= 'test';
        opp1.Opportunity_Type__c = 'New Client';
        opp1.Currency__c = 'PHP';
        opp1.Client_Type__c = 'Direct';
        opp1.Closing_Date__c = date.today();
        opp1.Ctrlshift_Market_Name__c = 'Thailand';
        opp1.Bill_To_Account__c = 'Advertiser';
        opp1.Payment_Terms__c = 'Prepay';
        opp1.Business_Type__c = 'Platform Solution';
        opp1.Opportunity_Source__c = 'LinkedIn';
        opp1.Client_Geo_Market__c = 'Afghanistan';
        opp1.Currency__c = 'USD';
        //opp1.Advertiser_Name__c = acc.id;
        opp1.CtrlShift_Billing_Entity__c = acc.id;
        opp1.Campaign_Start_Date1__c = date.today()+20;
        opp1.Campaign_End_Date1__c = date.today();
        opp1.Budget1__c = 5678;
        opp1.RecordTypeId = oppRecordTypeId;
        opp1.Proposal_Due_Date__c = date.today();
        insert opp1;

        Financial_Rates__c fr = new Financial_Rates__c();
        fr.Currency_Rate__c = 200;
        fr.Currency__c = opp1.Currency__c;
        fr.Active__c = true;
        fr.End_Date__c =null;
        insert fr;



        List<Platform_Solution_Detail__c> pdList = new List<Platform_Solution_Detail__c>();
        Platform_Solution_Detail__c pls1=new Platform_Solution_Detail__c();
        pls1.Opportunity__c=opp1.id;
        pls1.Unit_Price__c =10;
        pls1.Quantity__c=10;
        pdList.add(pls1);

        Platform_Solution_Detail__c pls2=new Platform_Solution_Detail__c();
        pls2.Opportunity__c=opp1.id;
        pls2.Unit_Price__c =10;
        pls2.Quantity__c=10;
        pdList.add(pls2);

        Platform_Solution_Detail__c pls3=new Platform_Solution_Detail__c();
        pls3.Opportunity__c=opp1.id;
        pls3.Unit_Price__c =10;
        pls3.Quantity__c=10;
        pdList.add(pls3);
        insert pdList;

        Test.setCurrentPageReference(new PageReference('Page.OpportunityPage')); 
        System.currentPageReference().getParameters().put('id', 'index1');

        pageReference ref1=new PageReference('OpportunityPage');
        ref1.getParameters().put('index2','1');

        List<Publisher_Solution__c> psList = new List<Publisher_Solution__c>();
        Publisher_Solution__c ps = new Publisher_Solution__c();
        ps.End_Date__c = system.today();
        ps.Budget__c = null;
        ps.Opportunity__c = opp1.id;
        ps.Start_Date__c = system.today();
        psList.add(ps);

        Publisher_Solution__c ps1 = new Publisher_Solution__c();
        ps1.End_Date__c =system.today();
        ps1.Opportunity__c = opp1.id;
        ps1.Start_Date__c = system.today();
        psList.add(ps1);

        Publisher_Solution__c ps2 = new Publisher_Solution__c();
        ps2.End_Date__c = system.today();
        ps2.Opportunity__c = opp1.id;
        ps2.Start_Date__c = system.today();
        psList.add(ps2);
        insert psList;

        List<Marketer_Solution__c> msList1 = new List<Marketer_Solution__c>();

        Marketer_Solution__c ms = new Marketer_Solution__c();
        ms.End_Date__c = system.today();
        ms.Opportunity__c = opp1.id;
        ms.Start_Date__c = system.today();
        msList1.add(ms);

        Marketer_Solution__c ms1 = new Marketer_Solution__c();
        ms1.End_Date__c = system.today();
        ms1.Opportunity__c = opp1.id;
        ms1.Start_Date__c = system.today();
        msList1.add(ms1);

        Marketer_Solution__c ms2 = new Marketer_Solution__c();
        ms2.End_Date__c = system.today();
        ms2.Opportunity__c = opp1.id;
        ms2.Start_Date__c = system.today();
        msList1.add(ms2);
        insert msList1;

        ApexPages.standardController controller = new ApexPages.standardController(Opp1);
        OpportunityController oppcntrollr = new OpportunityController(controller);
        oppcntrollr.decrementCounter();
        oppcntrollr.totalprice();
        oppcntrollr.cancel();
        oppcntrollr.checkDate();
        oppcntrollr.checkDate1();
        oppcntrollr.checkBudget();
        oppcntrollr.checkBudget1();
        ps2.Budget__c = 0;
        update ps2; 

        oppcntrollr.checkLost();
        oppcntrollr.checkLost1();
        oppcntrollr.saveOpp();
        oppcntrollr.addRowForPlatform();

        opp1.Business_Type__c = 'combined';
        opp1.Business_Dev_Marketer_Soln_BDMS__c = null;
        update opp1;
        oppcntrollr.saveOpp();

        opp1.Bill_To_Account__c = 'Agency';
        opp1.Agency_Name__c = null;
        update opp1;
        oppcntrollr.saveOpp();

        opp1.Opportunity_Source__c = null;
        update opp1;
        oppcntrollr.saveOpp();

        opp1.Client_Geo_Market__c = null;
        update opp1;
        oppcntrollr.saveOpp(); 

        opp1.CtrlShift_Billing_Entity__c = null;
        update opp1;
        oppcntrollr.saveOpp();

        opp1.Payment_Terms__c = null;
        update opp1;
        oppcntrollr.saveOpp();

        opp1.Business_Type__c = null;
        update opp1;
        oppcntrollr.saveOpp();

        opp1.Ctrlshift_Market_Name__c = null;
        update opp1;
        oppcntrollr.saveOpp();

        opp1.Bill_To_Account__c = null;
        update opp1;
        oppcntrollr.saveOpp();

        opp1.Client_Type__c = null;
        update opp1;
        oppcntrollr.saveOpp();

        opp1.Opportunity_Type__c = null;
        update opp1;  
        oppcntrollr.saveOpp();

        opp1.Name = null;
        update opp1;
        oppcntrollr.saveOpp();

    }
}

Controller:

public with sharing class OpportunityController {

    public Opportunity__c opp;
    public list<Publisher_Solution__c> publisherList {get;set;}
    public list<Publisher_Solution__c> publisherAddList {get;set;}
    public list<Marketer_Solution__c> marketerList {get;set;}
    public list<Marketer_Solution__c> marketerAddList {get;set;}
    public list<Platform_Solution_Detail__c> platformList {get;set;}
    public list<Platform_Solution_Detail__c> platformAddList {get;set;}
    list<Financial_Rates__c> Financiallist = new list<Financial_Rates__c>();
    public Integer rowNum{get;set;}
    public Integer rowNum1{get;set;}
    public Integer rowNum2{get;set;}
    public string u{get;set;}
    public boolean msps{get; set; }
    public boolean platform {get; set;}
    public boolean er{get; set;}
    public boolean err{get; set;}
    public boolean lost {get; set;}

    Public OpportunityController(Apexpages.standardcontroller stdController){
        Financiallist = new list<Financial_Rates__c>();
        this.opp = (Opportunity__c)stdController.getRecord();
        System.debug('--opp---'+(Opportunity__c)stdController.getRecord());
        System.debug('--opp---'+opp.Currency__c);
        publisherAddList = new List<Publisher_Solution__c>();
        system.debug('--publisherAddList--'+publisherAddList);
        //publisherAddList.add(new Publisher_Solution__c());
        marketerAddList = new List<Marketer_Solution__c>();
        //marketerAddList.add(new Marketer_Solution__c());
        platformAddList = new list<Platform_Solution_Detail__c>();
        platformAddList.add(new Platform_Solution_Detail__c());
        u = Userinfo.getName();
        system.debug('--u--'+u);
        addRow();
        addRowForMarketer();



        msps=false;
        platform=false;
        er=false;
        err=false;
        lost = false;
        string id=ApexPages.currentPage().getParameters().get('RecordType');
        system.debug('id!@@@'+id);
        List<RecordType> msid=[SELECT Id FROM RecordType WHERE SObjectType = 'Opportunity__c' and DeveloperName = 'MS_PS_Opportunity'];
        List<RecordType> plid=[SELECT Id FROM RecordType WHERE SObjectType = 'Opportunity__c' and DeveloperName = 'Platform_Solution_Opportunity'];
        if(id==msid[0].id){
            msps=true;
        }
        else if(id==plid[0].id){
            platform=true;
        }
        system.debug('msps'+msps+platform);
    } 

    public void decrementCounter(){     
        Date dd = system.today();   
        Financiallist =[select id,name,active__c,Start_Date__c,Currency_Rate__c from Financial_Rates__c where currency__c=:opp.currency__c AND  active__c = true AND (Start_Date__c>=:dd OR End_Date__c >=:dd OR End_Date__c = null)];
        opp.Exchange_Rate_LookUp__c=null;
        opp.Currency_Rate__c= null;
        system.debug('--Financiallist--'+Financiallist);
        if(Financiallist!= null && Financiallist .size()>0){
            for(Financial_Rates__c fr:Financiallist ){     
                opp.Exchange_Rate_LookUp__c= fr.id;
                //opp.Currency_Rate__c= string.valueof(fr.Currency_Rate__c);
                opp.Currency_Rate__c= fr.Currency_Rate__c;
                system.debug('--opp1---'+opp.Exchange_Rate_LookUp__c);
            }

            System.debug('--opp---'+opp.Currency__c);
        }


    }

    public void addRow()
    {

        publisherAddList.add(new Publisher_Solution__c());        

        system.debug('--publisherAddListAdd--'+publisherAddList);
    }

    public void addRowForMarketer()
    {
        marketerAddList.add(new Marketer_Solution__c());        
        system.debug('--marketerAddListAdd--'+marketerAddList);
    }

    public void delRow()
    {
        rowNum = Integer.valueOf(apexpages.currentpage().getparameters().get('index'));
        publisherAddList.remove(rowNum);   
        system.debug('--publisherAddListDel--'+publisherAddList);
    } 

    public void delRowForMarketer()
    {
        rowNum1 = Integer.valueOf(apexpages.currentpage().getparameters().get('index1'));
        marketerAddList.remove(rowNum1);   
        system.debug('--marketerAddListDel--'+marketerAddList);
    }  
    public void addRowForPlatform()
    {
        platformAddList.add(new Platform_Solution_Detail__c());        
        system.debug('--platformAddListAdd--'+platformAddList);
    }

    public void delRowForPlatform()
    {
        rowNum2 = Integer.valueOf(apexpages.currentpage().getparameters().get('index2'));
        system.debug(rowNum2);
        platformAddList.remove(rowNum2);   
        system.debug('--platformAddListDel--'+platformAddList);
    } 

    public void totalprice(){
        if(platformAddList != null && platformAddList.size()>0){
            for(Platform_Solution_Detail__c  ps :platformAddList){  
                if(ps.Unit_Price__c!=null && ps.Quantity__c!=null){
                    if(ps.Unit_Price__c>0 && ps.Quantity__c>0)
                        ps.Total_Price__c=ps.Unit_Price__c * ps.Quantity__c;
                    else{ 
                        ApexPages.addmessage(new ApexPages.message(ApexPages.severity.Error,'Quantity and price must be greater than 0.If you do not know the budget, please enter 8 or 88 in your local currency')); 
                        er=true;
                    }
                }
                else{
                    ApexPages.addmessage(new ApexPages.message(ApexPages.severity.Error,'Quantity and price must not be empty.If you do not know the budget, please enter 8 or 88 in your local currency')); 
                    er=true;
                }
            }      
        }      
    }


    public void checkBudget1(){
        if(publisherAddList != null && publisherAddList.size()>0){    
            for(Publisher_Solution__c p:publisherAddList){    
                if(p.Budget__c == null)    
                    ApexPages.addmessage(new ApexPages.message(ApexPages.severity.Error,'Budget must not be empty.')); 
                else{
                    if(p.Budget__c <=0)    
                        ApexPages.addmessage(new ApexPages.message(ApexPages.severity.Error,'Budget must be greater than 0.')); 

                }   
                err=true;
            }    
        }
    }

    public void checkBudget(){
        if(marketerAddList != null && marketerAddList.size()>0){    
            for(Marketer_Solution__c m:marketerAddList){    
               if(m.Budget__c == null)    
                    ApexPages.addmessage(new ApexPages.message(ApexPages.severity.Error,'Budget must not be empty.')); 
                else{
                    if(m.Budget__c <=0)    
                        ApexPages.addmessage(new ApexPages.message(ApexPages.severity.Error,'Budget must be greater than 0.')); 

                }
                err=true;
               }    
        }  
    }

    public pageReference checkDate(){    
        if(publisherAddList != null && publisherAddList.size()>0){    
            for(Publisher_Solution__c p:publisherAddList){    
                if(p.Start_Date__c>=p.End_Date__c)    
                    ApexPages.addmessage(new ApexPages.message(ApexPages.severity.Error,'End date should be greater than Start date.'));    
               err=true;
            }    
        }        
        return null;    
    }    
    public pageReference checkDate1(){    
        if(marketerAddList != null && marketerAddList.size()>0){    
            for(Marketer_Solution__c m:marketerAddList){    
                if(m.Start_Date__c>=m.End_Date__c)    
                    ApexPages.addmessage(new ApexPages.message(ApexPages.severity.Error,'End date should be greater than Start date.'));    
            err=true;
            }    
        }        
        return null;    
    }

    public void checkLost(){
        if(opp.Opportunity_Stage__c != 'Lost')
         lost =false;
         else
         lost =true;
    }
    public void checkLost1(){
        if(opp.Platform_Solution_Opportunity_Stage__c != 'Opportunity Lost')
         lost =false;
         else
         lost =true;
    }


    public PageReference saveOpp()
    {
         if(opp.name == null || opp.name ==''){
            ApexPages.addmessage(new ApexPages.message(ApexPages.severity.Error,'Name should not be blank'));
            return null;
        }

        else if(opp.Opportunity_Type__c== null || opp.Opportunity_Type__c==''){
            ApexPages.addmessage(new ApexPages.message(ApexPages.severity.Error,'type should not be blank'));
            return null;
        }
        else if(opp.Client_Type__c== null || opp.Client_Type__c==''){
            ApexPages.addmessage(new ApexPages.message(ApexPages.severity.Error,'Client type should not be blank'));
            return null;
        }
        else if(opp.Bill_To_Account__c== null || opp.Bill_To_Account__c==''){
            ApexPages.addmessage(new ApexPages.message(ApexPages.severity.Error,'Bill To Account should not be blank'));
            return null;
        }
        else if(opp.Ctrlshift_Market_Name__c== null || opp.Ctrlshift_Market_Name__c==''){
            ApexPages.addmessage(new ApexPages.message(ApexPages.severity.Error,'Market should not be blank'));
            return null;
        }
        else if(opp.Business_Type__c== null || opp.Business_Type__c==''){
            ApexPages.addmessage(new ApexPages.message(ApexPages.severity.Error,'Business Type should not be blank'));
            return null;
        }
        else if(opp.Payment_Terms__c== null || opp.Payment_Terms__c==''){
            ApexPages.addmessage(new ApexPages.message(ApexPages.severity.Error,'Payment Term should not be blank'));
            return null;
        }
        else if(opp.CtrlShift_Billing_Entity__c== null ){
            ApexPages.addmessage(new ApexPages.message(ApexPages.severity.Error,'Billing Entity should not be blank'));
            return null;
        }
        else if(opp.Client_Geo_Market__c== null || opp.Client_Geo_Market__c==''){
            ApexPages.addmessage(new ApexPages.message(ApexPages.severity.Error,'Client Geo Market should not be blank'));
            return null;
        }
        else if(opp.Opportunity_Source__c== null || opp.Opportunity_Source__c==''){
            ApexPages.addmessage(new ApexPages.message(ApexPages.severity.Error,'Source should not be blank'));
            return null;
        }   

        system.debug('Bill_To_Account__c '+opp.Bill_To_Account__c );  
        system.debug('Client_Type__c'+opp.Client_Type__c); 
        system.debug('Agency_Name__c'+opp.Agency_Name__c);


       list<account> ac= [select RecordType.name from Account where id=:opp.CtrlShift_Billing_Entity__c]; 

        if(ac.size()>0 && ac[0].RecordType.name!='Internal')
        {
            ApexPages.addmessage(new ApexPages.message(ApexPages.severity.Error,'CtrlShift Company (Billing Entity) should be CtrlShift Company Name. Clear the entered value and Choose a value from the Lookup.'));
            return null;
        }


        if (opp.Bill_To_Account__c == 'Advertiser' && opp.Advertiser_Name__c == null)
        {
            ApexPages.addmessage(new ApexPages.message(ApexPages.severity.Error,'Advertiser Name is required when Bill to account equal to Advertiser.'));
            return null;
        }

        if (opp.Bill_To_Account__c == 'Agency' && opp.Agency_Name__c == null)
        {
            ApexPages.addmessage(new ApexPages.message(ApexPages.severity.Error,'Agency Name is required when Bill to account equal to Agency.'));
            return null;
        }


        if (opp.Business_Type__c == 'Combined' && (opp.Business_Dev_Marketer_Soln_BDMS__c == null || opp.Business_Dev_Publisher_Soln_BDPS__c == null ||
                                                   opp.Client_Success_Marketer_Soln_CSMS__c == null || opp.Client_Success_Publisher_Soln_CSPS__c == null))
        {
            ApexPages.addmessage(new ApexPages.message(ApexPages.severity.Error,'BDMS,BDPS,CSMS and CSPS cannot be left blank.'));
            return null;
        }

        if (opp.Business_Type__c == 'Marketer Solution' && (opp.Business_Dev_Marketer_Soln_BDMS__c == null ||
                                                            opp.Client_Success_Marketer_Soln_CSMS__c == null))
        {
            ApexPages.addmessage(new ApexPages.message(ApexPages.severity.Error,'BDMS and CSMS cannot be left blank.'));
            return null;
        }
        if (opp.Business_Type__c == 'Publisher Solution' && (opp.Business_Dev_Publisher_Soln_BDPS__c == null || opp.Client_Success_Publisher_Soln_CSPS__c == null))
        {
            ApexPages.addmessage(new ApexPages.message(ApexPages.severity.Error,'BDPS and CSPS cannot be left blank.'));
            return null;
        }


        if (opp.Business_Type__c == 'Publisher Solution')
        {
            if((publisherAddList[0].PS_Product__c==null || publisherAddList[0].PS_Product__c=='') || (publisherAddList[0].Budget__c == null ) || (publisherAddList[0].Start_Date__c == null ) || (publisherAddList[0].End_Date__c== null ))
            {
                ApexPages.addmessage(new ApexPages.message(ApexPages.severity.Error,'Publisher Solution Section is required when Business Type equal to Publisher Solution.'));
                return null;
            }                
        }


        if (opp.Business_Type__c == 'Marketer Solution')
        {
            if((marketerAddList[0].MS_Product__c==null || marketerAddList[0].MS_Product__c=='') || (marketerAddList[0].Budget__c ==null) || (marketerAddList[0].Start_Date__c ==null) || (marketerAddList[0].End_Date__c==null))
            {
                ApexPages.addmessage(new ApexPages.message(ApexPages.severity.Error,'Marketer Solution Section is required when Business Type equal to Marketer Solution.'));
                return null;
            }                
        }

        if (opp.Business_Type__c == 'Combined')
        {
            if((marketerAddList[0].MS_Product__c==null || marketerAddList[0].MS_Product__c=='') || (marketerAddList[0].Budget__c ==null) || (marketerAddList[0].Start_Date__c ==null) || (marketerAddList[0].End_Date__c==null) || (publisherAddList[0].PS_Product__c==null || publisherAddList[0].PS_Product__c=='') || (publisherAddList[0].Budget__c == null ) || (publisherAddList[0].Start_Date__c == null ) || (publisherAddList[0].End_Date__c== null ))
            {
                ApexPages.addmessage(new ApexPages.message(ApexPages.severity.Error,'Marketer Solution and Publisher Solution Section is required when Business Type equal to Combined.'));
                return null;
            }                
        }
        /*
if(opp.Client_Geo_Market__c == null ){            
ApexPages.addmessage(new ApexPages.message(ApexPages.severity.Error,'Client Geo Market is Blank'));              
return null;    
}*/            


        if(opp.Agency_Commission__c== null && msps == true){
            ApexPages.addmessage(new ApexPages.message(ApexPages.severity.Error,'Agency Commission(%) is Blank'));
            return null;
        }          
        if(opp.Opportunity_Stage__c== null && msps == true ){  
            ApexPages.addmessage(new ApexPages.message(ApexPages.severity.Error,'MS / PS Opportunity Stage is Blank'));
            return null;
        } 
        if(opp.Business_Type__c== null && msps == true ){  
            ApexPages.addmessage(new ApexPages.message(ApexPages.severity.Error,'Business Type is Blank'));
            return null;
        }
        if(opp.Payment_Terms__c== null && msps == true ){  
            ApexPages.addmessage(new ApexPages.message(ApexPages.severity.Error,'Payment Terms is Blank'));
            return null;
        }


        for(Publisher_Solution__c p:publisherAddList){    
            if(p.Start_Date__c>=p.End_Date__c)    
                ApexPages.addmessage(new ApexPages.message(ApexPages.severity.Error,'End date should be greater than Start date.'));  
            //return null;  
        }

        for(Marketer_Solution__c m:marketerAddList){    
            if(m.Start_Date__c>=m.End_Date__c)    
                ApexPages.addmessage(new ApexPages.message(ApexPages.severity.Error,'End date should be greater than Start date.'));    
            //return null;
        }

        try {
            upsert opp;
        }       
        catch(exception e) {
        }


        if(publisherAddList != null && publisherAddList.size()>0){

            for(Publisher_Solution__c ps :publisherAddList){
                system.debug('--ps---'+ps);
                if(ps.PS_Product__c!=null){
                    ps.Opportunity__c = opp.id;
                    //ps.Start_Date__c = opp.Campaign_Start_Date1__c;
                    //ps.End_Date__c = opp.Campaign_End_Date1__c;              
                }        
            }
        }

        try{

            List<Publisher_Solution__c> PubListToInsert = new List<Publisher_Solution__c>();

            for(Publisher_Solution__c ps :publisherAddList){
                if(ps.PS_Product__c != null && ps.PS_Product__c != ''){
                    PubListToInsert.add(ps);
                }
            }

            if(PubListToInsert != null && PubListToInsert.size()>0){
                insert PubListToInsert;
            }
            system.debug('--publisherAddList2--'+publisherAddList);
        }
        Catch(exception e) {
        }

        if(marketerAddList != null && marketerAddList.size()>0){
            for(Marketer_Solution__c ms:marketerAddList){
                system.debug('--ms---'+ms);
                if(ms.MS_Product__c!=null){
                    ms.Opportunity__c = opp.id;
                    //ms.Start_Date__c = opp.Campaign_Start_Date1__c;
                    //ms.End_Date__c = opp.Campaign_End_Date1__c;
                } 
            }
        }

        try{          
            List<Marketer_Solution__c> MarListToInsert = new List<Marketer_Solution__c>();

            for(Marketer_Solution__c ms :marketerAddList){
                if(ms.MS_Product__c!=null && ms.MS_Product__c != ''){
                    MarListToInsert.add(ms);
                }
            }

            if(MarListToInsert != null && MarListToInsert.size()>0){
                insert MarListToInsert;
            }
        }
        Catch(exception e){
        }

        if(platformAddList != null && platformAddList.size()>0){

            for(Platform_Solution_Detail__c  ps :platformAddList){
                system.debug('--ps---'+ps);
                if(ps.Platform_Product__c!=null){
                    ps.Opportunity__c = opp.id;         
                }        
            }
        }

        try{

            List<Platform_Solution_Detail__c> PltaformListToInsert = new List<Platform_Solution_Detail__c>();

            for(Platform_Solution_Detail__c ps :platformAddList){
                if(ps.Platform_Product__c != null ){
                    PltaformListToInsert.add(ps);
                }
            }

            if(PltaformListToInsert != null && PltaformListToInsert.size()>0){
                insert PltaformListToInsert;
            }
            system.debug('--platformAddList2--'+platformAddList);
        }
        Catch(exception e) {
            system.debug('---Error--'+e.getlinenumber());
        }




        PageReference oppPage = new ApexPages.StandardController(opp).view();
        oppPage.setRedirect(true);
        return oppPage;
    }


    public PageReference cancel(){
        PageReference providerPage = new PageReference('/a06/o');
        providerPage.setRedirect(true);
        return providerPage;      
    }
}
2

There is no "quick fix" here. You need to examine the controller and think about the various paths through it and then write multiple test methods that cause those paths to be taken. Move code in the test class that would otherwise be repeated into separate methods you call from multiple tests or into nested classes.

A few other points:

  • Only use seealldata=true where you have to in tests; here I don't think you have to
  • Tests should confirm the behaviour of your code by using assert calls and then code coverage comes as a side effect so assert the results
  • In the controller, having Catch(exception e) {} is a very bad idea as your logic will silently fail and leave your users confused - see the commonly used alternative below.

A better way to handle the exceptions:

try {
    upsert opp;
} catch (exception e) {
    // An <apex:pageMessages/> in the Visualforce will present the messsages
    ApexPages.addMessages(e);
    return null;
}

Not the answer you're looking for? Browse other questions tagged or ask your own question.