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

Implemented mocking constructors with parameters #583

Merged
merged 2 commits into from Mar 16, 2021

Conversation

Raibaz
Copy link
Collaborator

@Raibaz Raibaz commented Mar 11, 2021

This takes over from @oleksiyp 's implementation in #267 to provide a working implementation of #209.

The main difference with the original implementation is fixing a bug with handler matching that prevented calls like

verify {
        constructedWith<MockCls>(EqMatcher(6)).op(1, 2) 
}

from working.

Basically, the handlers map in ConstructorMockVariety was using an Array as the key, and comparing arrays compares their references rather than comparing their content.

This means that getting an existing handler was always failing, because the equals call between argument arrays was always returning false: this in turn meant that verification was failing because when retrieving the mock to run verification against the retrieval failed and the verification was being run against a "clean" mock, with no recorded calls.

By using a List rather than an array, retrieving existing mocks works as expected and verification is performed against the proper mock.

@codecov-io
Copy link

Codecov Report

Merging #583 (6fc7e93) into master (a927224) will increase coverage by 0.31%.
The diff coverage is 78.94%.

❗ Current head 6fc7e93 differs from pull request most recent head 12d3c3b. Consider uploading reports for the commit 12d3c3b to get more accurate results
Impacted file tree graph

@@             Coverage Diff              @@
##             master     #583      +/-   ##
============================================
+ Coverage     75.57%   75.89%   +0.31%     
- Complexity      816      817       +1     
============================================
  Files           100      100              
  Lines          2788     2825      +37     
  Branches        435      445      +10     
============================================
+ Hits           2107     2144      +37     
  Misses          502      502              
  Partials        179      179              
Impacted Files Coverage Δ Complexity Δ
dsl/common/src/main/kotlin/io/mockk/API.kt 0.00% <ø> (ø) 0.00 <0.00> (ø)
...lin/io/mockk/impl/platform/JvmWeakConcurrentMap.kt 56.00% <ø> (+8.00%) 7.00 <0.00> (ø)
...kk/impl/instantiation/JvmConstructorMockFactory.kt 79.03% <76.47%> (+4.03%) 16.00 <5.00> (+1.00)
...otlin/io/mockk/impl/eval/RecordedBlockEvaluator.kt 95.12% <100.00%> (+0.12%) 7.00 <0.00> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update a927224...12d3c3b. Read the comment docs.

@Raibaz Raibaz merged commit f5d062a into master Mar 16, 2021
This was referenced Mar 17, 2021
This was referenced Mar 17, 2021
@Raibaz Raibaz deleted the constructor-mocking-with-params branch April 7, 2021 13:55
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

2 participants