Skip to content

Instantly share code, notes, and snippets.

@cmathew
Created September 12, 2023 17:19
Show Gist options
  • Save cmathew/dcc2a2681ca59dcfc941f609c1331351 to your computer and use it in GitHub Desktop.
Save cmathew/dcc2a2681ca59dcfc941f609c1331351 to your computer and use it in GitHub Desktop.
Example of providing a stubbed dependency to an Android Lint unit test
// Define Joda-Time stub
val JODA_STUB = TestFiles.kotlin(
"""
package org.joda.time
class DateTime(
private val moment: Int,
private val zone: String
) {
companion object {
fun now(): DateTime {
return DateTime(1000, "America/Los_Angeles")
}
}
fun toLocalDate(): LocalDate {
return LocalDate(2020, 11, 23)
}
fun toLocalDateTime(): LocalDateTime {
return LocalDate(2020, 11, 23)
}
}
data class LocalDate(
private val year: Int,
private val month: Int,
private val day: Int
)
data class LocalDateTime(
private val moment: Int
)
""",
).indented()
// Use Joda-Time stub
lint().files(JODA_STUB, ...)...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment