0

我无法在 Kotlin 中使用 captor 参数。

服务等级:

class ClassService(private val clientFeign: ClientFeign) {

    fun startIntegration() {
        val object: ObjectVO = createObject()
        val objectCreated = clientFeign.createObject(object)
        return objectCreated
    }
}

测试类别:

import io.mockk.impl.annotations.MockK
import io.mockk.junit5.MockKExtension
import com.nhaarman.mockitokotlin2.argumentCaptor
import org.junit.jupiter.api.DisplayName
import org.junit.jupiter.api.Test
import org.junit.jupiter.api.extension.ExtendWith

@ExtendWith(MockKExtension::class)
@DisplayName("Test")
class ServiceTest {
    @MockK
    private lateinit var clientFeign: ClientFeign
    
    private lateinit var classService: ClassService

    @Test
    fun `should create client`() {
         val obejctVO = ObjectVO(.....)
         
         every { clientFeign.createObject(any()) } 
         returns objectVO
  
         classService.startIntegration()
  
         var objectCaptor = com.nhaarman.mockitokotlin2.argumentCaptor<ObjectVO()

         verify(exactly = 1) {
           clientFeign.createObject(
             objectCaptor.capture(),
           )
         }
     }
}
    

我遇到以下错误:

java.lang.AssertionError:验证失败:调用 1 of 1:ClientFeign(clientFeign#6).createClient(null()))。只发生了一次对 ClientFeign(clientFeign#6)/createClient(objectVO) 的匹配调用,但参数不匹配:[0]:参数:ObjectVO(id=null, name=TESTE, poEmail=teste@gmail.com, displayName=测试,数字=4),匹配器:null(),结果:

我不明白为什么这些论点不匹配。

4

0 回答 0