<commit_before>package com.github.panpf.sketch.test.android

import android.graphics.drawable.BitmapDrawable
import androidx.test.ext.junit.runners.AndroidJUnit4
import com.github.panpf.sketch.test.utils.getTestContext
import org.junit.Assert
import org.junit.Test
import org.junit.runner.RunWith

@RunWith(AndroidJUnit4::class)
class ResourcesTest {

    @Test
    fun test() {
        val context = getTestContext()

        val drawable1 =
            context.resources.getDrawable(android.R.drawable.ic_delete) as BitmapDrawable
        val drawable2 =
            context.resources.getDrawable(android.R.drawable.ic_delete) as BitmapDrawable

        Assert.assertNotSame(drawable1, drawable2)
        Assert.assertSame(drawable1.bitmap, drawable2.bitmap)

        drawable2.bitmap.recycle()
        Assert.assertTrue(drawable1.bitmap.isRecycled)
        val drawable3 =
            context.resources.getDrawable(android.R.drawable.ic_delete) as BitmapDrawable
        Assert.assertTrue(drawable3.bitmap.isRecycled)
    }
}<commit_msg>test: Improve unit test<commit_after>package com.github.panpf.sketch.test.android

import android.graphics.drawable.BitmapDrawable
import androidx.appcompat.content.res.AppCompatResources
import androidx.test.ext.junit.runners.AndroidJUnit4
import com.github.panpf.sketch.test.utils.getTestContext
import org.junit.Assert
import org.junit.Test
import org.junit.runner.RunWith

@RunWith(AndroidJUnit4::class)
class ResourcesTest {

    @Test
    fun testBitmapDrawableBitmap() {
        val context = getTestContext()

        val drawable1 = AppCompatResources.getDrawable(
            context, android.R.drawable.ic_delete,
        ) as BitmapDrawable
        val drawable2 = AppCompatResources.getDrawable(
            context, android.R.drawable.ic_delete,
        ) as BitmapDrawable

        Assert.assertNotSame(drawable1, drawable2)
        Assert.assertSame(drawable1.bitmap, drawable2.bitmap)

        drawable2.bitmap.recycle()
        Assert.assertTrue(drawable1.bitmap.isRecycled)
        val drawable3 = AppCompatResources.getDrawable(
            context, android.R.drawable.ic_delete,
        ) as BitmapDrawable
        Assert.assertTrue(drawable3.bitmap.isRecycled)
    }

    @Test
    fun testBitmapDrawableMutate() {
        val context = getTestContext()

        val drawable1 = AppCompatResources.getDrawable(
            context, android.R.drawable.ic_delete,
        ) as BitmapDrawable
        val drawable2 = AppCompatResources.getDrawable(
            context, android.R.drawable.ic_delete
        ) as BitmapDrawable

        Assert.assertNotSame(drawable1, drawable2)
        Assert.assertNotSame(drawable1.paint, drawable2.paint)
        Assert.assertEquals(255, drawable1.alpha)
        Assert.assertEquals(255, drawable2.alpha)

        val drawable3 = drawable1.mutate() as BitmapDrawable
        Assert.assertSame(drawable1, drawable3)
        Assert.assertSame(drawable1.paint, drawable3.paint)
        Assert.assertEquals(255, drawable3.alpha)

        drawable3.alpha = 100
        Assert.assertEquals(100, drawable1.alpha)
        Assert.assertEquals(255, drawable2.alpha)
        Assert.assertEquals(100, drawable3.alpha)

        val drawable4 = AppCompatResources.getDrawable(
            context, android.R.drawable.ic_delete
        ) as BitmapDrawable
        Assert.assertEquals(255, drawable4.alpha)
    }
}
{'fraction_non_alphanumeric': 0.08426635238656452, 'fraction_numerical': 0.020329994107248086, 'mean_word_length': 3.1452991452991452, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5455167', 'n_tokens_mistral': 1020, 'n_tokens_neox': 988, 'n_words': 157}