DrawableUtilTests.kt 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. package com.owncloud.android.utils
  2. import android.content.Context
  3. import android.graphics.Bitmap
  4. import android.graphics.drawable.BitmapDrawable
  5. import androidx.test.platform.app.InstrumentationRegistry
  6. import org.junit.After
  7. import org.junit.Assert.fail
  8. import org.junit.Before
  9. import org.junit.Test
  10. class DrawableUtilTests {
  11. private var sut: DrawableUtil? = null
  12. private var context: Context? = null
  13. @Before
  14. fun setUp() {
  15. sut = DrawableUtil()
  16. context = InstrumentationRegistry.getInstrumentation().context
  17. }
  18. @Test
  19. fun testAddDrawableAsOverlayWhenGivenValidDrawablesShouldContainTwoDrawable() {
  20. val bitmap: Bitmap = Bitmap.createBitmap(10, 10, Bitmap.Config.ARGB_8888)
  21. val drawable = BitmapDrawable(context?.resources, bitmap)
  22. if (context == null) {
  23. fail("context expected to be not null")
  24. }
  25. val layerDrawable = sut?.addDrawableAsOverlay(context!!, drawable, drawable)
  26. if (layerDrawable == null) {
  27. fail("Layer drawable expected to be not null")
  28. }
  29. assert(layerDrawable?.numberOfLayers == 2)
  30. }
  31. @After
  32. fun destroy() {
  33. sut = null
  34. context = null
  35. }
  36. }