DrawableUtilTests.kt 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. /*
  2. * Nextcloud Android client application
  3. *
  4. * @author Alper Ozturk
  5. * Copyright (C) 2023 Alper Ozturk
  6. * Copyright (C) 2023 Nextcloud GmbH
  7. *
  8. * This program is free software: you can redistribute it and/or modify
  9. * it under the terms of the GNU Affero General Public License as published by
  10. * the Free Software Foundation, either version 3 of the License, or
  11. * (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU Affero General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU Affero General Public License
  19. * along with this program. If not, see <https://www.gnu.org/licenses/>.
  20. */
  21. package com.owncloud.android.utils
  22. import android.content.Context
  23. import android.graphics.Bitmap
  24. import android.graphics.drawable.BitmapDrawable
  25. import androidx.test.platform.app.InstrumentationRegistry
  26. import org.junit.After
  27. import org.junit.Assert.fail
  28. import org.junit.Before
  29. import org.junit.Test
  30. class DrawableUtilTests {
  31. private var sut: DrawableUtil? = null
  32. private var context: Context? = null
  33. @Before
  34. fun setUp() {
  35. sut = DrawableUtil()
  36. context = InstrumentationRegistry.getInstrumentation().context
  37. }
  38. @Test
  39. fun testAddDrawableAsOverlayWhenGivenValidDrawablesShouldContainTwoDrawable() {
  40. val bitmap: Bitmap = Bitmap.createBitmap(2, 2, Bitmap.Config.ARGB_8888)
  41. val drawable = BitmapDrawable(context?.resources, bitmap)
  42. val layerDrawable = sut?.addDrawableAsOverlay(drawable, drawable)
  43. if (layerDrawable == null) {
  44. fail("Layer drawable expected to be not null")
  45. }
  46. assert(layerDrawable?.numberOfLayers == 2)
  47. }
  48. @After
  49. fun destroy() {
  50. sut = null
  51. context = null
  52. }
  53. }