Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ambiguous method signature: void setMock #36

Open
EmilioMN92 opened this issue Apr 29, 2021 · 1 comment
Open

Ambiguous method signature: void setMock #36

EmilioMN92 opened this issue Apr 29, 2021 · 1 comment

Comments

@EmilioMN92
Copy link

EmilioMN92 commented Apr 29, 2021

When creating an AccountsServiceTest (similar to the OpportunitiesServiceTest in the sample), I have the following error:

Ambiguous method signature: void setMock.

The test method:

@IsTest
	private static void testSync(){
        // Create mocks
		fflib_ApexMocks mocks = new fflib_ApexMocks();
		
		fflib_ISObjectUnitOfWork uowMock = (fflib_ISObjectUnitOfWork) mocks.mock(fflib_ISObjectUnitOfWork.class);
		IAccounts domainMock = (IAccounts) mocks.mock(IAccounts.class);
		IAccountsSelector selectorMock = (IAccountsSelector) mocks.mock(IAccountsSelector.class);


		// Given
		mocks.startStubbing();
		List<Account> testAccsList = new List<Account> { 
			new Account(
				Id = fflib_IDGenerator.generate(Account.SObjectType),
				Name = 'Clinic Test',
                RecordTypeId = Schema.SObjectType.Account.getRecordTypeInfosByDeveloperName().get(Label.RecordType_BusinessAccount).getRecordTypeId(),
                Type = 'IVF Clinic', 
                Subsidiary__c = 'SPAIN', 
                Category__c = 'A', 
                BillingCountry = 'Spain', 
                SRMExternalId__c = '2222')};
		Set<Id> testAccSet = new Map<Id, Account>(testAccsList).keySet();
		mocks.when(domainMock.sObjectType()).thenReturn(Account.SObjectType);
		mocks.when(selectorMock.sObjectType()).thenReturn(Account.SObjectType);
		mocks.when(selectorMock.selectById(testAccSet)).thenReturn(testAccsList);
		mocks.stopStubbing();
		Application.UnitOfWork.setMock(uowMock);
		Application.Domain.setMock(domainMock);
		Application.Selector.setMock(selectorMock);

		// When
		AccountsService.sync(testAccSet);

		// Then
		((IAccounts) 
			mocks.verify(domainMock)).sync(uowMock);
		((fflib_ISObjectUnitOfWork) 
			mocks.verify(uowMock, 1)).commitWork();
    }

My IAccounts is like this:
public interface IAccounts extends fflib_ISObjectDomain { void sync(fflib_ISObjectUnitOfWork uow); }

In order to patch it, I added a new setMock function that receives an IAccounts as the parameter, but it is obviously a patch.
Can anyone please tell me why am I getting this error?

Thanks in advance.

@stohn777
Copy link
Contributor

stohn777 commented May 18, 2021

Hi @EmilioMN92

I think I see what might be happening here, but I cannot reproduce with a more simple test, included below. I'd have to do a bit more research.

May I suggest reducing your case to its bare essentials, which may uncover some overlooked bit of information.


IBase.cls

public interface IBase {
    void One();
}

InterfaceResolveTest.cls

@Istest
private class InterfaceResolveTest {

    @IsTest
    private static void test() {
        ISuper suuper = (ISuper) Test.createStub(ISuper.class, new Stubby());
        System.assertEquals('ISuper', new InterfaceResolveTest().setMock(suuper));
    }
    
    private String setMock(IBase mock) {
        return 'IBase';
    }
    
    private String setMock(ISuper mock) {
        return 'ISuper';
    }
}

ISuper.cls

public interface ISuper extends IBase {
    void Two();
}

Stubby.cls

public class Stubby implements StubProvider {

    public Object handleMethodCall(
        Object stubbedObject, 
        String stubbedMethodName, 
        Type returnType, 
        List<Type> listOfParamTypes, 
        List<String> listOfParamNames, 
        List<Object> listOfArgs) {
        
        return this;
    }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants