Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save guilhermekrz/9975ac66ec6e7b6bd5c36e71fc9532e2 to your computer and use it in GitHub Desktop.
Save guilhermekrz/9975ac66ec6e7b6bd5c36e71fc9532e2 to your computer and use it in GitHub Desktop.
@Test
fun `test multiple calls to method which created OkHttpClient`() {
val kotlinFile = kotlin(
"""
package com.brokoli.lint
import okhttp3.OkHttpClient
class MyClass {
fun method1() {
OkHttpClient()
}
fun method2() {
method1()
}
fun method3() {
method1()
}
}
"""
).indented()
val lintResult = lint()
.files(okHttpClientFile, kotlinFile)
.run()
lintResult
.expectWarningCount(2)
.expect("""
src/com/brokoli/lint/MyClass.kt:11: Warning: You should only create one OkHttpClient instance [MoreThanOneOkHttpClientDetector]
fun method2() {
^
src/com/brokoli/lint/MyClass.kt:15: Warning: You should only create one OkHttpClient instance [MoreThanOneOkHttpClientDetector]
fun method3() {
^
0 errors, 2 warnings
""".trimIndent())
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment