Assume you have a sealed class hierarchy as follows:
sealed class MyType {
data class Open(val something: String) : MyType()
data class Finish(val reason: String) : MyType()
}
Let's say the production code that I'm verifying against has a method with the following structure:
class MyClass {
fun doStuff(myType: MyType) {
// ...
}
}
So, somewhere in the production code we do this: myClass.doStuff(MyType.Open("something")). Later, in another place, we do this: myClass.doStuff(MyType.Finish("reason")).
In my test, this is the setup I am trying to use for verifying that myClass invoked doStuff() exactly once with the parameter MyType.Finish:
org.mockito.exceptions.verification.TooManyActualInvocations:
myClass.doStuff();
Wanted 1 time:
-> at "location in test method"
But was 2 times:
-> at "location where I call myClass.doStuff(MyType.Open("something"))"
-> at "location where I call myClass.doStuff(MyType.Finish("reason"))"
So, the argumentCaptor specified with the type MyType.Finish captures all invocations where the superclass MyType is used.
Assume you have a sealed class hierarchy as follows:
Let's say the production code that I'm verifying against has a method with the following structure:
So, somewhere in the production code we do this:
myClass.doStuff(MyType.Open("something"))
. Later, in another place, we do this:myClass.doStuff(MyType.Finish("reason"))
.In my test, this is the setup I am trying to use for verifying that
myClass
invokeddoStuff()
exactly once with the parameterMyType.Finish
:The test fails with the following output:
So, the argumentCaptor specified with the type
MyType.Finish
captures all invocations where the superclassMyType
is used.