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
Valentin F.Valentin F. 

Tests not entering into if/else

Hello everybody,
I needed to modify an apex class I deployed to production before.
The problem is that the code coverage is now 45% and I don't understand why it doesn't enter if neither if nor else. 

I'm doing a callout into a future method, using HttpCalloutMock.
Main class example :
User-added imageTest class :
Test.startTest();
        Test.setMock(HttpCalloutMock.class, new AppelAPIMock());
        ExpeditionSearchDPD.updateExpe(expeditions);
Test.stopTest();
AppelAPIMock :
@isTest
global with sharing class AppelAPIMock implements HTTPCalloutMock{
    global HTTPResponse respond(HTTPRequest req){
        HttpResponse res = new HTTPResponse();
        res.setHeader('Content-Type', 'text/xml');
        res.setBody('<?xml version="1.0" encoding="utf-8"?>' +
        	'<soap12:Envelope xmlns:soap12="http://www.w3.org/2003/05/soap-envelope" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">' +
        		'<soap12:Body>' + 
            		'<getShipmentTraceResponse xmlns="http://www.cargonet.software/">' + 
            			'<getShipmentTraceResult>' + 
                            '<ShippingDate>02.08.2019</ShippingDate>' + 
                            '<DeliveryDate>05.08.2019</DeliveryDate>' + 
                            '<Weight>0</Weight>' + 
                    	'</getShipmentTraceResult>' + 
                 	'</getShipmentTraceResponse>' + 
               	'</soap12:Body>' + 
            '</soap12:Envelope>');
        res.setStatusCode(200);
        return res;
    }
}
Thank you for your answers

 
Best Answer chosen by Valentin F.
Greg HGreg H
My guess is that the issue is related to how you are parsing the XML/DOM and not necessarily the mock callout. Are you sure you are traversing the nodes properly?
-greg

All Answers

piyush chawlapiyush chawla
thanks for ur article it was very useful 
PLZ. CHECK OUT MY PAGE OF APP CYBERFLIX.APK (https://cyberflixtv.info)
thanks
Jitendra Nagar 31Jitendra Nagar 31
Hi 
Valentin F.

Please provide values that satisfy the if and else condition, whenever it gets the values of if and else variable and satisfies the condition it will enter into them if and else
Valentin F.Valentin F.
Hi Jitendra, 
I specified in the AppelAPIMock class a value for 'DeliveryDate' as you can see.
It should be used as the ShippingDate juste before is. 
User-added image
Even when I'm hardcoding it directly in the Test.startTest();Test.stopTest(); it's not working
Greg HGreg H
My guess is that the issue is related to how you are parsing the XML/DOM and not necessarily the mock callout. Are you sure you are traversing the nodes properly?
-greg
This was selected as the best answer
Valentin F.Valentin F.
Indeed you're right Greg, I was looping in 'getShipmentTraceResult' to get every node and then I forgot to remove a break I put when I used another loop inside this one. For other elements, I didn't give them a value when creating a mocked object.
Thank you for your clue !