Closed cropredyHelix closed 6 years ago
After some inspired searching on frup42 blog, I now see how to use fflib_ArgumentCaptor
to solve the above on verifying maps. Still seems as if there should be enhancement possibilities for more matchers on fflib_Match
to deal with sets.
Another Apex quirk... This compiles fine:
List<Account> records = new List<Account>{};
List<Object> castUp = (List<Object>)records;
List<Account> castDown = (List<Account>)castUp;
But this doesn't compile, because: Incompatible types since an instance of Set
Set<Account> records = new Set<Account>{};
Set<Object> castUp = (Set<Object>)records;
Set<Account> castDown = (Set<Account>)castUp;
Likewise with Maps. So we can't write generic matchers for Maps and Sets, we have to have a specific matcher for the specific Typed Maps/Sets. This would be a lot of matchers, but not particularly useful for the majority of ApexMocks consumers.
So when the requirement comes up, we just let the consumer use captors or custom matchers knowing the specific Types in question in their test.
Looking through the examples in
fflib_Match.cls
andfflib_ApexMocksTest.cls
I'm not seeing any way tok
, has valuev
My example is testing a VF controller that calls a
FooService.doBar(..)
Hence, mocking a serviceFooServiceImpl
, methoddoBar(map<ID,Foo.CustomType>)
I tried this (match on entire map)
but even though
doBar
is called with the mapsomeId => new Foo.CustomType(arg1, arg2)
(verified using debug), theverify
method in ApexMocks comes back withExpected : 1, Actual: 0 -- Wanted but not invoked: FooServiceImpl__sfdc_ApexStub.doBar(Map<Id,Foo.CustomType>)
So, bottom line - would be nice to see how to use matchers on sets (specific entry) and maps (entire map, hasKey, hasValueForKey, etc.) - especially without having to resort to custom matchers.