Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save guilhermekrz/49176fa05ab1e48755e281dda63f43b1 to your computer and use it in GitHub Desktop.
Save guilhermekrz/49176fa05ab1e48755e281dda63f43b1 to your computer and use it in GitHub Desktop.
@Test
fun `two calls to OkHttpClient constructor in different files`() {
val javaFile = java(
"""
package com.brokoli.lint;
import okhttp3.OkHttpClient;
class MyClass {
public void method1() {
new OkHttpClient();
}
}
"""
).indented()
val kotlinFile = kotlin(
"""
package com.brokoli.lint
import okhttp3.OkHttpClient
class MyClass {
fun method1() {
OkHttpClient()
}
}
"""
).indented()
val lintResult = lint()
.files(okHttpClientFile, javaFile, kotlinFile)
.run()
lintResult
.expectWarningCount(2)
.expect("""
src/com/brokoli/lint/MyClass.java:8: Warning: You should only create one OkHttpClient instance [MoreThanOneOkHttpClientDetector]
new OkHttpClient();
~~~~~~~~~~~~~~~~~~
src/com/brokoli/lint/MyClass.kt:8: Warning: You should only create one OkHttpClient instance [MoreThanOneOkHttpClientDetector]
OkHttpClient()
~~~~~~~~~~~~~~
0 errors, 2 warnings
""".trimIndent())
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment