Compare commits

...
2 Commits
Author SHA1 Message Date
tobiasKaminsky ef92ca7db8 wip
Signed-off-by: tobiasKaminsky <[email protected]>
2020-02-19 15:24:40 +01:00
tobiasKaminsky 640e70e6f3 TestWorkshop
Signed-off-by: tobiasKaminsky <[email protected]>
2020-02-19 15:22:39 +01:00
5 changed files with 188 additions and 16 deletions

No files matched your search

+4
View File
@@ -109,6 +109,10 @@ shot {
}
android {
testOptions {
unitTests.returnDefaultValues = true
}
lintOptions {
abortOnError false
htmlReport true
@@ -0,0 +1,32 @@
package com.owncloud.android.ui.dialog;
import com.owncloud.android.R;
import com.owncloud.android.datamodel.OCFile;
import com.owncloud.android.lib.resources.files.FileUtils;
import com.owncloud.android.ui.helpers.FileOperationsHelper;
class Controller {
FileOperationsHelper fileOperationsHelper;
Controller(FileOperationsHelper fileOperationsHelper) {
this.fileOperationsHelper = fileOperationsHelper;
}
public void verifyAndCreateFolder(OCFile mParentFolder, String newFolderName) {
if (newFolderName.length() <= 0) {
throw new RuntimeException(String.valueOf(R.string.filename_empty));
}
if (!FileUtils.isValidName(newFolderName)) {
//DisplayUtils.showSnackMessage(getActivity(), R.string.filename_forbidden_characters);
return;
}
String path = mParentFolder.getRemotePath();
path += newFolderName + OCFile.PATH_SEPARATOR;
fileOperationsHelper.createFolder(path, false);
}
}
@@ -36,12 +36,14 @@ import com.owncloud.android.R;
import com.owncloud.android.datamodel.OCFile;
import com.owncloud.android.lib.resources.files.FileUtils;
import com.owncloud.android.ui.activity.ComponentsGetter;
import com.owncloud.android.ui.helpers.FileOperationsHelper;
import com.owncloud.android.utils.DisplayUtils;
import com.owncloud.android.utils.ThemeUtils;
import androidx.annotation.NonNull;
import androidx.appcompat.app.AlertDialog;
import androidx.fragment.app.DialogFragment;
import androidx.fragment.app.FragmentActivity;
/**
* Dialog to input the name for a new folder to create.
@@ -49,13 +51,16 @@ import androidx.fragment.app.DialogFragment;
* Triggers the folder creation when name is confirmed.
*/
public class CreateFolderDialogFragment
extends DialogFragment implements DialogInterface.OnClickListener {
extends DialogFragment implements DialogInterface.OnClickListener {
private static final String ARG_PARENT_FOLDER = "PARENT_FOLDER";
public static final String CREATE_FOLDER_FRAGMENT = "CREATE_FOLDER_FRAGMENT";
private OCFile mParentFolder;
OCFile mParentFolder;
Dialog localDialog;
FragmentActivity activity;
/**
* Public factory method to create new CreateFolderDialogFragment instances.
@@ -79,6 +84,8 @@ public class CreateFolderDialogFragment
int color = ThemeUtils.primaryAccentColor(getContext());
AlertDialog alertDialog = (AlertDialog) getDialog();
localDialog = getDialog();
activity = getActivity();
alertDialog.getButton(AlertDialog.BUTTON_POSITIVE).setTextColor(color);
alertDialog.getButton(AlertDialog.BUTTON_NEGATIVE).setTextColor(color);
@@ -104,10 +111,10 @@ public class CreateFolderDialogFragment
// Build the dialog
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
builder.setView(v)
.setPositiveButton(R.string.folder_confirm_create, this)
.setNegativeButton(R.string.common_cancel, this)
.setTitle(ThemeUtils.getColoredTitle(getResources().getString(R.string.uploader_info_dirname),
accentColor));
.setPositiveButton(R.string.folder_confirm_create, this)
.setNegativeButton(R.string.common_cancel, this)
.setTitle(ThemeUtils.getColoredTitle(getResources().getString(R.string.uploader_info_dirname),
accentColor));
Dialog d = builder.create();
Window window = d.getWindow();
@@ -121,24 +128,50 @@ public class CreateFolderDialogFragment
@Override
public void onClick(DialogInterface dialog, int which) {
if (which == AlertDialog.BUTTON_POSITIVE) {
String newFolderName =
((TextView)(getDialog().findViewById(R.id.user_input)))
.getText().toString().trim();
if (which != android.app.AlertDialog.BUTTON_POSITIVE) {
return;
}
String newFolderName =
((TextView) (localDialog.findViewById(R.id.user_input)))
.getText().toString().trim();
if (TextUtils.isEmpty(newFolderName)) {
DisplayUtils.showSnackMessage(getActivity(), R.string.filename_empty);
return;
}
if (!FileUtils.isValidName(newFolderName)) {
DisplayUtils.showSnackMessage(getActivity(), R.string.filename_forbidden_charaters_from_server);
try {
new Controller(((ComponentsGetter) getActivity()).getFileOperationsHelper())
.verifyAndCreateFolder(which, newFolderName);
} catch (RuntimeException e) {
DisplayUtils.showSnackMessage(getActivity(), e.getMessage());
}
}
return;
class Controller {
FileOperationsHelper fileOperationsHelper;
Controller(FileOperationsHelper fileOperationsHelper) {
this.fileOperationsHelper = fileOperationsHelper;
}
public void verifyAndCreateFolder(int which, String newFolderName) {
if (which == AlertDialog.BUTTON_POSITIVE) {
if (newFolderName.length() <= 0) {
throw new RuntimeException(String.valueOf(R.string.filename_empty));
}
if (!FileUtils.isValidName(newFolderName)) {
DisplayUtils.showSnackMessage(getActivity(), R.string.filename_forbidden_charaters_from_server);
return;
}
String path = mParentFolder.getRemotePath();
path += newFolderName + OCFile.PATH_SEPARATOR;
fileOperationsHelper.createFolder(path, false);
}
String path = mParentFolder.getRemotePath() + newFolderName + OCFile.PATH_SEPARATOR;
((ComponentsGetter) getActivity()).getFileOperationsHelper().createFolder(path, false);
}
}
}
@@ -0,0 +1,41 @@
package com.owncloud.android.ui.dialog;
import com.owncloud.android.datamodel.OCFile;
import com.owncloud.android.ui.helpers.FileOperationsHelper;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.Mockito;
import org.mockito.runners.MockitoJUnitRunner;
/**
* Created by daniel on 22.03.18.
*/
@RunWith(MockitoJUnitRunner.class)
public class ControllerTest {
@Mock
FileOperationsHelper fileOperationsHelper;
@Test
public void testSuccess() {
// setup
Controller sut = new Controller(fileOperationsHelper);
// test
sut.verifyAndCreateFolder(new OCFile("/123/"), "TestOrdner");
// verify
Mockito.verify(fileOperationsHelper).createFolder(Mockito.eq("/123/TestOrdner/"), Mockito.eq(false));
}
@Test(expected = RuntimeException.class)
public void testEmpty() {
// setup
Controller sut = new Controller(fileOperationsHelper);
// test
sut.verifyAndCreateFolder(new OCFile("/123/"), "");
}
}
@@ -0,0 +1,62 @@
package com.owncloud.android.ui.dialog;
import android.app.Dialog;
import android.support.v4.app.FragmentHostCallback;
import android.support.v7.app.AlertDialog;
import android.widget.TextView;
import com.owncloud.android.R;
import com.owncloud.android.datamodel.OCFile;
import com.owncloud.android.ui.activity.FileActivity;
import com.owncloud.android.ui.helpers.FileOperationsHelper;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.Mockito;
import org.mockito.runners.MockitoJUnitRunner;
/**
* Created by daniel on 22.03.18.
*/
@RunWith(MockitoJUnitRunner.class)
public class CreateFolderDialogFragmentTest {
@Mock
FragmentHostCallback mHost;
@Mock
Dialog dialog;
@Mock
TextView textView;
@Mock
FileActivity componentsGetter;
@Mock
FileOperationsHelper fileOperationsHelper;
@Mock
OCFile parentFolder;
@Test
public void testSuccess() {
// setup
CreateFolderDialogFragment sut = new CreateFolderDialogFragment();
sut.localDialog = dialog;
Mockito.when(dialog.findViewById(R.id.user_input)).thenReturn(textView);
Mockito.when(textView.getText()).thenReturn("TestOrdner");
sut.activity = componentsGetter;
Mockito.when(componentsGetter.getFileOperationsHelper()).thenReturn(fileOperationsHelper);
Mockito.when(fileOperationsHelper.isVersionWithForbiddenCharacters()).thenReturn(false);
sut.mParentFolder = parentFolder;
Mockito.when(parentFolder.getRemotePath()).thenReturn("/123/");
// test
sut.onClick(null, AlertDialog.BUTTON_POSITIVE);
// verify
Mockito.verify(fileOperationsHelper).createFolder(Mockito.eq("/123/TestOrdner/"), Mockito.eq(false));
}
}