【发布时间】:2020-07-13 17:36:10
【问题描述】:
所以我有以下测试
@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())
}
given(claimRepository.saveAll(anyList())).willAnswer { mutableListOf(daoClaim) } 行给出以下错误
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....
知道为什么吗?
【问题讨论】:
-
这看起来像一个 kotlin 编译器错误。您是否尝试过报告它和/或使用不同的编译器版本?
-
不,我没有,我今天会看一下。我以为我首先做错了什么。
-
你在使用最新的 kotlin 编译器吗?
-
我用 1.3.71 试过了
-
我开始认为这个问题来自于模拟 JpaRepository 方法。我正在尝试对 repository.findAll 进行模拟并得到相同的错误
标签: spring-boot kotlin mockito