|
| 1 | +/* |
| 2 | + * Copyright 2002-2022 the original author or authors. |
| 3 | + * |
| 4 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | + * you may not use this file except in compliance with the License. |
| 6 | + * You may obtain a copy of the License at |
| 7 | + * |
| 8 | + * https://www.apache.org/licenses/LICENSE-2.0 |
| 9 | + * |
| 10 | + * Unless required by applicable law or agreed to in writing, software |
| 11 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | + * See the License for the specific language governing permissions and |
| 14 | + * limitations under the License. |
| 15 | + */ |
| 16 | + |
| 17 | +package org.springframework.aot.hint.support |
| 18 | + |
| 19 | +import org.assertj.core.api.Assertions.assertThat |
| 20 | +import org.assertj.core.api.ThrowingConsumer |
| 21 | +import org.junit.jupiter.api.Test |
| 22 | +import org.springframework.aot.hint.* |
| 23 | + |
| 24 | +/** |
| 25 | + * Tests for Kotlin support in [BindingReflectionHintsRegistrar]. |
| 26 | + * |
| 27 | + * @author Sebastien Deleuze |
| 28 | + */ |
| 29 | +class KotlinBindingReflectionHintsRegistrarTests { |
| 30 | + |
| 31 | + private val bindingRegistrar = BindingReflectionHintsRegistrar() |
| 32 | + |
| 33 | + private val hints = RuntimeHints() |
| 34 | + |
| 35 | + @Test |
| 36 | + fun `Register type for Kotlinx serialization`() { |
| 37 | + bindingRegistrar.registerReflectionHints(hints.reflection(), SampleSerializableClass::class.java) |
| 38 | + assertThat(hints.reflection().typeHints()).satisfiesExactlyInAnyOrder( |
| 39 | + ThrowingConsumer { typeHint: TypeHint -> |
| 40 | + assertThat(typeHint.type).isEqualTo(TypeReference.of(String::class.java)) |
| 41 | + assertThat(typeHint.memberCategories).isEmpty() |
| 42 | + assertThat(typeHint.constructors()).isEmpty() |
| 43 | + assertThat(typeHint.fields()).isEmpty() |
| 44 | + assertThat(typeHint.methods()).isEmpty() |
| 45 | + }, |
| 46 | + ThrowingConsumer { typeHint: TypeHint -> |
| 47 | + assertThat(typeHint.type).isEqualTo(TypeReference.of(SampleSerializableClass::class.java)) |
| 48 | + assertThat(typeHint.methods()).singleElement() |
| 49 | + .satisfies(ThrowingConsumer { methodHint: ExecutableHint -> |
| 50 | + assertThat(methodHint.name).isEqualTo("getName") |
| 51 | + assertThat(methodHint.modes) |
| 52 | + .containsOnly(ExecutableMode.INVOKE) |
| 53 | + }) |
| 54 | + }, |
| 55 | + ThrowingConsumer { typeHint: TypeHint -> |
| 56 | + assertThat(typeHint.type).isEqualTo(TypeReference.of(SampleSerializableClass::class.qualifiedName + "\$Companion")) |
| 57 | + assertThat(typeHint.methods()).singleElement() |
| 58 | + .satisfies(ThrowingConsumer { methodHint: ExecutableHint -> |
| 59 | + assertThat(methodHint.name).isEqualTo("serializer") |
| 60 | + assertThat(methodHint.modes).containsOnly(ExecutableMode.INVOKE) |
| 61 | + }) |
| 62 | + }) |
| 63 | + } |
| 64 | +} |
| 65 | + |
| 66 | +@kotlinx.serialization.Serializable |
| 67 | +class SampleSerializableClass(val name: String) |
0 commit comments