https://kotlinlang.org logo
#mockk
Title
# mockk
q

quiqua

08/20/2018, 9:58 AM
Is it possible to create a
spyk
on a:
Copy code
object GeometryValidation {

    fun isPoint(coordinates: Position): ValidationResult = coordinates.validate()
    fun isLineString(coordinates: List<Position>): ValidationResult {
       coordinates.forEach { isPoint(it) }
       ....
    }
    private fun ...
}
and then verify that
isPoint
has been called when calling
isLineString
?
my test doesn’t approve so:
Copy code
it("Calls .isPoint for each coordinate in the linestring") {
                val coordinates = listOf(
                    Position(longitude = 1.0, latitude = 1.0),
                    Position(longitude = 2.0, latitude = 2.0),
                    Position(longitude = 3.0, latitude = 3.0)
                )
                val mock = spyk(GeometryValidation)
                mock.isLineString(coordinates)

                verify(exactly = 3) { mock.isPoint(any()) }
            }
Copy code
Verification failed: call 1 of 1: GeometryValidation(#1).isPoint(any())) was not called.

Calls to same mock:
1) GeometryValidation(#1).isLineString([Position(longitude=1.0, latitude=1.0, altitude=null), Position(longitude=2.0, latitude=2.0, altitude=null), Position(longitude=3.0, latitude=3.0, altitude=null)])
...
java.lang.AssertionError: Verification failed: call 1 of 1: GeometryValidation(#1).isPoint(any())) was not called.
o

oleksiyp

08/20/2018, 11:42 AM
Actually it should work. Can you create a ticket please in Github issues
o

oleksiyp

08/20/2018, 2:55 PM
thanks!
5 Views