Add new method(s) in ApplicationErrorVerifications to permit custom VerificationMode #297
Labels
new feature
A new feature such as a new class, method, package, group of classes, etc.
Milestone
Add a new method(s) in
ApplicationErrorVerifications
to permit using customVerificationMode
. This will allow more flexibility, such as when errors are recorded in a background thread and we need to provide a timeout to the verification.Suppose we have the following test code which needs to use a timeout, which we have no way to do currently in
ApplicationErrorVerifications
:We want a method which can take the place of the verification code above, e.g.
The above method implies that either the
insertOrIncrementCount
method was called exactly once or that we only care about the most recent captured value. The issue with allowing anyVerificationMode
here is that there can be multiple invocations such as when using theatLeast
verification mode. For example:By using
atLeastOnce
, there might be multiple invocations, and as defined we would only get the latest capturedApplicationError
. I don't see any way to define a single method which can handle both, so perhaps we add two methods and put the responsibility on the caller to call the correct method and pass the appropriateVerificationMode
based on whether the verification mode can result in one or more values. (with great power...)So, if someone passes
timeout(500).only()
toverifyManyInsertOrIncrementCount
and (somehow) expects to get more than one result, they will always be disappointed and will need to figure out the problem themselves. It would be a bad idea for us to inspect the actual type of theVerificationMode
to obtain the class (e.g.org.mockito.internal.verification.Only
) and try to detect invalid verification modes. One simple reason is hinted at by the package name containing the word "internal" - it's not supposed to be accessed by users, whether enforced by the Java module system or not.I prefer having the flexibility and take responsibility for using the methods correctly. Of course, the Javadocs should be very clear about the intended usage and provide appropriate caveats and warnings.
The text was updated successfully, but these errors were encountered: