aboutsummaryrefslogtreecommitdiff
path: root/plugins/base/src/test/kotlin/locationProvider/AndroidExternalLocationProviderTest.kt
blob: ea2c434f10cb5dd30923b9279677a39f26fb71a0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
package locationProvider

import org.jetbrains.dokka.base.resolvers.external.DefaultExternalLocationProvider
import org.jetbrains.dokka.base.resolvers.external.javadoc.AndroidExternalLocationProvider
import org.jetbrains.dokka.base.resolvers.shared.ExternalDocumentation
import org.jetbrains.dokka.base.resolvers.shared.PackageList
import org.jetbrains.dokka.base.resolvers.shared.RecognizedLinkFormat
import org.jetbrains.dokka.links.Callable
import org.jetbrains.dokka.links.DRI
import org.jetbrains.dokka.links.TypeConstructor
import org.jetbrains.dokka.plugability.DokkaContext
import org.jetbrains.dokka.testApi.testRunner.AbstractCoreTest
import org.junit.jupiter.api.Assertions.assertEquals
import org.junit.jupiter.api.Test
import java.net.URL

class AndroidExternalLocationProviderTest : AbstractCoreTest() {
    private val android = ExternalDocumentation(
        URL("https://developer.android.com/reference/kotlin"),
        PackageList(
            RecognizedLinkFormat.DokkaHtml,
            setOf("android.content", "android.net"),
            emptyMap(),
            URL("file://not-used")
        )
    )
    private val androidx = ExternalDocumentation(
        URL("https://developer.android.com/reference/kotlin"),
        PackageList(
            RecognizedLinkFormat.DokkaHtml,
            setOf("androidx.appcompat.app"),
            emptyMap(),
            URL("file://not-used")
        )
    )
    private val configuration = dokkaConfiguration {
        sourceSets {
            sourceSet {
                sourceRoots = listOf("src/")
                classpath += jvmStdlibPath!!
            }
        }
    }

    private fun getTestLocationProvider(
        externalDocumentation: ExternalDocumentation,
        context: DokkaContext? = null
    ): DefaultExternalLocationProvider {
        val dokkaContext = context ?: DokkaContext.create(configuration, logger, emptyList())
        return AndroidExternalLocationProvider(externalDocumentation, dokkaContext)
    }

    @Test
    fun `#1230 anchor to a method from AndroidX`() {
        val locationProvider = getTestLocationProvider(androidx)
        val dri = DRI(
            "androidx.appcompat.app",
            "AppCompatActivity",
            Callable("findViewById", null, listOf(TypeConstructor("kotlin.Int", emptyList())))
        )

        assertEquals(
            "${androidx.documentationURL}/androidx/appcompat/app/AppCompatActivity.html#findviewbyid",
            locationProvider.resolve(dri)
        )
    }

    @Test
    fun `anchor to a method from Android`() {
        val locationProvider = getTestLocationProvider(android)
        val dri = DRI(
            "android.content",
            "ContextWrapper",
            Callable(
                "checkCallingUriPermission",
                null,
                listOf(
                    TypeConstructor("android.net.Uri", emptyList()),
                    TypeConstructor("kotlin.Int", emptyList())
                )
            )
        )

        assertEquals(
            "${android.documentationURL}/android/content/ContextWrapper.html#checkcallinguripermission",
            locationProvider.resolve(dri)
        )
    }
}