ErrorMessageAdapterIT.java 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. /*
  2. * ownCloud Android client application
  3. *
  4. * @author David A. Velasco
  5. * Copyright (C) 2016 ownCloud Inc.
  6. *
  7. * This program is free software: you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License version 2,
  9. * as published by the Free Software Foundation.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  18. *
  19. */
  20. package com.owncloud.android.util;
  21. import android.accounts.Account;
  22. import android.content.Context;
  23. import android.content.res.Resources;
  24. import com.nextcloud.client.account.MockUser;
  25. import com.nextcloud.client.account.User;
  26. import com.owncloud.android.MainApp;
  27. import com.owncloud.android.datamodel.FileDataStorageManager;
  28. import com.owncloud.android.datamodel.OCFile;
  29. import com.owncloud.android.lib.common.operations.RemoteOperationResult;
  30. import com.owncloud.android.operations.RemoveFileOperation;
  31. import com.owncloud.android.utils.ErrorMessageAdapter;
  32. import org.junit.Test;
  33. import org.junit.runner.RunWith;
  34. import androidx.test.ext.junit.runners.AndroidJUnit4;
  35. import androidx.test.platform.app.InstrumentationRegistry;
  36. import static junit.framework.TestCase.assertEquals;
  37. @RunWith(AndroidJUnit4.class)
  38. public class ErrorMessageAdapterIT {
  39. private final static String PATH_TO_DELETE = "/path/to/a.file";
  40. private final static String EXPECTED_ERROR_MESSAGE = "You are not permitted to delete this file";
  41. private final static String ACCOUNT_TYPE = "nextcloud";
  42. @Test
  43. public void getErrorCauseMessageForForbiddenRemoval() {
  44. Resources resources = InstrumentationRegistry.getInstrumentation().getTargetContext().getResources();
  45. User user = new MockUser("name", ACCOUNT_TYPE);
  46. Context context = MainApp.getAppContext();
  47. String errorMessage = ErrorMessageAdapter.getErrorCauseMessage(
  48. new RemoteOperationResult(RemoteOperationResult.ResultCode.FORBIDDEN),
  49. new RemoveFileOperation(new OCFile(PATH_TO_DELETE),
  50. false,
  51. user.toPlatformAccount(),
  52. false,
  53. context,
  54. new FileDataStorageManager(user, context.getContentResolver())),
  55. resources
  56. );
  57. assertEquals(EXPECTED_ERROR_MESSAGE, errorMessage);
  58. }
  59. }