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
MUSFAR KT 6MUSFAR KT 6 

Hi Can anyone help with the testclass for below code

public with sharing class fflib_QualifiedMethodAndArgValues
{
    private final fflib_QualifiedMethod qm;
    private final fflib_MethodArgValues args;
    private final Object mockInstance;

    public fflib_QualifiedMethodAndArgValues(fflib_QualifiedMethod qm, fflib_MethodArgValues args, Object mockInstance)
    {
        this.qm = qm;
        this.args = args;
        this.mockInstance = mockInstance;
    }

    public fflib_QualifiedMethod getQualifiedMethod()
    {
        return qm;
    }

    public fflib_MethodArgValues getMethodArgValues()
    {
        return args;
    }

    public Object getMockInstance()
    {
        return mockInstance;
    }

    public override String toString()
    {
        return qm + ' with args: [' + String.join(args.argValues, '],[') + ']';
    }
}
Suraj Tripathi 47Suraj Tripathi 47
Hi MUSFAR,
Here, in this case, the parameters that are passed in the constructor are not clear, i.e We need to create a record of the same type as the parameters passed in the constructor. If you are able to create a record of that type please provide it. 
If the record is created, then you just need to call every function in the test class. and that's it, it will cover the whole class.
If You need to make a mock callout then you need to create a fake response for your requirement. Here is the example to create a mock response
@isTest
global class MockHttpResponseGenerator implements HttpCalloutMock {
    // Implement this interface method
    global HTTPResponse respond(HTTPRequest req) {
        // Optionally, only send a mock response for a specific endpoint
        // and method.
        System.assertEquals('http://example.com/example/test', req.getEndpoint());
        System.assertEquals('GET', req.getMethod());
        
        // Create a fake response
        HttpResponse res = new HttpResponse();
        res.setHeader('Content-Type', 'application/json');
        res.setBody('{"example":"test"}');
        res.setStatusCode(200);
        return res;
    }
}
Here is the example for your reference to write the test class.
@isTest
public class fflib_QualifiedMethodAndArgValues_Test{
	@isTest
	public static testfunction(){
		fflib_QualifiedMethod qm = new fflib_QualifiedMethod();
		//create the record of fflib_QualifiedMethod type
		fflib_MethodArgValues args= new fflib_MethodArgValues ();
		//create the record of fflib_MethodArgValues type
		//mock object
		Object mockinstance
		Test.startTest();
		fflib_QualifiedMethodAndArgValues cls = new fflib_QualifiedMethodAndArgValues(qm,args,mockinstance);
 		fflib_QualifiedMethod returnVal = cls.getQualifiedMethod();
		System.assertEqual(qm,returnVal);
		fflib_MethodArgValues returnArgs = cls.getMethodArgValues();
		System.assertEqual(args,returnArgs);
		//and so on.
	}	
}

If this helped you please mark it as the best answer.
Thank you 
Regards 
Suraj Tripathi
MUSFAR KT 6MUSFAR KT 6
Can you please share your contact number or this is my number 8893605960  because I have some doubts  
Suraj Tripathi 47Suraj Tripathi 47
Hi MUSFAR,
Sorry to say, but I can't share my number. But I'm eager to help.
If the above explanation helped you please mark it as the best answer.
If you have any other query you can post them as a separate question.
Hope you will understand.
Thank You 
Regards
Suraj Tripathi.