浏览代码

- fix IT tests
- re-organized build.gradle a bit

Signed-off-by: tobiasKaminsky <tobias@kaminsky.me>

tobiasKaminsky 6 年之前
父节点
当前提交
7d01ff75f0

+ 15 - 16
build.gradle

@@ -212,7 +212,7 @@ android {
 
     android.applicationVariants.all { variant ->
         String variantName = variant.name
-        String capVariantName = variantName.substring(0, 1).toUpperCase() + variantName.substring(1);
+        String capVariantName = variantName.substring(0, 1).toUpperCase() + variantName.substring(1)
         tasks.register("spotbugs${capVariantName}", SpotBugsTask) {
             ignoreFailures = false
             effort = "max"
@@ -273,7 +273,6 @@ dependencies {
     implementation 'pl.droidsonroids.gif:android-gif-drawable:1.2.15'
     implementation 'com.github.tobiaskaminsky:qrcodescanner:0.1.2.2' // 'com.github.blikoon:QRCodeScanner:0.1.2'
     implementation 'com.google.android:flexbox:1.1.0'
-
     implementation 'org.parceler:parceler-api:1.1.12'
     annotationProcessor 'org.parceler:parceler:1.1.12'
     implementation('com.github.bumptech.glide:glide:3.7.0') {
@@ -282,6 +281,19 @@ dependencies {
     implementation 'com.caverock:androidsvg:1.3'
     implementation 'androidx.annotation:annotation:1.0.2'
     implementation 'com.google.code.gson:gson:2.8.5'
+    implementation 'org.jetbrains:annotations:17.0.0'
+
+    spotbugsPlugins 'com.h3xstream.findsecbugs:findsecbugs-plugin:1.9.0'
+    spotbugsPlugins 'com.mebigfatguy.fb-contrib:fb-contrib:7.4.3'
+
+    implementation 'com.google.dagger:dagger:2.22.1'
+    implementation 'com.google.dagger:dagger-android:2.22.1'
+    implementation 'com.google.dagger:dagger-android-support:2.22.1'
+    annotationProcessor 'com.google.dagger:dagger-compiler:2.22.1'
+    annotationProcessor 'com.google.dagger:dagger-android-processor:2.22.1'
+
+    compileOnly "org.projectlombok:lombok:1.18.6"
+    annotationProcessor "org.projectlombok:lombok:1.18.6"
 
     // dependencies for local unit tests
     testImplementation 'junit:junit:4.12'
@@ -302,26 +314,13 @@ dependencies {
     // Espresso core
     androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.1'
     androidTestImplementation 'androidx.test.espresso:espresso-contrib:3.1.1'
+    androidTestImplementation 'org.mockito:mockito-core:2.27.0'
     // UIAutomator - for cross-app UI tests, and to grant screen is turned on in Espresso tests
     // androidTestImplementation 'androidx.test.uiautomator:uiautomator:2.2.0'
     // fix conflict in dependencies; see http://g.co/androidstudio/app-test-app-conflict for details
     //androidTestImplementation "com.android.support:support-annotations:${supportLibraryVersion}"
-    implementation 'org.jetbrains:annotations:17.0.0'
-
-    compileOnly "org.projectlombok:lombok:1.18.6"
-    annotationProcessor "org.projectlombok:lombok:1.18.6"
-
     androidTestImplementation 'tools.fastlane:screengrab:1.2.0'
 
-    spotbugsPlugins 'com.h3xstream.findsecbugs:findsecbugs-plugin:1.9.0'
-    spotbugsPlugins 'com.mebigfatguy.fb-contrib:fb-contrib:7.4.3'
-
-    implementation 'com.google.dagger:dagger:2.22.1'
-    implementation 'com.google.dagger:dagger-android:2.22.1'
-    implementation 'com.google.dagger:dagger-android-support:2.22.1'
-    annotationProcessor 'com.google.dagger:dagger-compiler:2.22.1'
-    annotationProcessor 'com.google.dagger:dagger-android-processor:2.22.1'
-
 //    jacocoAnt "org.jacoco:org.jacoco.ant:${jacocoVersion}"
 //    jacocoAgent "org.jacoco:org.jacoco.agent:${jacocoVersion}"
 //    androidJacocoAgent "org.jacoco:org.jacoco.agent:${jacocoVersion}"

+ 59 - 0
src/androidTest/java/com/owncloud/android/util/ErrorMessageAdapterIT.java

@@ -0,0 +1,59 @@
+/*
+ *   ownCloud Android client application
+ *
+ *   @author David A. Velasco
+ *   Copyright (C) 2016 ownCloud Inc.
+ *
+ *   This program is free software: you can redistribute it and/or modify
+ *   it under the terms of the GNU General Public License version 2,
+ *   as published by the Free Software Foundation.
+ *
+ *   This program is distributed in the hope that it will be useful,
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *   GNU General Public License for more details.
+ *
+ *   You should have received a copy of the GNU General Public License
+ *   along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+
+
+package com.owncloud.android.util;
+
+import android.accounts.Account;
+import android.content.res.Resources;
+
+import com.owncloud.android.MainApp;
+import com.owncloud.android.lib.common.operations.RemoteOperationResult;
+import com.owncloud.android.operations.RemoveFileOperation;
+import com.owncloud.android.utils.ErrorMessageAdapter;
+
+import org.junit.Test;
+import org.junit.runner.RunWith;
+
+import androidx.test.ext.junit.runners.AndroidJUnit4;
+import androidx.test.platform.app.InstrumentationRegistry;
+
+import static junit.framework.TestCase.assertEquals;
+
+@RunWith(AndroidJUnit4.class)
+public class ErrorMessageAdapterIT {
+    private final static String PATH_TO_DELETE = "/path/to/a.file";
+    private final static String EXPECTED_ERROR_MESSAGE = "You are not permitted to delete this file";
+    private final static String ACCOUNT_TYPE = "nextcloud";
+
+    @Test
+    public void getErrorCauseMessageForForbiddenRemoval() {
+        Resources resources = InstrumentationRegistry.getInstrumentation().getTargetContext().getResources();
+        Account account = new Account("name", ACCOUNT_TYPE);
+
+        String errorMessage = ErrorMessageAdapter.getErrorCauseMessage(
+            new RemoteOperationResult(RemoteOperationResult.ResultCode.FORBIDDEN),
+            new RemoveFileOperation(PATH_TO_DELETE, false, account, false, MainApp.getAppContext()),
+            resources
+        );
+
+        assertEquals(EXPECTED_ERROR_MESSAGE, errorMessage);
+    }
+}

+ 0 - 85
src/androidTest/java/com/owncloud/android/util/ErrorMessageAdapterUnitTest.java

@@ -1,85 +0,0 @@
-/*
- *   ownCloud Android client application
- *
- *   @author David A. Velasco
- *   Copyright (C) 2016 ownCloud Inc.
- *
- *   This program is free software: you can redistribute it and/or modify
- *   it under the terms of the GNU General Public License version 2,
- *   as published by the Free Software Foundation.
- *
- *   This program is distributed in the hope that it will be useful,
- *   but WITHOUT ANY WARRANTY; without even the implied warranty of
- *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- *   GNU General Public License for more details.
- *
- *   You should have received a copy of the GNU General Public License
- *   along with this program.  If not, see <http://www.gnu.org/licenses/>.
- *
- */
-
-
-package com.owncloud.android.util;
-
-import android.accounts.Account;
-import android.content.res.Resources;
-
-import com.owncloud.android.MainApp;
-import com.owncloud.android.R;
-import com.owncloud.android.lib.common.operations.RemoteOperationResult;
-import com.owncloud.android.operations.RemoveFileOperation;
-import com.owncloud.android.utils.ErrorMessageAdapter;
-
-import org.junit.Test;
-import org.junit.runner.RunWith;
-import org.mockito.Mock;
-import org.mockito.runners.MockitoJUnitRunner;
-
-import static org.hamcrest.CoreMatchers.is;
-import static org.hamcrest.MatcherAssert.assertThat;
-import static org.mockito.Mockito.when;
-
-/**
- * Local unit test, to be run out of Android emulator or device.
- *
- * At the moment, it's a sample to validate the automatic test environment, in the scope of local unit tests with
- * mock Android dependencies.
- *
- * Don't take it as an example of completeness.
- *
- * See http://developer.android.com/intl/es/training/testing/unit-testing/local-unit-tests.html .
- */
-@RunWith(MockitoJUnitRunner.class)
-public class ErrorMessageAdapterUnitTest {
-
-    private final static String MOCK_FORBIDDEN_PERMISSIONS = "You do not have permission %s";
-    private final static String MOCK_TO_DELETE = "to delete this file";
-    private final static String PATH_TO_DELETE = "/path/to/a.file";
-    private final static String EXPECTED_ERROR_MESSAGE = "You do not have permission to delete this file";
-    private final static String ACCOUNT_TYPE = "nextcloud";
-
-    @Mock
-    private Resources mMockResources;
-
-    @Test
-    public void getErrorCauseMessageForForbiddenRemoval() {
-        // Given a mocked set of resources passed to the object under test...
-        Mockito.when(mMockResources.getString(R.string.forbidden_permissions))
-            .thenReturn(MOCK_FORBIDDEN_PERMISSIONS);
-        Mockito.when(mMockResources.getString(R.string.forbidden_permissions_delete))
-            .thenReturn(MOCK_TO_DELETE);
-
-        Account account = new Account("name", ACCOUNT_TYPE);
-
-        // ... when method under test is called ...
-        String errorMessage = ErrorMessageAdapter.getErrorCauseMessage(
-            new RemoteOperationResult(RemoteOperationResult.ResultCode.FORBIDDEN),
-                new RemoveFileOperation(PATH_TO_DELETE, false, account, false, MainApp.getAppContext()),
-            mMockResources
-        );
-
-        // ... then the result should be the expected one.
-        assertThat(errorMessage, is(EXPECTED_ERROR_MESSAGE));
-
-    }
-}