You need to sign in to do that
Don't have an account?
Why is this test failing? System.Exception: Assertion Failed: Expected: A , Actual: A
Not sure what I am doing wrong or if this is not something you can test.
My class:
public class alertControllerV3 {
public static PageReference redirectToAppropriateAlertsPage_live() {
if( alwaysShowTheseInAlertsPageList_live.size()==0) {
PageReference acctPage = new PageReference('https://na3.salesforce.com/home/home.jsp');
acctPage.setRedirect(true);
return acctPage;
}
else {PageReference acctPage = new PageReference('https://na3.salesforce.com/apex/alert');
acctPage.setRedirect(true);
return acctPage;
}
return null;
}
}
My test:
public static testMethod void testPositiveResults(){
Test.setCurrentPage(redirectToAppropriateAlertsPage_live() );
System.debug('the current page is...' +ApexPages.currentPage() );
pageReference pageRef1 = ApexPages.currentPage();
pageReference pageRef2 = new pageReference('https://na3.salesforce.com/apex/alert');
System.assertEquals(pageRef2, pageRef1 );
}
Debug log:
20090616212631.426:Class.alertControllerV3.testPositiveResults: line 893, column 9:
returning System.PageReference from method public static System.PageReference redirectToAppropriateAlertsPage_live() in 0 ms
20090616212631.426:Class.alertControllerV3.testPositiveResults: line 898, column 3:
the current page is...System.PageReference[https://na3.salesforce.com/apex/alert]
System.Exception: Assertion Failed:
Expected:
System.PageReference[https://na3.salesforce.com/apex/alert],
Actual:
System.PageReference[https://na3.salesforce.com/apex/alert]
Thank you.
When testing this method...
Test.setCurrentPage(redirectToAppropriateAlertsPage_live() );
Is it a bug or am i writting something incorrectly to make it so if I use this, it works...
string result=''; for(Solution s012 :alwaysShowTheseInAlertsPageList_live){ if(alwaysShowTheseInAlertsPageList_live.size()>0){result='true';} else{result='false';} } pageReference pageRef1 = new pageReference('https://na3.salesforce.com/apex/alert'); System.debug('result of the redirect should be...' +pageRef1 ); System.debug('result of the redirect is...' ApexPages.currentPage() ); System.assertEquals( 'true', +result );
but if I use this it fails...
pageReference pageRef1 = new pageReference('https://na3.salesforce.com/apex/alert'); pageReference pageRef2 = new pageReference( ApexPages.currentPage() ); System.assertEquals( pageRef1 , pageRef2 );
Because the attempt directly above produces this in the debug log, which I dont understand...
System.Exception: Assertion Failed: Expected: System.PageReference[https://na3.salesforce.com/apex/alert], Actual: System.PageReference[https://na3.salesforce.com/apex/alert]
I am new to apex but to me it looks as if what I expected matches the actual.
Thank you.
Hi Walter,
Your problem is that you are comparing objects, pageRef1 and pageRef2. pageRef1 isn't the same object as pageRef2 so I'd expect an assertEquals not to work. I think the debug log shows the 'toString();' of each object so they look the same.
If you were to check the getUrl() method of each then it'd be the same.
Hope this helps.
R.
Thanks,
Dinesh