Verifying multiple calls with check function logs assertion error
See original GitHub issueHi,
I’dont now if this is a bug. I’m trying to verify two arguments by using check {}
. Of course I can use an argument capture, but I’m expecting this should working too.
import com.nhaarman.mockitokotlin2.check
import com.nhaarman.mockitokotlin2.mock
import com.nhaarman.mockitokotlin2.verify
import org.assertj.core.api.Assertions.assertThat
import org.junit.jupiter.api.Test
import org.mockito.internal.verification.Times
class Tweet(val id: Int, val text: String)
interface TweetRepository {
fun persist(tweet: Tweet)
}
class TweetTest {
@Test
internal fun `verify multiple perists`() {
val repositoryMock = mock<TweetRepository>()
repositoryMock.persist(Tweet(1, "first tweet"))
repositoryMock.persist(Tweet(2, "second tweet"))
verify(repositoryMock, Times(1)).persist(check {
assertThat(it.id).isEqualTo(1)
assertThat(it.text).isEqualTo("first tweet")
})
verify(repositoryMock, Times(1)).persist(check {
assertThat(it.id).isEqualTo(2)
assertThat(it.text).isEqualTo("second tweet")
})
}
}
is green but logs assertion errors
org.opentest4j.AssertionFailedError:
Expecting:
<2>
to be equal to:
<1>
but was not.
at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
Context
- mockito-kotlin version: 2.2.0
- OS: OSX
- Kotlin version: 1.3.60
- JDK version: 11
- JUnit version: 5.5.2
- AssertJ version: 3.13.2
- Type of test: unit test
Issue Analytics
- State:
- Created 4 years ago
- Comments:7
Top Results From Across the Web
Verifying multiple calls with check function logs assertion error
I'm trying to verify two arguments by using check {} . Of course I can use an argument capture, but I'm expecting this...
Read more >java - How to verify multiple method calls with different params
OP's test case calls methodToTest() once. It is the method argument ActionErrors errors is internally called twice. – Brad. Jun 5, 2019 at...
Read more >How to View Multiple JUnit Assertion Errors in One Test ...
Learn an easy solution to view all of the JUnit Assertion errors in one test execution from the test automation professionals at tapQA!...
Read more >Verifying interactions | testdouble.js - GitHub Pages
First, because the API for verifying invocations of test double functions is essentially identical to the API for stubbing responses, so if you're...
Read more >20.2. Checking Assumptions With assert - Runestone Academy
Many functions work correctly only for certain parameter values, ... The second call to sumnums(3, 1) causes the assert to fail and an...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@larmic You should take a look at this.
@larmic Or create your own
TweetMatcher
.But
eq()
is the easiest.