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

Extract invocation matching logic into InvocationShape #662

Merged
merged 4 commits into from
Aug 24, 2018

Conversation

stakx
Copy link
Contributor

@stakx stakx commented Aug 24, 2018

This refactoring moves all logic from MethodCall that is related to invocation matching into a dedicated new type, InvocationShape. This is useful mainly because of two reasons:

  1. The invocation matching becomes more easily testable once it is better isolated.

  2. Verification methods such as mock.Verify(expression) no longer need to instantiate a transient MethodCall (which at its heart really represents a setup) in order to match invocations. They will be able to use the much lighter-weight InvocationShape instead.

This moves all logic from `MethodCall` that is related to invocation
matching into a dedicated new type, `InvocationShape`. This seems use-
ful mainly because of two reasons:

 1. The invocation matching becomes more easily testable once it is
    better isolated.

 2. Verification methods such as `mock.Verify(expression)` no longer
    need to instantiate a transient `MethodCall` (which at its heart
    really represents a setup) in order to match invocations. They
    will be able to use the much lighter-weight `InvocationShape` in-
    stead.
If we want to be able to use `InvocationShape` in verification methods
as well (as described in the previous commit message), it's likely
that this type will have to be able to accept arguments, instead of
argument matchers.

Therefore, extract that logic from `MethodCall` and move it into
`InvocationShape'.
Rewrite the match conditions in such a way that the positive match al-
ways happens at the methods' end; all earlier conditions lead to an
early return and a negative match.

This makes the changed methods somewhat easier to read.
This realises one of the two benefits claimed in an earlier commit
message: verification methods are modified to use `InvocationShape`
instead of newing up transient `MethodCall` instances (which represent
setups and are much heavier-weight).
@stakx stakx added this to the 4.9.1 milestone Aug 24, 2018
@stakx stakx merged commit f852ba2 into devlooped:master Aug 24, 2018
@stakx stakx deleted the invocationshape branch August 24, 2018 21:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant