<commit_before>package fr.free.nrw.commons.profile.achievements

import android.content.Context
import android.graphics.Bitmap
import android.view.MenuItem
import androidx.fragment.app.FragmentManager
import androidx.fragment.app.FragmentTransaction
import fr.free.nrw.commons.TestAppAdapter
import fr.free.nrw.commons.TestCommonsApplication
import fr.free.nrw.commons.profile.ProfileActivity
import org.junit.Assert
import org.junit.Before
import org.junit.Test
import org.junit.runner.RunWith
import org.mockito.Mock
import org.mockito.MockitoAnnotations
import org.robolectric.Robolectric
import org.robolectric.RobolectricTestRunner
import org.robolectric.RuntimeEnvironment
import org.robolectric.annotation.Config
import org.robolectric.fakes.RoboMenuItem
import org.wikipedia.AppAdapter


@RunWith(RobolectricTestRunner::class)
@Config(sdk = [21], application = TestCommonsApplication::class)
class AchievementsFragmentUnitTests {

    private lateinit var fragment: AchievementsFragment

    private lateinit var context: Context

    private lateinit var menuItem: MenuItem

    @Mock
    private lateinit var bitmap: Bitmap

    @Before
    fun setUp() {
        MockitoAnnotations.initMocks(this)
        context = RuntimeEnvironment.application.applicationContext
        menuItem = RoboMenuItem(context)
        AppAdapter.set(TestAppAdapter())
        val activity = Robolectric.buildActivity(ProfileActivity::class.java).create().get()
        fragment = AchievementsFragment()
        val fragmentManager: FragmentManager = activity.supportFragmentManager
        val fragmentTransaction: FragmentTransaction = fragmentManager.beginTransaction()
        fragmentTransaction.add(fragment, null)
        fragmentTransaction.commit()

    }

    @Test
    @Throws(Exception::class)
    fun checkFragmentNotNull() {
        Assert.assertNotNull(fragment)
    }

    @Test
    @Throws(Exception::class)
    fun testShowAlert() {
        fragment.showAlert(bitmap)
    }


    @Test
    @Throws(Exception::class)
    fun testShowInfoDialog() {
        fragment.showInfoDialog()
    }

    @Test
    @Throws(Exception::class)
    fun testShowUploadInfo() {
        fragment.showUploadInfo()
    }

    @Test
    @Throws(Exception::class)
    fun testShowRevertedInfo() {
        fragment.showRevertedInfo()
    }

    @Test
    @Throws(Exception::class)
    fun testShowUsedByWikiInfo() {
        fragment.showUsedByWikiInfo()
    }

    @Test
    @Throws(Exception::class)
    fun testShowImagesViaNearbyInfo() {
        fragment.showImagesViaNearbyInfo()
    }

    @Test
    @Throws(Exception::class)
    fun testShowFeaturedImagesInfo() {
        fragment.showFeaturedImagesInfo()
    }

    @Test
    @Throws(Exception::class)
    fun testShowThanksReceivedInfo() {
        fragment.showThanksReceivedInfo()
    }

    @Test
    @Throws(Exception::class)
    fun testShowQualityImagesInfo() {
        fragment.showQualityImagesInfo()
    }

    @Test
    @Throws(Exception::class)
    fun testOnOptionsItemSelected() {
        fragment.onOptionsItemSelected(menuItem)
    }

}<commit_msg>Add few more unit tests for AchievementsFragment (#4272)<commit_after>package fr.free.nrw.commons.profile.achievements

import android.content.Context
import android.graphics.Bitmap
import android.view.MenuItem
import android.widget.ImageView
import android.widget.ProgressBar
import android.widget.TextView
import androidx.fragment.app.FragmentManager
import androidx.fragment.app.FragmentTransaction
import com.dinuscxj.progressbar.CircleProgressBar
import fr.free.nrw.commons.TestAppAdapter
import fr.free.nrw.commons.TestCommonsApplication
import fr.free.nrw.commons.profile.ProfileActivity
import org.junit.Assert
import org.junit.Before
import org.junit.Test
import org.junit.runner.RunWith
import org.mockito.Mock
import org.mockito.MockitoAnnotations
import org.powermock.reflect.Whitebox
import org.robolectric.Robolectric
import org.robolectric.RobolectricTestRunner
import org.robolectric.RuntimeEnvironment
import org.robolectric.annotation.Config
import org.robolectric.fakes.RoboMenuItem
import org.wikipedia.AppAdapter
import java.lang.reflect.Method


@RunWith(RobolectricTestRunner::class)
@Config(sdk = [21], application = TestCommonsApplication::class)
class AchievementsFragmentUnitTests {

    private lateinit var fragment: AchievementsFragment

    private lateinit var context: Context

    private lateinit var menuItem: MenuItem

    private lateinit var achievements: Achievements

    @Mock
    private lateinit var imageView: ImageView

    @Mock
    private lateinit var badgeText: TextView

    @Mock
    private lateinit var levelNumber: TextView

    @Mock
    private lateinit var thanksReceived: TextView

    @Mock
    private lateinit var imagesUploadedProgressbar: CircleProgressBar

    @Mock
    private lateinit var imagesUsedByWikiProgressBar: CircleProgressBar

    @Mock
    private lateinit var imageRevertsProgressbar: CircleProgressBar

    @Mock
    private lateinit var imagesFeatured: TextView

    @Mock
    private lateinit var tvQualityImages: TextView

    @Mock
    private lateinit var imagesRevertLimitText: TextView

    @Mock
    private lateinit var imageByWikiText: TextView

    @Mock
    private lateinit var imageRevertedText: TextView

    @Mock
    private lateinit var imageUploadedText: TextView

    @Mock
    private lateinit var bitmap: Bitmap

    @Mock
    private lateinit var progressBar: ProgressBar

    @Before
    fun setUp() {
        MockitoAnnotations.initMocks(this)
        context = RuntimeEnvironment.application.applicationContext
        menuItem = RoboMenuItem(context)
        AppAdapter.set(TestAppAdapter())
        val activity = Robolectric.buildActivity(ProfileActivity::class.java).create().get()
        fragment = AchievementsFragment()
        val fragmentManager: FragmentManager = activity.supportFragmentManager
        val fragmentTransaction: FragmentTransaction = fragmentManager.beginTransaction()
        fragmentTransaction.add(fragment, null)
        fragmentTransaction.commit()

        achievements = Achievements(0, 0, 0, 0, 0, 0, 0)

        Whitebox.setInternalState(fragment, "thanksReceived", thanksReceived)
        Whitebox.setInternalState(
            fragment,
            "imagesUsedByWikiProgressBar",
            imagesUsedByWikiProgressBar
        )
        Whitebox.setInternalState(
            fragment,
            "imagesUsedByWikiProgressBar",
            imagesUsedByWikiProgressBar
        )
        Whitebox.setInternalState(fragment, "imagesFeatured", imagesFeatured)
        Whitebox.setInternalState(fragment, "tvQualityImages", tvQualityImages)
        Whitebox.setInternalState(fragment, "levelNumber", levelNumber)
        Whitebox.setInternalState(fragment, "imageView", imageView)
        Whitebox.setInternalState(fragment, "badgeText", badgeText)
        Whitebox.setInternalState(fragment, "imagesUploadedProgressbar", imagesUploadedProgressbar)
        Whitebox.setInternalState(fragment, "imageRevertsProgressbar", imageRevertsProgressbar)
        Whitebox.setInternalState(
            fragment,
            "imagesUsedByWikiProgressBar",
            imagesUsedByWikiProgressBar
        )
        Whitebox.setInternalState(fragment, "imageView", imageView)
        Whitebox.setInternalState(fragment, "imageByWikiText", imageByWikiText)
        Whitebox.setInternalState(fragment, "imageRevertedText", imageRevertedText)
        Whitebox.setInternalState(fragment, "imageUploadedText", imageUploadedText)
        Whitebox.setInternalState(fragment, "imageView", imageView)
        Whitebox.setInternalState(fragment, "progressBar", progressBar)
        Whitebox.setInternalState(fragment, "imagesRevertLimitText", imagesRevertLimitText)
        Whitebox.setInternalState(fragment, "item", menuItem)
    }

    @Test
    @Throws(Exception::class)
    fun checkFragmentNotNull() {
        Assert.assertNotNull(fragment)
    }

    @Test
    @Throws(Exception::class)
    fun testShowAlert() {
        fragment.showAlert(bitmap)
    }


    @Test
    @Throws(Exception::class)
    fun testShowInfoDialog() {
        fragment.showInfoDialog()
    }

    @Test
    @Throws(Exception::class)
    fun testShowUploadInfo() {
        fragment.showUploadInfo()
    }

    @Test
    @Throws(Exception::class)
    fun testShowRevertedInfo() {
        fragment.showRevertedInfo()
    }

    @Test
    @Throws(Exception::class)
    fun testShowUsedByWikiInfo() {
        fragment.showUsedByWikiInfo()
    }

    @Test
    @Throws(Exception::class)
    fun testShowImagesViaNearbyInfo() {
        fragment.showImagesViaNearbyInfo()
    }

    @Test
    @Throws(Exception::class)
    fun testShowFeaturedImagesInfo() {
        fragment.showFeaturedImagesInfo()
    }

    @Test
    @Throws(Exception::class)
    fun testShowThanksReceivedInfo() {
        fragment.showThanksReceivedInfo()
    }

    @Test
    @Throws(Exception::class)
    fun testShowQualityImagesInfo() {
        fragment.showQualityImagesInfo()
    }

    @Test
    @Throws(Exception::class)
    fun testOnOptionsItemSelected() {
        fragment.onOptionsItemSelected(menuItem)
    }

    @Test
    @Throws(Exception::class)
    fun testLaunchAlert() {
        val method: Method = AchievementsFragment::class.java.getDeclaredMethod(
            "launchAlert",
            String::class.java,
            String::class.java
        )
        method.isAccessible = true
        method.invoke(fragment, "", "")
    }

    @Test
    @Throws(Exception::class)
    fun testHideProgressBar() {
        val method: Method = AchievementsFragment::class.java.getDeclaredMethod(
            "hideProgressBar",
            Achievements::class.java
        )
        method.isAccessible = true
        method.invoke(fragment, achievements)
    }

    @Test
    @Throws(Exception::class)
    fun testSetAchievementsUploadCount() {
        val method: Method = AchievementsFragment::class.java.getDeclaredMethod(
            "setAchievementsUploadCount",
            Achievements::class.java,
            Int::class.java
        )
        method.isAccessible = true
        method.invoke(fragment, achievements, 0)
    }

    @Test
    @Throws(Exception::class)
    fun testCheckAccount() {
        val method: Method = AchievementsFragment::class.java.getDeclaredMethod(
            "checkAccount"
        )
        method.isAccessible = true
        method.invoke(fragment)
    }

    @Test
    @Throws(Exception::class)
    fun testSetUploadCount() {
        val method: Method = AchievementsFragment::class.java.getDeclaredMethod(
            "setUploadCount",
            Achievements::class.java
        )
        method.isAccessible = true
        method.invoke(fragment, achievements)
    }

    @Test
    @Throws(Exception::class)
    fun testOnError() {
        val method: Method = AchievementsFragment::class.java.getDeclaredMethod(
            "onError"
        )
        method.isAccessible = true
        method.invoke(fragment)
    }

    @Test
    @Throws(Exception::class)
    fun testShowSnackBarWithRetryTrue() {
        val method: Method = AchievementsFragment::class.java.getDeclaredMethod(
            "showSnackBarWithRetry", Boolean::class.java
        )
        method.isAccessible = true
        method.invoke(fragment, true)
    }

    @Test
    @Throws(Exception::class)
    fun testShowSnackBarWithRetryFalse() {
        val method: Method = AchievementsFragment::class.java.getDeclaredMethod(
            "showSnackBarWithRetry", Boolean::class.java
        )
        method.isAccessible = true
        method.invoke(fragment, false)
    }

    @Test
    @Throws(Exception::class)
    fun testSetWikidataEditCount() {
        val method: Method = AchievementsFragment::class.java.getDeclaredMethod(
            "setWikidataEditCount"
        )
        method.isAccessible = true
        method.invoke(fragment)
    }

    @Test
    @Throws(Exception::class)
    fun testSetAchievements() {
        val method: Method = AchievementsFragment::class.java.getDeclaredMethod(
            "setAchievements"
        )
        method.isAccessible = true
        method.invoke(fragment)
    }

    @Test
    @Throws(Exception::class)
    fun testShareScreen() {
        val method: Method = AchievementsFragment::class.java.getDeclaredMethod(
            "shareScreen", Bitmap::class.java
        )
        method.isAccessible = true
        method.invoke(fragment, bitmap)
    }

}
{'fraction_non_alphanumeric': 0.08506041449947987, 'fraction_numerical': 0.001280307273745699, 'mean_word_length': 3.2194463200540175, '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': '6207577', 'n_tokens_mistral': 3567, 'n_tokens_neox': 3434, 'n_words': 624}