Skip to content

Verify on mocked UoW.registerDirty() with relationship fails with matcher number mismatch #416

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

Open
janskola opened this issue Jun 24, 2022 · 0 comments

Comments

@janskola
Copy link

Issue description
When I need to verify fflib_ISObjectUnitOfWork.registerDirty(SObject, SObjectField, SObject) method call on a mocked instance, I'm getting this exception:
fflib_ApexMocks.ApexMocksException: The number of matchers defined (3). does not match the number expected (1)

To Reproduce
I've created classes to reproduce the issue.

Steps to reproduce the behavior:

  1. Create a scratch org with fflib-apex-common deployed
  2. Deploy following classes SimpleClass, SimpleClass_Test
  3. Run the test method SimpleClass_Test.testIssue()
  4. See error

SimpleClass.cls

public with sharing class SimpleClass {

    public void modifyData(Account a, Contact c, fflib_ISObjectUnitOfWork uow) {
        uow.registerDirty(c, Contact.AccountId, a);
    }
}

SimpleClass_Test.cls

@IsTest
private class SimpleClass_Test {
    @IsTest
    private static void testIssue() {
        fflib_ApexMocks mocks = new fflib_ApexMocks();
        fflib_ISObjectUnitOfWork uowMock = new fflib_SObjectMocks.SObjectUnitOfWork(mocks);

        Account a = new Account();
        Contact c = new Contact();

        SimpleClass sc = new SimpleClass();

        Test.startTest();
        sc.modifyData(a, c, uowMock);
        Test.stopTest();

        ((fflib_ISObjectUnitOfWork) mocks.verify(uowMock, mocks.times(1)))
            .registerDirty(
                fflib_Match.sObjectOfType(Contact.SObjectType),
                fflib_Match.anySObjectField(),
                fflib_Match.sObjectOfType(Account.SObjectType)
            );
    }
}

Expected behavior
This test method is expected to execute without any issue and result in a test pass.

Error message observed

fflib_ApexMocks.ApexMocksException: The number of matchers defined (3). does not match the number expected (1)
If you are using matchers all arguments must be passed in as matchers.
For example myList.add(fflib_Match.anyInteger(), 'String') should be defined as myList.add(fflib_Match.anyInteger(), fflib_Match.eq('String')).
Class.fflib_Match: line 51, column 1
Class.fflib_AnyOrder.verify: line 23, column 1
Class.fflib_MethodVerifier.verifyMethodCall: line 20, column 1
Class.fflib_ApexMocks.verifyMethodCall: line 132, column 1
Class.fflib_ApexMocks: line 256, column 1
Class.fflib_ApexMocks: line 236, column 1
Class.fflib_SObjectMocks.SObjectUnitOfWork.registerDirty: line 145, column 1
Class.SimpleClass_Test.testIssue: line 20, column 1

Version
Reproducible for me on latest version of fflib-apex-common.

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

1 participant