DrawableUtilTests.kt 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. /*
  2. * Nextcloud Android Library is available under MIT license
  3. * @author Alper Öztürk
  4. * Copyright (C) 2023 Alper Öztürk
  5. * Copyright (C) 2023 Nextcloud GmbH
  6. *
  7. * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
  8. *
  9. * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
  10. *
  11. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  12. * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  13. * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  14. * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
  15. * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
  16. * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
  17. * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  18. * THE SOFTWARE.
  19. */
  20. package com.owncloud.android.utils
  21. import android.content.Context
  22. import android.graphics.Bitmap
  23. import android.graphics.drawable.BitmapDrawable
  24. import androidx.test.platform.app.InstrumentationRegistry
  25. import org.junit.After
  26. import org.junit.Assert.fail
  27. import org.junit.Before
  28. import org.junit.Test
  29. class DrawableUtilTests {
  30. private var sut: DrawableUtil? = null
  31. private var context: Context? = null
  32. @Before
  33. fun setUp() {
  34. sut = DrawableUtil()
  35. context = InstrumentationRegistry.getInstrumentation().context
  36. }
  37. @Test
  38. fun testAddDrawableAsOverlayWhenGivenValidDrawablesShouldContainTwoDrawable() {
  39. val bitmapSize = 10
  40. val bitmap: Bitmap = Bitmap.createBitmap(bitmapSize, bitmapSize, 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. }