apex-enterprise-patterns / fflib-apex-mocks

An Apex mocking framework for true unit testing in Salesforce, with Stub API support
BSD 3-Clause "New" or "Revised" License
423 stars 214 forks source link

Matcher sObjectWith doesn't work with uow.registerXXX(list) #53

Closed cropredyHelix closed 6 years ago

cropredyHelix commented 7 years ago

The useful Matcher sObjectWith can't be used when attempting to verify the inputs to these:

uow.registerNew(someListOfSobjects); or uow.registerDirty(someListOfSobjects);

This is because the sObjectWith matcher is a singleton SObject and the argument passed to the uow methods is a list.

What would be nice is a Matcher that would compare an expected SObject w/ field vals to see if any of the Sobjects passed to a uow.registerXXX(someList) had an sobject with those fieldValues.

This could, I suppose, be extended to a Matcher that was a list of expected Sobjects w/ field values and would ensure that the list argument passed to uow.registerXXX had all of the expected Sobjects.

Basically, if the code under test is using the uow.registerXXX(someList) methods, there is no current way without resorting to ArgumentCapture to verify that the code under test called uow with the expected sobject(s). Or, put another way, since ApexMocks exists to support fflib (among other use cases), then supporting the uow.registerXXX(someList) should be supported with a Matcher.

dfruddffdc commented 6 years ago

Yup, sounds reasonable. What would be really awesome is composable matchers, so we wouldn't have to deal with every permutation (List of SObjects with Name, List of SObjects with some field values, List of SObjects with Ids, or all of the Map and Set counterparts)... But List seems a particularly common case, like you say, so should get specific support.

dfruddffdc commented 6 years ago

I guess we can close this, thanks to your PR. Thanks again!