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('http://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('http://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());
        
    }
    
}

No comments:

Post a Comment