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

Changed the answers for collections to return a new instance every time #536

Merged
merged 1 commit into from Nov 27, 2020

Conversation

Raibaz
Copy link
Collaborator

@Raibaz Raibaz commented Nov 26, 2020

This fixes #510.

A change introduced in 1.10.2 added default answers for collections by using the helper listOf(), mapOf()...functions.

However, these all return the same instance of the corresponding collection, so when the AnyValueGenerator was used in creating matchers for recording calls the signature determination was broken: blocks stubbed as

every { doSomething(any(), any()) } just runs

Where both parameters are Lists were being mistakenly matched as doSomething(any(), eq([]).

By making sure that the `AnyValueGenerator´ always returns a new instance of collections, the signatures now take into account different values of the same type and result in proper matchers.

@Raibaz Raibaz requested a review from oleksiyp November 26, 2020 23:19
@oleksiyp
Copy link
Collaborator

Only one concern I might predict - more garbage generated, but believe we need to accept that, and most probably effect going to be minimal.

@codecov-io
Copy link

codecov-io commented Nov 27, 2020

Codecov Report

Merging #536 (734e03c) into master (1466af1) will decrease coverage by 0.08%.
The diff coverage is 86.66%.

Impacted file tree graph

@@             Coverage Diff              @@
##             master     #536      +/-   ##
============================================
- Coverage     72.79%   72.71%   -0.09%     
+ Complexity      777      776       -1     
============================================
  Files            99       99              
  Lines          2764     2763       -1     
  Branches        431      431              
============================================
- Hits           2012     2009       -3     
  Misses          577      577              
- Partials        175      177       +2     
Impacted Files Coverage Δ Complexity Δ
...lin/io/mockk/impl/instantiation/JvmInstantiator.kt 100.00% <ø> (ø) 3.00 <0.00> (-1.00)
...n/io/mockk/impl/instantiation/AnyValueGenerator.kt 92.30% <83.33%> (-3.85%) 24.00 <0.00> (ø)
...o/mockk/impl/instantiation/JvmAnyValueGenerator.kt 79.16% <87.50%> (-4.17%) 15.00 <1.00> (ø)
...m/src/main/kotlin/io/mockk/impl/JvmMockKGateway.kt 89.24% <100.00%> (ø) 24.00 <1.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 1466af1...734e03c. Read the comment docs.

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.

Matching of functions with two arguments of type List fails
3 participants