tstachl/force_desk_api — pull request #1 by ViViDboarder (2013-12-20 19:32:20+00:00)
Title: Add setMock instance method to DeskClient

It appears there is a "feature" in SFDC that makes Tests for Batch Apex
containing Http Callouts fail when using Test.setMock.

It seems that when the batch is run sequentially at the call of
Test.stopTest(), the insert of the batch job into the AsyncApexJob table
causes the callout to fail because of "uncommitted work". After several
hours talking with SFDC, it seems there is no solution since it is
"working as designed".

As a result, this patch allows a user to specify a Mock response for the
Client via an instance method. When set and while running a test, it
will try to get a response from the Mock instead of the HTTP request.
This prevents the request from being executed at all and provides a
workaround for this problem.

Should Salesforce update their system to allow for testing Requests in
Batch Apex, this will no longer be needed and can be reverted.