Galera, creiei um fun extension, que recebe um parametro, depedendo do valor ele irá setar uma cor e icone, meus testes ficaram assim:\
Quando executo o test quebra no setup, na linha onde inicializo a imageView.
Estou em duvida também se a forma como estou avaliando o drawable está correto.
assertThat(imageView.drawable, equalTo(ContextCompat.getDrawable(context, R.drawable.ic_arrow_downward_black_16dp)))
class AppCompatImageViewExtensionTest {
private lateinit var context: Context
private lateinit var imageView: AppCompatImageView
@Before
fun setup() {
context = ApplicationProvider.getApplicationContext<Context>()
imageView = AppCompatImageView(context)
}
@Test
@SmallTest
fun `test setIcon extension function with value containing "-"`() {
val value = "example-1"
imageView.setIcon(value, context)
assertThat(imageView.drawable, equalTo(ContextCompat.getDrawable(context, R.drawable.ic_arrow_downward_black_16dp)))
assertThat(imageView.imageTintList?.defaultColor, equalTo(ContextCompat.getColor(context, R.color.orangeDark)))
}
@Test
@SmallTest
fun `test setIcon extension function with value not containing "-"`() {
val value = "example"
imageView.setIcon(value, context)
assertThat(imageView.drawable, equalTo(ContextCompat.getDrawable(context, R.drawable.ic_arrow_upward_black_16dp)))
assertThat(imageView.imageTintList?.defaultColor, equalTo(ContextCompat.getColor(context, R.color.greenCitricDarkest)))
}
}