Функция расширения Котлина велика. Но как я могу выполнить unit test на них? Особенно те, что относятся к Android SDK, предоставляют класс (например, Context, Dialog).
Я приведу два примера ниже, и если бы кто-нибудь мог поделиться, как я мог unit test их, или мне нужно написать их по-другому, если я действительно хочу их unit test.
fun Context.getColorById(colorId: Int): Int {
if (Build.VERSION.SDK_INT >= 23)
return ContextCompat.getColor(this, colorId)
else return resources.getColor(colorId)
}
и
fun Dialog.setupErrorDialog(body : String, onOkFunc: () -> Unit = {}): Dialog {
window.requestFeature(Window.FEATURE_NO_TITLE)
this.setContentView(R.layout.dialog_error_layout)
(findViewById(R.id.txt_body) as TextView).text = body
(findViewById(R.id.txt_header) as TextView).text = context.getString(R.string.dialog_title_error)
(findViewById(R.id.txt_okay)).setOnClickListener{
onOkFunc()
dismiss()
}
return this
}
Любое предложение поможет. Спасибо!