Skip to content

Instantly share code, notes, and snippets.

@Audhil
Last active July 6, 2020 17:57
Show Gist options
  • Save Audhil/997b4f9cf69b7f5d6490981dd6a50c2b to your computer and use it in GitHub Desktop.
Save Audhil/997b4f9cf69b7f5d6490981dd6a50c2b to your computer and use it in GitHub Desktop.
util - to read fake json response from src code for Instrumentation test cases. for eg., fake response in MockWebServer
object FileReader {
fun readStringFromFile(fileName: String): String {
try {
val inputStream =
(InstrumentationRegistry.getInstrumentation().targetContext.applicationContext as HiltTestApplication).assets.open(
fileName
)
val builder = StringBuilder()
val reader = InputStreamReader(inputStream, "UTF-8")
reader.readLines().forEach {
builder.append(it)
}
return builder.toString()
} catch (e: IOException) {
throw e
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment