Implemented tests for FolderPickerActivity

This commit is contained in:
Kilian Périsset 2020-02-13 12:55:02 +01:00 committed by tobiasKaminsky
parent 511a16612d
commit 389090d3e8
No known key found for this signature in database
GPG key ID: 0E00D4D47D0C5AF7
2 changed files with 85 additions and 11 deletions

View file

@ -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);
}
}

View file

@ -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;
}