function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Behzad Bahadori 18Behzad Bahadori 18 

Test class Unit test not covering method

I have this method
 
public PageReference selectBandwidth() {

    if (!BandwidthQualified
        || prequalToSave == null
        || servicesToAdd == null
        || (prequalToSave != null && prequalToSave.IsComplete__c && servicesToAdd.size() == 0))
    {
        return Page.PBXOrderingQuotePdf;
    }


    Decimal bandServicesSel = 0;

    if (servicesToAdd != null)
    {
        for (Service__c service : servicesToAdd)
        {
            if (service.IsSelected__c)
                bandServicesSel += 1;
        }
    }

        showPageMessage = false;
        pageMessage = '';

    if (!String.isBlank(qotId)) { 
        qot = [select Id, Pricebook2Id, Name from Quote where Id = :qotId];

    }
    else if (!isVoiceBeingAdded)
    {
        if (qot.Name == null)
            qot.Name = 'No Name';
        qot.BillingCity = city;
        qot.BillingState = state ;
        qot.BillingPostalCode = zip ;

        qot.BillingStreet = addressLine1 + ' ' + unitType + ' ' + unitValue ;
        qot.ShippingCity =  account.ShippingCity; 
        qot.ShippingCountry = account.ShippingCountry;
        qot.ShippingStreet = account.ShippingStreet;
        qot.ShippingState = account.ShippingState;
        qot.ShippingPostalCode = account.ShippingPostalCode;


        insert qot;
        url = '/apex/QuotePDF?id=' + qot.Id;
    }

    List<PricebookEntry> products = [Select Id, ProductCode , IsActive, Product2Id, UnitPrice, Name from PricebookEntry where Pricebook2Id =: qot.Pricebook2Id];

    if (servicesToAdd != null)
    {
        System.debug('I am inside the Service and service has been added 1');
        for (Service__c service : servicesToAdd)
        {
             System.debug('I am inside the Service and service has been added 2' + servicesToAdd );
            if (service.IsSelected__c)
            {
                 System.debug('I am inside the Service and service has been added 3 service.IsSelected__c' );

                for (PricebookEntry entry : products)
                {
                    System.debug('entry.ProductCode Counter' + entry.ProductCode);
                    if (entry.ProductCode == 'internetAccessWizard')

                    {



                        QuoteLineItem quoteLineItem = new QuoteLineItem();
                        quoteLineItem.QuoteId = qot.Id;
                        quoteLineItem.PricebookEntryId = entry.Id;
                        quoteLineItem.Product2Id = entry.Product2Id;
                        quoteLineItem.Quantity = 1;
                        quoteLineItem.UnitPrice = service.Price__c;
                                                   quoteLineItem.Enter_Activation__c = service.SetupPrice__c;
                        quoteLineItem.Activation_Fee_CheckBox__c = true;
                        quoteLineItem.Term_Area__c = service.ContractLength__c;
                        System.debug(' Contract Term ' +  quoteLineItem.Term_Area__c );



                        if(service.SubType__c.contains('test')){
                            quoteLineItem.Internet_Service_Fee__c = 2.88;
                            quoteLineItem.Internet_Service_Fee_CheckBox__c = true;
                        }
                        else{

                            quoteLineItem.It_HAS_FSLS_checkBox__c = true;


                        }



                        insert quoteLineItem;

                    }
                }



                bandServicesSel += 1;
            }
        }
    }


   return Page.PBXOrderingQuotePdf;
}
Unit Test
 
static testmethod void selectBandwidth_Test(){
     OpportunityController controller = new OpportunityController();
     controller.BandwidthQualified = false;

    Product2 prod = new Product2();
    prod.Name = 'Laptop X200'; 
    prod.IsActive = true;
    prod.ProductCode  = 'Feature';

    insert prod;

        id customPB = Test.getStandardPricebookId();

    Opportunity opp = new Opportunity();
    opp.Name = 'Test';
    opp.StageName='Quote Sent';
    opp.CloseDate = system.today();
    opp.Pricebook2Id = customPB;
    insert opp;

    Quote quote = new Quote();
    quote.Name='test';
    quote.Opportunityid = opp.id;     
    quote.ExpirationDate = date.today()+30;        
    quote.Pricebook2Id = customPB;

    //insert quote;

    controller.isVoiceBeingAdded = false;






    PricebookEntry customPrice = new PricebookEntry(
        Pricebook2Id = customPB, Product2Id = prod.Id,
        UnitPrice = 12000, IsActive = true);

    insert customPrice;

    controller.qot = quote;
     controller.selectBandwidth();
 }


I am not sure what else to add
bob_buzzardbob_buzzard
And you get no coverage of the method at all? That makes no sense as you are clearly calling the controller method in your test so it must hit the first if statement at least. Do you get any errors when you run the test? That's the only way I can see you wouldn't get coverage.