The parameter values need to match exactly. Because your controller is calling
ConnectApi.ChatterFeeds.getFeedItemsFromFeed(null, ConnectApi.FeedType.Record, '0F9d00000000fJc');
you need to call
ConnectApi.ChatterFeeds.setTestGetFeedItemsFromFeed(null, ConnectApi.FeedType.Record, '0F9d00000000fJc', testPage);
in your test to register the test data, instead of
ConnectApi.ChatterFeeds.setTestGetFeedItemsFromFeed(null, ConnectApi.FeedType.News, 'me', testPage);
Yes!
I love this question, as it's one of my pet peeves. People don't test @future calling methods because they don't know it's possible.
Enter the magic of two key methods:
Test.StartTest();
Test.StopTest();
When you utilize these methods -- and you should! they do a couple of key things for you.
- they reset your governor limits so you can test if your actual code is going to hit Limits.
- Test.StopTest(), actually forces your @future methods to run right now and return before progressing to the next step.
so, in your test example, if you take your exact test and add those two methods thusly:
@isTest
private class FooControllerTest
{
@isTest
private static void save_ValidData_CalloutQueued()
{
// Setup my test data...
FooController controller = new FooController();
Test.StartTest();
controller.save();
Test.StopTest();
// You can actually now assert that yes, it indeed was queued,
// and has run, and has returned data. Since this is a callout?
// look at the callout mocks for more info on returning mock
// data to assert on.
System.assert(System.isFutureJobQueued('FooServices.bar'));
}
}
With Regards to just identifying of a job has been queued:
Select ApexClassId, CompletedDate, CreatedById, CreatedDate, ExtendedStatus, Id,
JobItemsProcessed, JobType, LastProcessed, LastProcessedOffset, MethodName,
NumberOfErrors, ParentJobId, Status, TotalJobItems from AsyncApexJob
This object, (and query above) should list all pending async apex jobs including enqueued @future methods. I expect (but have never tried) that you could build a where clause based on MethodName. ApexClassId would likely work as well, but would be ugly as the Id's may be hard to come by dynamically.
Best Answer
Chatter Announcements are nothing but FeedItem records. You can just query them after creating an announcement in test class
Make sure you mark your test class seeAllData as true.
src: https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/connectAPI_TestingApex.htm