Move BindingReflectionHintsRegistrar to spring-core

See gh-28979
This commit is contained in:
Sébastien Deleuze
2022-09-01 17:59:43 +02:00
parent 6475523a53
commit aaffb8b27e
7 changed files with 11 additions and 11 deletions

View File

@@ -1,66 +0,0 @@
/*
* Copyright 2002-2022 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.context.aot
import org.assertj.core.api.Assertions.assertThat
import org.assertj.core.api.ThrowingConsumer
import org.junit.jupiter.api.Test
import org.springframework.aot.hint.*
/**
* Tests for Kotlin support in [BindingReflectionHintsRegistrar].
*
* @author Sebastien Deleuze
*/
class KotlinBindingReflectionHintsRegistrarTests {
private val bindingRegistrar = BindingReflectionHintsRegistrar()
private val hints = RuntimeHints()
@Test
fun `Register type for Kotlinx serialization`() {
bindingRegistrar.registerReflectionHints(hints.reflection(), SampleSerializableClass::class.java)
assertThat(hints.reflection().typeHints()).satisfiesExactlyInAnyOrder(
ThrowingConsumer { typeHint: TypeHint ->
assertThat(typeHint.type).isEqualTo(TypeReference.of(String::class.java))
assertThat(typeHint.memberCategories).isEmpty()
assertThat(typeHint.constructors()).isEmpty()
assertThat(typeHint.fields()).isEmpty()
assertThat(typeHint.methods()).isEmpty()
},
ThrowingConsumer { typeHint: TypeHint ->
assertThat(typeHint.type).isEqualTo(TypeReference.of(SampleSerializableClass::class.java))
assertThat(typeHint.methods()).singleElement()
.satisfies(ThrowingConsumer { methodHint: ExecutableHint ->
assertThat(methodHint.name).isEqualTo("getName")
assertThat(methodHint.mode).isEqualTo(ExecutableMode.INVOKE)
})
},
ThrowingConsumer { typeHint: TypeHint ->
assertThat(typeHint.type).isEqualTo(TypeReference.of(SampleSerializableClass::class.qualifiedName + "\$Companion"))
assertThat(typeHint.methods()).singleElement()
.satisfies(ThrowingConsumer { methodHint: ExecutableHint ->
assertThat(methodHint.name).isEqualTo("serializer")
assertThat(methodHint.mode).isEqualTo(ExecutableMode.INVOKE)
})
})
}
}
@kotlinx.serialization.Serializable
class SampleSerializableClass(val name: String)