mirror of
https://github.com/nextcloud/android.git
synced 2024-11-26 15:15:51 +03:00
Implemented tests for FolderPickerActivity
This commit is contained in:
parent
511a16612d
commit
389090d3e8
2 changed files with 85 additions and 11 deletions
|
@ -0,0 +1,74 @@
|
|||
package com.owncloud.android.ui.activity;
|
||||
|
||||
import com.owncloud.android.datamodel.OCFile;
|
||||
|
||||
import org.junit.Assert;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
|
||||
import androidx.test.ext.junit.runners.AndroidJUnit4;
|
||||
import androidx.test.filters.LargeTest;
|
||||
import androidx.test.rule.ActivityTestRule;
|
||||
|
||||
@RunWith(AndroidJUnit4.class)
|
||||
@LargeTest
|
||||
public class FolderPickerActivityTest {
|
||||
@Rule
|
||||
public ActivityTestRule<FolderPickerActivity> activityRule =
|
||||
new ActivityTestRule<>(FolderPickerActivity.class);
|
||||
|
||||
@Test
|
||||
public void getFile_NoDifferenceTest() {
|
||||
// Arrange
|
||||
FolderPickerActivity targetActivity = activityRule.getActivity();
|
||||
OCFile origin = new OCFile("/test/file.test");
|
||||
origin.setRemotePath("/remotePath/test");
|
||||
|
||||
// Act
|
||||
targetActivity.setFile(origin);
|
||||
OCFile target = targetActivity.getFile();
|
||||
|
||||
// Assert
|
||||
Assert.assertEquals(origin, target);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getParentFolder_isNotRootFolderTest() {
|
||||
// Arrange
|
||||
FolderPickerActivity targetActivity = activityRule.getActivity();
|
||||
|
||||
|
||||
OCFile origin = new OCFile("/test/");
|
||||
origin.setFileId(1);
|
||||
origin.setRemotePath("/test/");
|
||||
origin.setStoragePath("/test/");
|
||||
origin.setFolder();
|
||||
|
||||
// Act
|
||||
targetActivity.setFile(origin);
|
||||
OCFile target = targetActivity.getCurrentFolder();
|
||||
|
||||
// Assert
|
||||
Assert.assertEquals(origin, target);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getParentFolder_isRootFolderTest() {
|
||||
// Arrange
|
||||
FolderPickerActivity targetActivity = activityRule.getActivity();
|
||||
|
||||
OCFile origin = new OCFile("/");
|
||||
origin.setFileId(1);
|
||||
origin.setRemotePath("/");
|
||||
origin.setStoragePath("/");
|
||||
origin.setFolder();
|
||||
|
||||
// Act
|
||||
targetActivity.setFile(origin);
|
||||
OCFile target = targetActivity.getCurrentFolder();
|
||||
|
||||
// Assert
|
||||
Assert.assertEquals(origin, target);
|
||||
}
|
||||
}
|
|
@ -331,22 +331,22 @@ public class FolderPickerActivity extends FileActivity implements FileFragment.C
|
|||
}
|
||||
|
||||
protected OCFile getCurrentFolder() {
|
||||
OCFile currentStateFile = getFile();
|
||||
OCFile finalFolder;
|
||||
OCFile currentFile = getFile();
|
||||
OCFile finalFolder = null;
|
||||
|
||||
// If the file is null, take the root folder to avoid any error in functions depending on this one
|
||||
if (currentStateFile == null) {
|
||||
finalFolder = getStorageManager().getFileByPath(OCFile.ROOT_PATH);
|
||||
} else {
|
||||
if (currentStateFile.isFolder()) {
|
||||
finalFolder = currentStateFile;
|
||||
} else {
|
||||
String parentPath = currentStateFile
|
||||
if (currentFile != null) {
|
||||
if (currentFile.isFolder()) {
|
||||
finalFolder = currentFile;
|
||||
} else if(currentFile.getRemotePath() != null) {
|
||||
String parentPath = currentFile
|
||||
.getRemotePath()
|
||||
.substring(0, currentStateFile.getRemotePath()
|
||||
.lastIndexOf(currentStateFile.getFileName()));
|
||||
.substring(0, currentFile.getRemotePath()
|
||||
.lastIndexOf(currentFile.getFileName()));
|
||||
finalFolder = getStorageManager().getFileByPath(parentPath);
|
||||
}
|
||||
} else {
|
||||
finalFolder = getStorageManager().getFileByPath(OCFile.ROOT_PATH);
|
||||
}
|
||||
return finalFolder;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue