surajp / universalmock

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

Method call chaining could lead to incorrect passing tests. #2

Closed Thieveryshoe closed 4 years ago

Thieveryshoe commented 4 years ago

As a newer developer, one of the issues I anticipate with the way things are setup is the chaining of method calls. The timesExactly() call will likely be forgotten at some point, and without compiler support for Apex, the mock won't be setup correctly and test could accidentally pass.

mock.assertThat().method(mockedMethodName).wasCalled(2).timesExactly();

I propose that some sort of Times object be used, and be a required argument in the wasCalled() method.

mock.assertThat().method(mockedMethodName).wasCalled(Times.Exactly, 1); mock.assertThat().method(mockedMethodName).wasCalled(Times.LessThan, 2); mock.assertThat().method(mockedMethodName).wasCalled(Times.MoreThan, 1);

This signature style forces the developer to explicitly state how many times the method should be called and there will be a compilation error if no Times argument is given.

surajp commented 4 years ago

@Thieveryshoe Thanks for the feedback. I've made a change to address this. Will think about it some more before merging with master. Let me know your thoughts