0

I am writing a test class for a visualforce page extension. The method upserts a record and then redirects to a custom vf page to add Opportunity products.

I get the error

System.AssertException: Assertion Failed: The url should have redirected:

Expected: /apex/ProductSelectorApp?Id=00618000007yNDdAAM&oppId2=00618000007yNDdAAM&oppRevisionId=a1718000001hzLNAAY,

Actual: /apex/ProductSelectorApp?id=00618000007yNDdAAM&oppId2=00618000007yNDdAAM&oppRevisionId=a1718000001hzLNAAY

Looking at both strings they look exactly the same, what could I be doing wrong?

Apex Class:

public PageReference saveAddProduct()
{
    revision.Name = revision.Revision_Reason__c;
    upsert revision;
    
    String url = '/apex/ProductSelectorApp?oppId2={0}&oppRevisionId={1}&id={0}';
    url = String.format(url, new String[] {revision.Opportunity_Name__c, revision.Id });
    return new Pagereference(url);
}

Test class:

@isTest static void testSave_AddProduct()
{
    Opportunity oppy = [SELECT Id FROM Opportunity];
    Opportunity_Revision__c oppyR = new Opportunity_Revision__c();
        oppyR.Opportunity_name__c = oppy.id;
        oppyR.Revision_Reason__c = 'Swap';
    insert oppyR;

    String s = 'Cancellation';
    String url = '/apex/ProductSelectorApp?Id=' + oppy.Id + '&oppId2=' + oppy.id + '&oppRevisionId=' + oppyR.Id;

    Test.startTest();      
        ApexPages.StandardController sc = new ApexPages.StandardController(oppyR);
        NPD_OpportunityRevisionExtension ext = new NPD_OpportunityRevisionExtension(sc);

        oppyR.Revision_Reason__c = s;
        PageReference pRef = ext.saveAddProduct();

    Test.stopTest();

    Opportunity_Revision__c results = [SELECT Id, Revision_Reason__c FROM Opportunity_Revision__c];
    System.assertEquals(s, results.Revision_Reason__c,
        'The Revision record should be updated');
    
    System.assertEquals(url, pRef.getURL(),
        'The url should have redirected');
}

1 Answer 1

0

I figured this out as I was proofreading so might as well leave this for future knowledge. System.assert is exact in the matching

in one method I had:

/apex/ProductSelectorApp?id=

In the other method I had:

/apex/ProductSelectorApp?Id=

The difference is between I and i.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .