function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
WhiteFusion17WhiteFusion17 

Static Resource Mock - Help Needed

Hello I want to use a static resource for my Mock but I cannot get it to work where am I going wrong based on this snippet of code:
 
@isTest
global class TrelloAPICalloutClass_Mock implements HttpCalloutMock {

    public static HttpResponse res;
    public static HttpRequest req;
    private String whichMock;

    public TrelloAPICalloutClass_Mock (String mockNeeded){
        this.whichMock = mockNeeded;
    }

    global HTTPResponse respond(HTTPRequest req){
        res = new HttpResponse();
        switch on whichMock {
            when 'createboards' {
                createBoardMock();
            }
            when 'getattachment' {
                attachmentMock();
            }
            when 'gettrelloboards' {
                getTrelloBoardsMock();
            }
            when 'getTrelloListsFromBoardMock' {
                getTrelloListsFromBoardMock();
            }
            when 'getTrelloLabelsFromBoardsMock' {
                getTrelloLabelsFromBoardsMock();
            }
            when 'getTrelloBoardsMockError' {
                getTrelloBoardsMockError();
            }
            when 'getTrelloBoardsMockNewBoard' {
                getTrelloBoardsMockNewBoard();
            }
            when 'getTrelloBoardsMockUpdateName' {
                getTrelloBoardsMockUpdateName();
            }
            when 'getTrelloListsFromBoardMockNewList' {
                getTrelloListsFromBoardMockNewList();
            }
        }
        return res;        
        
    }

    private static void getTrelloBoardsMock(){
        // Get The Trello Boards
        StaticResourceCalloutMock mock = new StaticResourceCalloutMock();
        mock.setStaticResource('getOrgBoards');
        mock.setHeader('Content-Type', 'application/json');
        mock.setStatusCode(200);
        Test.setMock(HttpCalloutMock.class, mock);
    }

I have no doubt it is to do with the res vs the mock but I cannot work out the issue
Best Answer chosen by WhiteFusion17
WhiteFusion17WhiteFusion17
Sorted this when you use a static resource for the mock body you have to change the way you call the method in the test

All Answers

WhiteFusion17WhiteFusion17
Sorted this when you use a static resource for the mock body you have to change the way you call the method in the test
This was selected as the best answer
SwethaSwetha (Salesforce Developers) 
HI WhiteFusion17 ,
Thank you for sharing the fix. Can you elaborate more/provide code on the way you call the method in the test.