While converting a utility class from V26 to V31, my VF testmethods started breaking.
Problem was traced down to how ApexPages.addMessage() behavior varies if the i+1st message has the same summary as the ith message, even if the detail argument is different between i+1st and ith message.
If the summary values are the same, the i+1st message won't get added to the page messages.
Here is the code that proves this:
@isTest
private static void testAddVFMsg() {
Test.startTest();
Test.setCurrentPage(Page.Foo);
ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.INFO,'MsgSummary','00detail'));
System.assertEquals(1,ApexPages.getMessages().size());
ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.INFO,'MsgSummary','01detail'));
// passes at V28 and earlier, fails at V29+
System.assertEquals(2,ApexPages.getMessages().size());
Test.stopTest();
}
Obviously I can work around this by using different values for the summary argument in the ApexPages.Message constructor or reworking my testmethod expectations.
But - seems to me that if you call addMessage(..), the resulting getMessages() should include the message you added.
So - the question is:
- Bug? or
- Documentation needs enhancing?