Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/spring-boot/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Spring boot Kotlin模拟弹簧启动测试can';不编译_Spring Boot_Kotlin_Mockito - Fatal编程技术网

Spring boot Kotlin模拟弹簧启动测试can';不编译

Spring boot Kotlin模拟弹簧启动测试can';不编译,spring-boot,kotlin,mockito,Spring Boot,Kotlin,Mockito,所以我有下面的测试 @Test fun `when save claims is called with email saved to that profile` () { //arrange given(profileRepository.findProfileByEmail(anyString())).willAnswer { daoProfile } given(patientRepository.findById(anyInt())

所以我有下面的测试

@Test
    fun `when save claims is called with email saved to that profile` () {
        //arrange
        given(profileRepository.findProfileByEmail(anyString())).willAnswer { daoProfile }
        given(patientRepository.findById(anyInt())).willAnswer { Optional.of(daoPatient) }
        given(claimRepository.saveAll(anyList())).willAnswer { mutableListOf(daoClaim) }

        //act
        val result = claimService.saveClaimsForEmail(listOf(dtoClaim), "Test@test.test")

        //assert
        assert(result != null)
        assert(result?.isNotEmpty() ?: false)
        verify(claimRepository).saveAll(anyList())
    } 
给定(claimRepository.saveAll(anyList()).willAnswer{mutableListOf(daosclaim)}
给出以下错误

e: org.jetbrains.kotlin.codegen.CompilationException: Back-end (JVM) Internal error: Failed to generate expression: KtBlockExpression
File being compiled at position: (217,71) in /Users/archer/Work/masterhealth/master_billing/src/test/kotlin/com/masterhealthsoftware/master_billing/data/service/ClaimServiceTest.kt
The root cause java.lang.IllegalStateException was thrown at: org.jetbrains.kotlin.codegen.state.KotlinTypeMapper$typeMappingConfiguration$1.processErrorType(KotlinTypeMapper.kt:113)
...
Caused by: java.lang.IllegalStateException: Error type encountered: (???..???) (FlexibleTypeImpl).
        at org.jetbrains.kotlin.codegen.state.KotlinTypeMapper$typeMappingConfiguration$1.processErrorType(KotlinTypeMapper.kt:113)
当删除该行时,它会编译,但由于明显的原因测试失败

claimRespoitory在测试类顶部被注释为@MockBean,是一个JpaInterface。第217行是函数的开始。我还尝试使用
when
和其他各种willReturn或willAnswer


知道为什么吗?

我在使用Mockito
Any()时遇到了同样的问题。将其更改为
ArgumentMatchers.any(YourClass::class.java))
解决了编译错误,有一个弃用的
ArgumentMatchers.anyListOf(YourClass::class.java)
可能完成此任务。

这看起来像是kotlin编译器的错误。您是否尝试过报告它和/或使用不同的编译器版本?不,我没有,今天我来看看。我认为我首先做错了什么。你在使用最新的kotlin编译器吗?我用1.3.71试过了。我开始认为这个问题来自于模仿JpaRepository方法。我在repository.findAll上尝试一个模拟,得到了相同的错误,所以它不是任何匹配器。anyList()工作正常。我刚从试图模仿其他东西中发现,模仿JpaRepository方法很麻烦。我有一个findAll(),我试着去嘲笑它,却得到了同样的错误。你能再解释一下吗?。我在模仿
findAll()
findById(ArgumentMatchers.anyLong())
findByLastName(ArgumentMatchers.anyStirng())
,以及答案中提到的那个。使用
JpaRepository
reactivecrudepository
,我没有得到任何编译错误。谢谢!