surajp / universalmock

A universal mock class in Apex
MIT License
80 stars 17 forks source link

Add support for void return methods #6

Closed jamessimone closed 3 years ago

jamessimone commented 4 years ago

I added a method to my own implementation:

public UniversalMocker thenReturnVoid() {
    if (!this.isInSetupMode) {
      throw new InvalidOperationException('Invalid order of operations. Must specify method name to mock/assert first');
    }

    this.callCountsMap.put(this.getCurrentKey(), 0);
    this.resetState();
    return this;
}

However, you might have some opinion on a better implementation, and I'm all ears!

surajp commented 4 years ago

Makes sense to have a dedicated method to return void. What would be some scenarios/reasons where you would want to mock a method to return void?

jamessimone commented 4 years ago

When I want to validate their inputs - but if this is already possible and I’m misremembering the API, I will gladly close!

surajp commented 4 years ago

I see. Yes, you don't have to mock a return value to validate the inputs or call counts after the test. The one scenario I can think of, is when you've overloaded methods. I think adding this to the api makes sense. Will do so. Thanks!

surajp commented 3 years ago

Added in #8 . Commit bcbb743726c5