From 4e78a5f3e8a60bc129fee10ccaf669212e31e00e Mon Sep 17 00:00:00 2001 From: davigonz Date: Fri, 1 Mar 2019 13:10:37 +0100 Subject: [PATCH] Use openfortesting for new Kotlin files needed in tests --- owncloudComLibrary/build.gradle | 7 +++++ .../android/lib/testing/OpenForTesting.kt | 31 +++++++++++++++++++ .../lib/resources/status/OwnCloudVersion.kt | 4 ++- 3 files changed, 41 insertions(+), 1 deletion(-) create mode 100644 owncloudComLibrary/src/debug/java/com/owncloud/android/lib/testing/OpenForTesting.kt diff --git a/owncloudComLibrary/build.gradle b/owncloudComLibrary/build.gradle index 3b04c31f..463d135a 100644 --- a/owncloudComLibrary/build.gradle +++ b/owncloudComLibrary/build.gradle @@ -2,12 +2,19 @@ apply plugin: 'com.android.library' apply plugin: 'kotlin-android' apply plugin: 'kotlin-kapt' +apply plugin: 'kotlin-allopen' + dependencies { api 'com.squareup.okhttp3:okhttp:3.12.0' implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlinVersion" api 'com.gitlab.ownclouders:dav4android:oc_support_1.0.1' } +allOpen { + // allows mocking for classes w/o directly opening them for release builds + annotation 'com.owncloud.android.lib.testing.OpenClass' +} + android { compileSdkVersion 28 diff --git a/owncloudComLibrary/src/debug/java/com/owncloud/android/lib/testing/OpenForTesting.kt b/owncloudComLibrary/src/debug/java/com/owncloud/android/lib/testing/OpenForTesting.kt new file mode 100644 index 00000000..3c91e836 --- /dev/null +++ b/owncloudComLibrary/src/debug/java/com/owncloud/android/lib/testing/OpenForTesting.kt @@ -0,0 +1,31 @@ +/* + * Copyright (C) 2018 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.owncloud.android.lib.testing + +/** + * This annotation allows us to open some classes for mocking purposes while they are final in + * release builds. + */ +@Target(AnnotationTarget.ANNOTATION_CLASS) +annotation class OpenClass + +/** + * Annotate a class with [OpenForTesting] if you want it to be extendable in debug builds. + */ +@OpenClass +@Target(AnnotationTarget.CLASS) +annotation class OpenForTesting diff --git a/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/status/OwnCloudVersion.kt b/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/status/OwnCloudVersion.kt index 80b8814e..8b09859e 100644 --- a/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/status/OwnCloudVersion.kt +++ b/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/status/OwnCloudVersion.kt @@ -27,7 +27,9 @@ package com.owncloud.android.lib.resources.status import android.os.Parcel import android.os.Parcelable +import com.owncloud.android.lib.testing.OpenForTesting +@OpenForTesting class OwnCloudVersion(version: String) : Comparable, Parcelable { // format is in version @@ -36,7 +38,7 @@ class OwnCloudVersion(version: String) : Comparable, Parcelable // ie version 2.0.3 will be stored as 0x02000300 private var mVersion: Int = 0 var isVersionValid: Boolean = false - private set + set val version: String get() = if (isVersionValid) {