lundi 24 octobre 2016

getAnnotation for Java annotation used on Kotlin method returns null

Say, I have the following interface:

interface AppRepository : GraphRepository<App> {

    @Query("""MATCH (a:App) RETURN a""")
    fun findAll(): List<App>
}

In a test I want to check specifics of the query string and therefore I do

open class AppRepositoryTest {

    lateinit @Autowired var appRepository: AppRepository

    @Test
    open fun checkQuery() {
        val productionMethod = appRepository.javaClass.getDeclaredMethod("findAll")
        val productionQuery = productionMethod!!.getAnnotation(Query::class.java)

        //demo test
        assertThat(productionQuery!!.value).isNotEmpty() //KotlinNPE
    }
}

For a reason I don't comprehend, productionQuery is nnull. I have double checked that the types of the imported Query in the test class and the Query in the repository are the same.

Thus, why is the productionQuery null in this case?





Aucun commentaire:

Enregistrer un commentaire