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

Functionality for mocking method call to alter mutable parameters #71

Closed
donnie745 opened this issue Jan 4, 2019 · 2 comments
Closed
Labels

Comments

@donnie745
Copy link

Hi there,
I have an interface with a method that applies changes to mutable parameters and as far as I can tell the fflib library does not provide the functionality to setup the mock instance in the unit test to apply changes to the input parameters.

If this is indeed not currently available, are there any plans to add this in future? It would be a very useful addition to the library.

Cheers,
Donnie

@dfruddffdc
Copy link
Contributor

It supports Answering, see more detail here: https://xonoxforce.wordpress.com/2017/03/31/answering-with-apex-mocks/

Usually you just stub methods so that they return a particular value or throw a particular exception when invoked with the specified set of arguments. But as you've found, there are methods whose job is to mutate the supplied arguments.

Answering allows you to provide your own dummy implementation of these methods, to do things such as:

  • mutate supplied arguments
  • use the supplied arguments to derive a return value (e.g. return the supplied String argument, but in upper-case)

So answers are very powerful, just take care to keep your tests naive and self-contained - avoid simply recreating the actual implementation, since we're using mocking to avoid coupling with the real method.

@donnie745
Copy link
Author

Thanks for getting back so quickly. I'll need to update our version of the fflib library (and merge in a couple of bug fixes applied to the old library our end for the issue raised in #30 and the issue raised in #29, although it looks like the second issue may have also been fixed by you in #42), as we don't have the fflib_Answer class and functionality in our current version.

Cheers,
Donnie

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

No branches or pull requests

2 participants