Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -379,6 +379,7 @@ Generally, whenever you need:
* media playback
* networking
* logging
* notifications management

we have something more suitable.

Expand Down
19 changes: 15 additions & 4 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -357,7 +357,9 @@ dependencies {
testImplementation 'org.powermock:powermock-api-mockito2:2.0.7'
testImplementation 'org.json:json:20200518'
testImplementation "com.nhaarman.mockitokotlin2:mockito-kotlin:2.2.0"
testImplementation "androidx.arch.core:core-testing:2.1.0"
testImplementation 'androidx.arch.core:core-testing:2.1.0'
testImplementation 'io.mockk:mockk:1.10.0'
testImplementation 'io.mockk:mockk-android:1.10.0'

// dependencies for instrumented tests
// JUnit4 Rules
Expand All @@ -370,7 +372,19 @@ dependencies {
// Espresso core
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
androidTestImplementation 'androidx.test.espresso:espresso-contrib:3.2.0'

// Mocking support
androidTestImplementation 'com.github.tmurakami:dexopener:2.0.5' // required to allow mocking on API 27 and older
androidTestImplementation "com.nhaarman.mockitokotlin2:mockito-kotlin:2.2.0"
androidTestImplementation 'org.mockito:mockito-core:3.4.4'
androidTestImplementation("org.mockito:mockito-android:3.3.3") {
exclude group: "net.bytebuddy", module: "byte-buddy-android"
}
androidTestImplementation 'net.bytebuddy:byte-buddy:1.10.13'
androidTestImplementation "net.bytebuddy:byte-buddy-android:1.10.10"
androidTestImplementation "io.mockk:mockk-android:1.10.0"
androidTestImplementation 'androidx.arch.core:core-testing:2.0.1'

// 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
Expand All @@ -388,9 +402,6 @@ dependencies {
// androidJacocoAnt "org.jacoco:org.jacoco.agent:${jacocoVersion}"

implementation "com.github.stateless4j:stateless4j:2.6.0"
androidTestImplementation "com.nhaarman.mockitokotlin2:mockito-kotlin:2.2.0"
androidTestImplementation "org.mockito:mockito-android:3.4.4"
androidTestImplementation 'net.bytebuddy:byte-buddy:1.10.13'
}

spotbugs {
Expand Down
12 changes: 6 additions & 6 deletions detekt.yml
Original file line number Diff line number Diff line change
Expand Up @@ -83,14 +83,14 @@ complexity:
ignoreStringsRegex: '$^'
TooManyFunctions:
active: true
thresholdInFiles: 11
thresholdInClasses: 11
thresholdInInterfaces: 11
thresholdInObjects: 11
thresholdInFiles: 15
thresholdInClasses: 15
thresholdInInterfaces: 15
thresholdInObjects: 15
thresholdInEnums: 11
ignoreDeprecated: false
ignoreDeprecated: true
ignorePrivate: false
ignoreOverridden: false
ignoreOverridden: true

empty-blocks:
active: true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,33 @@

package com.nextcloud.client;

import android.app.Application;
import android.content.Context;
import android.os.Build;
import android.os.Bundle;

import com.facebook.testing.screenshot.ScreenshotRunner;
import com.github.tmurakami.dexopener.DexOpener;

import androidx.test.runner.AndroidJUnitRunner;

public class ScreenshotTestRunner extends AndroidJUnitRunner {

@Override
public Application newApplication(ClassLoader cl, String className, Context context)
throws ClassNotFoundException, IllegalAccessException, InstantiationException {

/*
* Initialize DexOpener only on API below 28 to enable mocking of Kotlin classes.
* On API 28+ the platform supports mocking natively.
*/
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.P) {
DexOpener.install(this);
}

return super.newApplication(cl, className, context);
}

@Override
public void onCreate(Bundle args) {
super.onCreate(args);
Expand Down
71 changes: 71 additions & 0 deletions src/androidTest/java/com/nextcloud/client/account/MockUserTest.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
/*
* Nextcloud Android client application
*
* @author Chris Narkiewicz <hello@ezaquarii.com>
* Copyright (C) 2020 Chris Narkiewicz
* Copyright (C) 2020 Nextcloud GmbH
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* 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 Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package com.nextcloud.client.account

import android.os.Parcel
import org.junit.Assert.assertEquals
import org.junit.Assert.assertNotSame
import org.junit.Assert.assertTrue
import org.junit.Test

class MockUserTest {

private companion object {
const val ACCOUNT_NAME = "test_account_name"
const val ACCOUNT_TYPE = "test_account_type"
}

@Test
fun mock_user_is_parcelable() {
// GIVEN
// mock user instance
val original = MockUser(ACCOUNT_NAME, ACCOUNT_TYPE)

// WHEN
// instance is serialized into Parcel
// instance is retrieved from Parcel
val parcel = Parcel.obtain()
parcel.setDataPosition(0)
parcel.writeParcelable(original, 0)
parcel.setDataPosition(0)
val retrieved = parcel.readParcelable<User>(User::class.java.classLoader)

// THEN
// retrieved instance in distinct
// instances are equal
assertNotSame(original, retrieved)
assertTrue(retrieved is MockUser)
assertEquals(original, retrieved)
}

@Test
fun mock_user_has_platform_account() {
// GIVEN
// mock user instance
val mock = MockUser(ACCOUNT_NAME, ACCOUNT_TYPE)

// THEN
// can convert to platform account
val account = mock.toPlatformAccount()
assertEquals(ACCOUNT_NAME, account.name)
assertEquals(ACCOUNT_TYPE, account.type)
}
}
Loading