move sleep to function

fix errors found by detekt

Signed-off-by: tobiasKaminsky <tobias@kaminsky.me>
This commit is contained in:
tobiasKaminsky 2020-03-19 15:56:17 +01:00
parent 7eb0f66079
commit 1a1c42e0a7
No known key found for this signature in database
GPG key ID: 0E00D4D47D0C5AF7
8 changed files with 59 additions and 41 deletions

View file

@ -71,10 +71,10 @@ public class FileDisplayActivityIT extends AbstractIT {
Manifest.permission.WRITE_EXTERNAL_STORAGE);
@Test
public void open() throws InterruptedException {
public void open() {
Activity sut = activityRule.launchActivity(null);
Thread.sleep(3000);
shortSleep();
Screenshot.snapActivity(sut).record();
}
@ -162,7 +162,7 @@ public class FileDisplayActivityIT extends AbstractIT {
}
@Test
public void allFiles() throws InterruptedException {
public void allFiles() {
// ActivityScenario<FileDisplayActivity> sut = ActivityScenario.launch(FileDisplayActivity.class);
FileDisplayActivity sut = activityRule.launchActivity(null);
@ -184,7 +184,7 @@ public class FileDisplayActivityIT extends AbstractIT {
.perform(NavigationViewActions.navigateTo(R.id.nav_all_files));
// then should be in root again
Thread.sleep(2000);
shortSleep();
assertEquals(getStorageManager().getFileByPath("/"), sut.getCurrentDir());
}
}

View file

@ -192,7 +192,7 @@ public abstract class AbstractIT {
protected void openDrawer(IntentsTestRule activityRule) throws InterruptedException {
Activity sut = activityRule.launchActivity(null);
Thread.sleep(3000);
shortSleep();
onView(withId(R.id.drawer_layout)).perform(DrawerActions.open());
@ -214,4 +214,20 @@ public abstract class AbstractIT {
return currentActivity;
}
protected void shortSleep() {
try {
Thread.sleep(2000);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
protected void longSleep() {
try {
Thread.sleep(20000);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}

View file

@ -60,7 +60,7 @@ public class ScreenshotsIT extends AbstractIT {
openOverflowMenu();
onView(anyOf(withText(R.string.action_switch_grid_view), withId(R.id.action_switch_view))).perform(click());
Thread.sleep(1000);
shortSleep();
Screengrab.screenshot("01_gridView");
@ -70,12 +70,12 @@ public class ScreenshotsIT extends AbstractIT {
Assert.assertTrue(true); // if we reach this, everything is ok
}
private void openOverflowMenu() throws InterruptedException {
private void openOverflowMenu() {
try {
Espresso.openContextualActionModeOverflowMenu();
} catch (NoActivityResumedException e) {
ActivityScenario.launch(FileDisplayActivity.class);
Thread.sleep(1000);
shortSleep();
Espresso.openContextualActionModeOverflowMenu();
}
}
@ -143,12 +143,12 @@ public class ScreenshotsIT extends AbstractIT {
}
@Test
public void davdroidScreenshot() throws InterruptedException {
public void davdroidScreenshot() {
ActivityScenario.launch(SettingsActivity.class);
onData(PreferenceMatchers.withTitle(R.string.prefs_category_more)).perform(ViewActions.scrollTo());
Thread.sleep(1000);
shortSleep();
Screengrab.screenshot("06_davdroid");

View file

@ -42,9 +42,6 @@ import org.junit.Test
import java.io.File
class FileUploaderIT : AbstractIT() {
val SHORT_WAIT: Long = 5000
val LONG_WAIT: Long = 20000
var uploadsStorageManager: UploadsStorageManager? = null
val connectivityServiceMock: ConnectivityService = object : ConnectivityService {
@ -149,7 +146,7 @@ class FileUploaderIT : AbstractIT() {
false,
FileUploader.NameCollisionPolicy.DEFAULT)
Thread.sleep(LONG_WAIT)
longSleep()
val result = ReadFileRemoteOperation("/testFile.txt").execute(client)
assertTrue(result.isSuccess)
@ -166,7 +163,7 @@ class FileUploaderIT : AbstractIT() {
FileUploader.LOCAL_BEHAVIOUR_COPY,
FileUploader.NameCollisionPolicy.OVERWRITE)
Thread.sleep(SHORT_WAIT)
shortSleep()
val result2 = ReadFileRemoteOperation("/testFile.txt").execute(client)
assertTrue(result2.isSuccess)
@ -256,7 +253,7 @@ class FileUploaderIT : AbstractIT() {
false,
FileUploader.NameCollisionPolicy.DEFAULT)
Thread.sleep(LONG_WAIT)
longSleep()
val result = ReadFileRemoteOperation("/testFile.txt").execute(client)
assertTrue(result.isSuccess)
@ -273,7 +270,7 @@ class FileUploaderIT : AbstractIT() {
FileUploader.LOCAL_BEHAVIOUR_COPY,
FileUploader.NameCollisionPolicy.RENAME)
Thread.sleep(SHORT_WAIT)
shortSleep()
val result2 = ReadFileRemoteOperation("/testFile.txt").execute(client)
assertTrue(result2.isSuccess)
@ -356,7 +353,7 @@ class FileUploaderIT : AbstractIT() {
false,
FileUploader.NameCollisionPolicy.DEFAULT)
Thread.sleep(LONG_WAIT)
longSleep()
val result = ReadFileRemoteOperation("/testFile.txt").execute(client)
assertTrue(result.isSuccess)
@ -373,7 +370,7 @@ class FileUploaderIT : AbstractIT() {
FileUploader.LOCAL_BEHAVIOUR_COPY,
FileUploader.NameCollisionPolicy.CANCEL)
Thread.sleep(SHORT_WAIT)
shortSleep()
val result2 = ReadFileRemoteOperation("/testFile.txt").execute(client)
assertTrue(result2.isSuccess)

View file

@ -59,7 +59,7 @@ public class ConflictsResolveActivityIT extends AbstractIT {
private boolean returnCode;
@Test
public void screenshotTextFiles() throws InterruptedException {
public void screenshotTextFiles() {
OCFile newFile = new OCFile("/newFile.txt");
newFile.setFileLength(56000);
newFile.setModificationTimestamp(1522019340);
@ -88,13 +88,13 @@ public class ConflictsResolveActivityIT extends AbstractIT {
getInstrumentation().waitForIdleSync();
Thread.sleep(2000);
shortSleep();
Screenshot.snap(dialog.getDialog().getWindow().getDecorView()).record();
}
@Test
public void screenshotImages() throws InterruptedException, IOException {
public void screenshotImages() throws IOException {
FileDataStorageManager storageManager = new FileDataStorageManager(account,
targetContext.getContentResolver());
@ -141,13 +141,13 @@ public class ConflictsResolveActivityIT extends AbstractIT {
dialog.listener = listener;
getInstrumentation().waitForIdleSync();
Thread.sleep(2000);
shortSleep();
Screenshot.snap(dialog.getDialog().getWindow().getDecorView()).record();
}
@Test
public void cancel() throws InterruptedException {
public void cancel() {
returnCode = false;
OCUpload newUpload = new OCUpload(FileStorageUtils.getSavePath(account.name) + "/nonEmpty.txt",
@ -179,7 +179,7 @@ public class ConflictsResolveActivityIT extends AbstractIT {
};
getInstrumentation().waitForIdleSync();
Thread.sleep(2000);
shortSleep();
onView(withText("Cancel")).perform(click());

View file

@ -40,22 +40,22 @@ public class ManageAccountsActivityIT extends AbstractIT {
false);
@Test
public void open() throws InterruptedException {
public void open() {
Activity sut = activityRule.launchActivity(null);
Thread.sleep(2000);
shortSleep();
Screenshot.snapActivity(sut).record();
}
@Test
public void userInfoDetail() throws InterruptedException {
public void userInfoDetail() {
ManageAccountsActivity sut = activityRule.launchActivity(null);
User user = sut.accountManager.getUser();
sut.onClick(user);
Thread.sleep(2000);
shortSleep();
Screenshot.snapActivity(getCurrentActivity()).record();
}

View file

@ -55,6 +55,11 @@ import org.junit.Rule
import org.junit.Test
class OCFileListFragmentIT : AbstractIT() {
companion object {
val SECOND_IN_MILLIS = 1000L
val RESULT_PER_PAGE = 50
}
@get:Rule
val activityRule = IntentsTestRule(FileDisplayActivity::class.java, true, false)
@ -112,7 +117,7 @@ class OCFileListFragmentIT : AbstractIT() {
assertTrue(newUpload.execute(client, storageManager).isSuccess)
assertTrue(RefreshFolderOperation(storageManager.getFileByPath("/test/"),
System.currentTimeMillis() / 1000,
System.currentTimeMillis() / SECOND_IN_MILLIS,
false,
true,
storageManager,
@ -122,7 +127,7 @@ class OCFileListFragmentIT : AbstractIT() {
val sut = ActivityScenario.launch(FileDisplayActivity::class.java)
sut.onActivity { activity -> activity.onBrowsedDownTo(storageManager.getFileByPath("/test/")) }
Thread.sleep(2000)
shortSleep()
sut.onActivity { activity ->
Screenshot.snapActivity(activity).setName("richworkspaces_light").record()
@ -138,7 +143,7 @@ class OCFileListFragmentIT : AbstractIT() {
sut.onActivity { activity -> activity.onBrowsedDownTo(storageManager.getFileByPath("/test/")) }
Thread.sleep(2000)
shortSleep()
sut.onActivity { activity ->
Screenshot.snapActivity(activity).setName("richworkspaces_dark").record()
@ -170,7 +175,7 @@ class OCFileListFragmentIT : AbstractIT() {
val sut: FileDisplayActivity = activityRule.launchActivity(null)
sut.startSyncFolderOperation(storageManager.getFileByPath("/"), true)
Thread.sleep(2000)
shortSleep()
InstrumentationRegistry.getInstrumentation().waitForIdleSync()
Screenshot.snapActivity(sut).record()
}
@ -192,7 +197,7 @@ class OCFileListFragmentIT : AbstractIT() {
val sut: FileDisplayActivity = activityRule.launchActivity(null)
sut.startSyncFolderOperation(storageManager.getFileByPath("/"), true)
Thread.sleep(2000)
shortSleep()
InstrumentationRegistry.getInstrumentation().waitForIdleSync()
Screenshot.snapActivity(sut).record()
}
@ -204,7 +209,7 @@ class OCFileListFragmentIT : AbstractIT() {
// share folder to circle
// get circleId
val searchResult = GetShareesRemoteOperation("publicCircle", 1, 50).execute(client)
val searchResult = GetShareesRemoteOperation("publicCircle", 1, RESULT_PER_PAGE).execute(client)
assertTrue(searchResult.logMessage, searchResult.isSuccess)
val resultJson: JSONObject = searchResult.data[0] as JSONObject
@ -221,7 +226,7 @@ class OCFileListFragmentIT : AbstractIT() {
val sut: FileDisplayActivity = activityRule.launchActivity(null)
sut.startSyncFolderOperation(storageManager.getFileByPath("/"), true)
Thread.sleep(2000)
shortSleep()
InstrumentationRegistry.getInstrumentation().waitForIdleSync()
Screenshot.snapActivity(sut).record()
}
@ -243,7 +248,7 @@ class OCFileListFragmentIT : AbstractIT() {
val sut: FileDisplayActivity = activityRule.launchActivity(null)
sut.startSyncFolderOperation(storageManager.getFileByPath("/"), true)
Thread.sleep(2000)
shortSleep()
InstrumentationRegistry.getInstrumentation().waitForIdleSync()
Screenshot.snapActivity(sut).record()
}

View file

@ -53,7 +53,7 @@ public class PreviewTextFileFragmentTest extends AbstractIT {
public void displaySimpleTextFile() throws InterruptedException {
FileDisplayActivity sut = activityRule.launchActivity(null);
Thread.sleep(3000);
shortSleep();
File file = new File(FileStorageUtils.getSavePath(account.name) + "/nonEmpty.txt");
OCFile test = new OCFile("/text.md");
@ -61,7 +61,7 @@ public class PreviewTextFileFragmentTest extends AbstractIT {
test.setStoragePath(file.getAbsolutePath());
sut.startTextPreview(test, false);
Thread.sleep(3000);
shortSleep();
Screenshot.snapActivity(sut).record();
}
@ -70,7 +70,7 @@ public class PreviewTextFileFragmentTest extends AbstractIT {
public void displayJavaSnippetFile() throws IOException, InterruptedException {
FileDisplayActivity sut = activityRule.launchActivity(null);
Thread.sleep(3000);
shortSleep();
File file = getFile("java.md");
OCFile test = new OCFile("/java.md");
@ -78,7 +78,7 @@ public class PreviewTextFileFragmentTest extends AbstractIT {
test.setStoragePath(file.getAbsolutePath());
sut.startTextPreview(test, false);
Thread.sleep(3000);
shortSleep();
Screenshot.snapActivity(sut).record();
}