Skip to content

Commit

Permalink
fix CI
Browse files Browse the repository at this point in the history
Signed-off-by: parneet-guraya <[email protected]>
  • Loading branch information
parneet-guraya committed Dec 7, 2024
1 parent d1b0b4d commit 8c851ba
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import fr.free.nrw.commons.customselector.ui.selector.ImageLoader
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.ExperimentalCoroutinesApi
import kotlinx.coroutines.runBlocking
import kotlinx.coroutines.test.TestCoroutineDispatcher
import kotlinx.coroutines.test.StandardTestDispatcher
import kotlinx.coroutines.test.resetMain
import kotlinx.coroutines.test.setMain
import org.junit.After
Expand All @@ -34,7 +34,6 @@ import org.robolectric.RobolectricTestRunner
import org.robolectric.annotation.Config
import java.lang.reflect.Field
import java.util.TreeMap
import kotlin.collections.ArrayList

/**
* Custom Selector image adapter test.
Expand Down Expand Up @@ -65,7 +64,7 @@ class ImageAdapterTest {
private lateinit var selectedImageField: Field
private var uri: Uri = Mockito.mock(Uri::class.java)
private lateinit var image: Image
private val testDispatcher = TestCoroutineDispatcher()
private val testDispatcher = StandardTestDispatcher()

/**
* Set up variables.
Expand All @@ -91,7 +90,6 @@ class ImageAdapterTest {
@After
fun tearDown() {
Dispatchers.resetMain()
testDispatcher.cleanupTestCoroutines()
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,10 @@ import fr.free.nrw.commons.upload.FileUtilsWrapper
import io.reactivex.Single
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.ExperimentalCoroutinesApi
import kotlinx.coroutines.test.TestCoroutineDispatcher
import kotlinx.coroutines.test.StandardTestDispatcher
import kotlinx.coroutines.test.TestScope
import kotlinx.coroutines.test.resetMain
import kotlinx.coroutines.test.runBlockingTest
import kotlinx.coroutines.test.runTest
import kotlinx.coroutines.test.setMain
import org.junit.After
import org.junit.Assert
Expand All @@ -45,7 +46,6 @@ import java.io.File
import java.io.FileInputStream
import java.util.Calendar
import java.util.Date
import kotlin.collections.HashMap

/**
* Image Loader Test.
Expand Down Expand Up @@ -92,7 +92,7 @@ class ImageLoaderTest {
private lateinit var contentResolver: ContentResolver

@ExperimentalCoroutinesApi
private val testDispacher = TestCoroutineDispatcher()
private val testDispacher = StandardTestDispatcher()

private lateinit var imageLoader: ImageLoader
private var mapImageSHA1: HashMap<Uri, String> = HashMap()
Expand Down Expand Up @@ -153,7 +153,6 @@ class ImageLoaderTest {
@ExperimentalCoroutinesApi
fun tearDown() {
Dispatchers.resetMain()
testDispacher.cleanupTestCoroutines()
mockedPickedFiles.close()
}

Expand All @@ -162,7 +161,7 @@ class ImageLoaderTest {
*/
@Test
fun testQueryAndSetViewUploadedStatusNull() =
testDispacher.runBlockingTest {
TestScope(testDispacher).runTest {
whenever(uploadedStatusDao.getUploadedFromImageSHA1(any())).thenReturn(null)
whenever(notForUploadStatusDao.find(any())).thenReturn(0)
mapModifiedImageSHA1[image] = "testSha1"
Expand All @@ -182,7 +181,7 @@ class ImageLoaderTest {
*/
@Test
fun testQueryAndSetViewUploadedStatusNotNull() =
testDispacher.runBlockingTest {
TestScope(testDispacher).runTest {
whenever(uploadedStatusDao.getUploadedFromImageSHA1(any())).thenReturn(uploadedStatus)
whenever(notForUploadStatusDao.find(any())).thenReturn(0)
whenever(context.getSharedPreferences("custom_selector", 0))
Expand All @@ -195,7 +194,7 @@ class ImageLoaderTest {
*/
@Test
fun testNextActionableImage() =
testDispacher.runBlockingTest {
TestScope(testDispacher).runTest {
whenever(notForUploadStatusDao.find(any())).thenReturn(0)
whenever(uploadedStatusDao.findByImageSHA1(any(), any())).thenReturn(0)
whenever(uploadedStatusDao.findByModifiedImageSHA1(any(), any())).thenReturn(0)
Expand All @@ -208,16 +207,40 @@ class ImageLoaderTest {
whenever(PickedFiles.pickedExistingPicture(context, Uri.parse("test"))).thenReturn(
uploadableFile,
)
imageLoader.nextActionableImage(listOf(image), testDispacher, testDispacher, 0, emptyList())
imageLoader.nextActionableImage(
listOf(image),
testDispacher,
testDispacher,
0,
emptyList()
)

whenever(notForUploadStatusDao.find(any())).thenReturn(1)
imageLoader.nextActionableImage(listOf(image), testDispacher, testDispacher, 0, emptyList())
imageLoader.nextActionableImage(
listOf(image),
testDispacher,
testDispacher,
0,
emptyList()
)

whenever(uploadedStatusDao.findByImageSHA1(any(), any())).thenReturn(2)
imageLoader.nextActionableImage(listOf(image), testDispacher, testDispacher, 0, emptyList())
imageLoader.nextActionableImage(
listOf(image),
testDispacher,
testDispacher,
0,
emptyList()
)

whenever(uploadedStatusDao.findByModifiedImageSHA1(any(), any())).thenReturn(2)
imageLoader.nextActionableImage(listOf(image), testDispacher, testDispacher, 0, emptyList())
imageLoader.nextActionableImage(
listOf(image),
testDispacher,
testDispacher,
0,
emptyList()
)
}

/**
Expand All @@ -226,7 +249,7 @@ class ImageLoaderTest {
@Test
@ExperimentalCoroutinesApi
fun testGetSha1() =
testDispacher.runBlockingTest {
TestScope(testDispacher).runTest {
BDDMockito
.given(PickedFiles.pickedExistingPicture(context, image.uri))
.willReturn(UploadableFile(uri, File("ABC")))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ class MediaDetailFragmentUnitTests {
@Mock
private lateinit var mockSharedPreferencesEditor: SharedPreferences.Editor

private lateinit var binding: FragmentMediaDetailBinding
private lateinit var _binding: FragmentMediaDetailBinding

@Before
fun setUp() {
Expand All @@ -185,26 +185,26 @@ class MediaDetailFragmentUnitTests {

layoutInflater = LayoutInflater.from(activity)

binding = FragmentMediaDetailBinding.inflate(layoutInflater)
_binding = FragmentMediaDetailBinding.inflate(layoutInflater)

scrollView = binding.mediaDetailScrollView
scrollView = _binding.mediaDetailScrollView

progressBarDeletion = binding.progressBarDeletion
delete = binding.nominateDeletion
progressBarDeletion = _binding.progressBarDeletion
delete = _binding.nominateDeletion

Whitebox.setInternalState(fragment, "media", media)
Whitebox.setInternalState(fragment, "isDeleted", isDeleted)
Whitebox.setInternalState(fragment, "reasonList", reasonList)
Whitebox.setInternalState(fragment, "reasonListEnglishMappings", reasonListEnglishMappings)
Whitebox.setInternalState(fragment, "reasonBuilder", reasonBuilder)
Whitebox.setInternalState(fragment, "deleteHelper", deleteHelper)
Whitebox.setInternalState(fragment, "binding", binding)
Whitebox.setInternalState(fragment, "_binding", _binding)
Whitebox.setInternalState(fragment, "detailProvider", detailProvider)
Whitebox.setInternalState(binding, "mediaDetailImageView", simpleDraweeView)
Whitebox.setInternalState(binding, "mediaDetailTitle", textView)
Whitebox.setInternalState(binding, "mediaDetailDepictionContainer", linearLayout)
Whitebox.setInternalState(binding, "dummyCaptionDescriptionContainer", linearLayout)
Whitebox.setInternalState(binding, "depictionsEditButton", button)
Whitebox.setInternalState(_binding, "mediaDetailImageView", simpleDraweeView)
Whitebox.setInternalState(_binding, "mediaDetailTitle", textView)
Whitebox.setInternalState(_binding, "mediaDetailDepictionContainer", linearLayout)
Whitebox.setInternalState(_binding, "dummyCaptionDescriptionContainer", linearLayout)
Whitebox.setInternalState(_binding, "depictionsEditButton", button)
Whitebox.setInternalState(fragment, "locationManager", locationManager)

`when`(simpleDraweeView.hierarchy).thenReturn(genericDraweeHierarchy)
Expand Down Expand Up @@ -241,7 +241,7 @@ class MediaDetailFragmentUnitTests {
@Throws(Exception::class)
fun testLaunchZoomActivity() {
`when`(media.imageUrl).thenReturn("")
fragment.launchZoomActivity(binding.root)
fragment.launchZoomActivity(_binding.root)
}

@Test
Expand Down

0 comments on commit 8c851ba

Please sign in to comment.