Эх сурвалжийг харах

Use correct thread and fix idling logic

Signed-off-by: alperozturk <alper_ozturk@proton.me>
alperozturk 11 сар өмнө
parent
commit
1ba24ce999

+ 15 - 28
app/src/androidTest/java/com/owncloud/android/ui/activity/NotificationsActivityIT.kt

@@ -7,6 +7,7 @@
  */
 package com.owncloud.android.ui.activity
 
+import androidx.annotation.UiThread
 import androidx.test.core.app.launchActivity
 import androidx.test.espresso.Espresso.onView
 import androidx.test.espresso.IdlingRegistry
@@ -19,16 +20,12 @@ import com.owncloud.android.lib.resources.notifications.models.Action
 import com.owncloud.android.lib.resources.notifications.models.Notification
 import com.owncloud.android.lib.resources.notifications.models.RichObject
 import com.owncloud.android.utils.ScreenshotTest
-import kotlinx.coroutines.CoroutineScope
-import kotlinx.coroutines.Dispatchers
-import kotlinx.coroutines.launch
 import org.junit.After
 import org.junit.Before
 import org.junit.Test
 import java.util.GregorianCalendar
 
 class NotificationsActivityIT : AbstractIT() {
-    private val scope = CoroutineScope(Dispatchers.IO)
     private val testClassName = "com.owncloud.android.ui.activity.NotificationsActivityIT"
 
     @Before
@@ -42,27 +39,23 @@ class NotificationsActivityIT : AbstractIT() {
     }
 
     @Test
+    @UiThread
     @ScreenshotTest
     fun empty() {
         launchActivity<NotificationsActivity>().use { scenario ->
             scenario.onActivity { sut ->
                 onIdleSync {
-                    sut.runOnUiThread { sut.populateList(ArrayList()) }
+                    sut.populateList(ArrayList())
                     val screenShotName = createName(testClassName + "_" + "empty", "")
-
-                    scope.launch {
-                        onView(isRoot()).check(matches(isDisplayed()))
-
-                        launch(Dispatchers.Main) {
-                            screenshotViaName(sut, screenShotName)
-                        }
-                    }
+                    onView(isRoot()).check(matches(isDisplayed()))
+                    screenshotViaName(sut, screenShotName)
                 }
             }
         }
     }
 
     @Test
+    @UiThread
     @ScreenshotTest
     @SuppressWarnings("MagicNumber")
     fun showNotifications() {
@@ -146,33 +139,27 @@ class NotificationsActivityIT : AbstractIT() {
 
         launchActivity<NotificationsActivity>().use { scenario ->
             scenario.onActivity { sut ->
-                sut.runOnUiThread { sut.populateList(notifications) }
-                val screenShotName = createName(testClassName + "_" + "showNotifications", "")
-                scope.launch {
+                onIdleSync {
+                    sut.populateList(notifications)
+                    val screenShotName = createName(testClassName + "_" + "showNotifications", "")
                     onView(isRoot()).check(matches(isDisplayed()))
-
-                    launch(Dispatchers.Main) {
-                        screenshotViaName(sut, screenShotName)
-                    }
+                    screenshotViaName(sut, screenShotName)
                 }
             }
         }
     }
 
     @Test
+    @UiThread
     @ScreenshotTest
     fun error() {
         launchActivity<NotificationsActivity>().use { scenario ->
             scenario.onActivity { sut ->
-                sut.runOnUiThread { sut.setEmptyContent("Error", "Error! Please try again later!") }
-                val screenShotName = createName(testClassName + "_" + "error", "")
-
-                scope.launch {
+                onIdleSync {
+                    sut.setEmptyContent("Error", "Error! Please try again later!")
+                    val screenShotName = createName(testClassName + "_" + "error", "")
                     onView(isRoot()).check(matches(isDisplayed()))
-
-                    launch(Dispatchers.Main) {
-                        screenshotViaName(sut, screenShotName)
-                    }
+                    screenshotViaName(sut, screenShotName)
                 }
             }
         }

+ 25 - 46
app/src/androidTest/java/com/owncloud/android/ui/trashbin/TrashbinActivityIT.kt

@@ -10,6 +10,7 @@ package com.owncloud.android.ui.trashbin
 import android.accounts.Account
 import android.accounts.AccountManager
 import android.content.Intent
+import androidx.annotation.UiThread
 import androidx.test.core.app.launchActivity
 import androidx.test.espresso.Espresso.onView
 import androidx.test.espresso.IdlingRegistry
@@ -21,15 +22,11 @@ import com.owncloud.android.AbstractIT
 import com.owncloud.android.MainApp
 import com.owncloud.android.lib.common.accounts.AccountUtils
 import com.owncloud.android.utils.ScreenshotTest
-import kotlinx.coroutines.CoroutineScope
-import kotlinx.coroutines.Dispatchers
-import kotlinx.coroutines.launch
 import org.junit.After
 import org.junit.Before
 import org.junit.Test
 
 class TrashbinActivityIT : AbstractIT() {
-    private val scope = CoroutineScope(Dispatchers.IO)
     private val testClassName = "com.owncloud.android.ui.trashbin.TrashbinActivityIT"
 
     enum class TestCase {
@@ -49,6 +46,7 @@ class TrashbinActivityIT : AbstractIT() {
     }
 
     @Test
+    @UiThread
     @ScreenshotTest
     fun error() {
         launchActivity<TrashbinActivity>().use { scenario ->
@@ -56,29 +54,26 @@ class TrashbinActivityIT : AbstractIT() {
                 val trashbinRepository = TrashbinLocalRepository(TestCase.ERROR)
                 sut.trashbinPresenter = TrashbinPresenter(trashbinRepository, sut)
                 onIdleSync {
-                    sut.runOnUiThread { sut.loadFolder() }
+                    sut.loadFolder()
                     val screenShotName = createName(testClassName + "_" + "error", "")
-                    scope.launch {
-                        onView(isRoot()).check(matches(isDisplayed()))
-
-                        launch(Dispatchers.Main) {
-                            screenshotViaName(sut, screenShotName)
-                        }
-                    }
+                    onView(isRoot()).check(matches(isDisplayed()))
+                    screenshotViaName(sut, screenShotName)
                 }
             }
         }
     }
 
     @Test
+    @UiThread
     @ScreenshotTest
     fun files() {
         launchActivity<TrashbinActivity>().use { scenario ->
             scenario.onActivity { sut ->
                 val trashbinRepository = TrashbinLocalRepository(TestCase.FILES)
+                sut.trashbinPresenter = TrashbinPresenter(trashbinRepository, sut)
                 onIdleSync {
-                    sut.trashbinPresenter = TrashbinPresenter(trashbinRepository, sut)
-                    sut.runOnUiThread { sut.loadFolder() }
+                    sut.loadFolder()
+                    onView(isRoot()).check(matches(isDisplayed()))
                     val screenShotName = createName(testClassName + "_" + "files", "")
                     screenshotViaName(sut, screenShotName)
                 }
@@ -87,6 +82,7 @@ class TrashbinActivityIT : AbstractIT() {
     }
 
     @Test
+    @UiThread
     @ScreenshotTest
     fun empty() {
         launchActivity<TrashbinActivity>().use { scenario ->
@@ -94,21 +90,17 @@ class TrashbinActivityIT : AbstractIT() {
                 val trashbinRepository = TrashbinLocalRepository(TestCase.EMPTY)
                 sut.trashbinPresenter = TrashbinPresenter(trashbinRepository, sut)
                 onIdleSync {
-                    sut.runOnUiThread { sut.loadFolder() }
+                    sut.loadFolder()
+                    onView(isRoot()).check(matches(isDisplayed()))
                     val screenShotName = createName(testClassName + "_" + "empty", "")
-                    scope.launch {
-                        onView(isRoot()).check(matches(isDisplayed()))
-
-                        launch(Dispatchers.Main) {
-                            screenshotViaName(sut, screenShotName)
-                        }
-                    }
+                    screenshotViaName(sut, screenShotName)
                 }
             }
         }
     }
 
     @Test
+    @UiThread
     @ScreenshotTest
     fun loading() {
         launchActivity<TrashbinActivity>().use { scenario ->
@@ -116,21 +108,17 @@ class TrashbinActivityIT : AbstractIT() {
                 val trashbinRepository = TrashbinLocalRepository(TestCase.EMPTY)
                 sut.trashbinPresenter = TrashbinPresenter(trashbinRepository, sut)
                 onIdleSync {
-                    sut.runOnUiThread { sut.showInitialLoading() }
+                    sut.showInitialLoading()
                     val screenShotName = createName(testClassName + "_" + "loading", "")
-                    scope.launch {
-                        onView(isRoot()).check(matches(isDisplayed()))
-
-                        launch(Dispatchers.Main) {
-                            screenshotViaName(sut, screenShotName)
-                        }
-                    }
+                    onView(isRoot()).check(matches(isDisplayed()))
+                    screenshotViaName(sut, screenShotName)
                 }
             }
         }
     }
 
     @Test
+    @UiThread
     @ScreenshotTest
     fun normalUser() {
         launchActivity<TrashbinActivity>().use { scenario ->
@@ -138,21 +126,17 @@ class TrashbinActivityIT : AbstractIT() {
                 val trashbinRepository = TrashbinLocalRepository(TestCase.EMPTY)
                 sut.trashbinPresenter = TrashbinPresenter(trashbinRepository, sut)
                 onIdleSync {
-                    sut.runOnUiThread { sut.showUser() }
+                    sut.showUser()
                     val screenShotName = createName(testClassName + "_" + "normalUser", "")
-                    scope.launch {
-                        onView(isRoot()).check(matches(isDisplayed()))
-
-                        launch(Dispatchers.Main) {
-                            screenshotViaName(sut, screenShotName)
-                        }
-                    }
+                    onView(isRoot()).check(matches(isDisplayed()))
+                    screenshotViaName(sut, screenShotName)
                 }
             }
         }
     }
 
     @Test
+    @UiThread
     @ScreenshotTest
     fun differentUser() {
         val temp = Account("differentUser@https://nextcloud.localhost", MainApp.getAccountType(targetContext))
@@ -172,15 +156,10 @@ class TrashbinActivityIT : AbstractIT() {
                 val trashbinRepository = TrashbinLocalRepository(TestCase.EMPTY)
                 sut.trashbinPresenter = TrashbinPresenter(trashbinRepository, sut)
                 onIdleSync {
-                    sut.runOnUiThread { sut.showUser() }
+                    sut.showUser()
                     val screenShotName = createName(testClassName + "_" + "differentUser", "")
-                    scope.launch {
-                        onView(isRoot()).check(matches(isDisplayed()))
-
-                        launch(Dispatchers.Main) {
-                            screenshotViaName(sut, screenShotName)
-                        }
-                    }
+                    onView(isRoot()).check(matches(isDisplayed()))
+                    screenshotViaName(sut, screenShotName)
                 }
             }
         }