How to cover PageReference method in test class with assertions in Salesforce?

How to cover PageReference method in test class with assertions in Salesforce?

Sample Code:


Apex Class:


public class Sample {


    public Sample() {
    }
    
    public PageReference goToInfallible() {
    
        PageReference pg = new PageReference(‘https://www.infallibletechie.com’);
        pg.setRedirect(true);
        return pg;
        
    }
    
}


Test Class:


@isTest
private class SampleTest {


    @isTest static void test() {
    
        Sample s = new Sample();
        PageReference pg = s.goToInfallible();
        system.assertEquals(‘https://www.infallibletechie.com’, pg.getUrl());
        system.assertEquals(true, pg.getRedirect());
        system.assertEquals(new Map < String, String >(), pg.getParameters());
        system.assertEquals(new Map < String, String >(), pg.getHeaders());
        
    }
    
}

Leave a Reply