From 9ad9d4fc85cbca516fdaf8f0b32bb37513406e57 Mon Sep 17 00:00:00 2001 From: Jose Alcerreca Date: Mon, 26 Feb 2018 11:04:44 +0100 Subject: [PATCH] New module :test-shared + gradle cleanup Bug: 72216577 Change-Id: I4de13f1b6f37e458df46b39106d24c3a1d349b7f --- build.gradle | 11 +++++ mobile/build.gradle | 7 +++ .../{ => test}/util/SyncTaskExecutorRule.kt | 4 +- .../ui/schedule/ScheduleViewModelTest.kt | 4 +- settings.gradle | 2 +- shared/build.gradle | 20 ++++---- .../iosched/ui/schedule/SessionFilters.kt | 2 +- .../iosched/ui/schedule/SessionFiltersTest.kt | 4 +- test-shared/.gitignore | 1 + test-shared/build.gradle | 48 +++++++++++++++++++ test-shared/proguard-rules.pro | 21 ++++++++ test-shared/src/main/AndroidManifest.xml | 18 +++++++ .../iosched/test}/util/LiveDataTestUtil.kt | 2 +- tv/build.gradle | 7 +++ 14 files changed, 133 insertions(+), 18 deletions(-) rename mobile/src/test/java/com/google/samples/apps/iosched/{ => test}/util/SyncTaskExecutorRule.kt (93%) create mode 100644 test-shared/.gitignore create mode 100644 test-shared/build.gradle create mode 100644 test-shared/proguard-rules.pro create mode 100644 test-shared/src/main/AndroidManifest.xml rename {mobile/src/test/java/com/google/samples/apps/iosched => test-shared/src/main/java/com/google/samples/apps/iosched/test}/util/LiveDataTestUtil.kt (96%) diff --git a/build.gradle b/build.gradle index 874df6f7c6..45e4497f47 100644 --- a/build.gradle +++ b/build.gradle @@ -68,3 +68,14 @@ task clean(type: Delete) { delete rootProject.buildDir } +// Force all of the primary support libraries to use the same version. +configurations.all { + resolutionStrategy { + eachDependency { details -> + if (details.requested.group == 'com.android.support') { + details.useVersion supportLibraryVersion + } + } + } +} + diff --git a/mobile/build.gradle b/mobile/build.gradle index 1943558302..166a1e50da 100644 --- a/mobile/build.gradle +++ b/mobile/build.gradle @@ -40,6 +40,12 @@ android { staging { initWith debug + + // Specifies a sorted list of fallback build types that the + // plugin should try to use when a dependency does not include a + // "staging" build type. + // Used with :test-shared, which doesn't have a staging variant. + matchingFallbacks = ['debug'] } } dataBinding { @@ -49,6 +55,7 @@ android { dependencies { implementation project(":shared") + testImplementation project(':test-shared') implementation fileTree(dir: 'libs', include: ['*.jar']) diff --git a/mobile/src/test/java/com/google/samples/apps/iosched/util/SyncTaskExecutorRule.kt b/mobile/src/test/java/com/google/samples/apps/iosched/test/util/SyncTaskExecutorRule.kt similarity index 93% rename from mobile/src/test/java/com/google/samples/apps/iosched/util/SyncTaskExecutorRule.kt rename to mobile/src/test/java/com/google/samples/apps/iosched/test/util/SyncTaskExecutorRule.kt index 64708393a8..fad430f0e3 100644 --- a/mobile/src/test/java/com/google/samples/apps/iosched/util/SyncTaskExecutorRule.kt +++ b/mobile/src/test/java/com/google/samples/apps/iosched/test/util/SyncTaskExecutorRule.kt @@ -14,7 +14,7 @@ * limitations under the License. */ -package com.google.samples.apps.iosched.util +package com.google.samples.apps.iosched.test.util import com.google.samples.apps.iosched.shared.usecases.internal.DefaultScheduler import com.google.samples.apps.iosched.shared.usecases.internal.SyncScheduler @@ -23,8 +23,6 @@ import org.junit.runner.Description /** * Rule to be used in tests that sets a synchronous task scheduler used to avoid race conditions. - * - * TODO: Move to testutils module b/72216577 */ class SyncTaskExecutorRule : TestWatcher() { override fun starting(description: Description?) { diff --git a/mobile/src/test/java/com/google/samples/apps/iosched/ui/schedule/ScheduleViewModelTest.kt b/mobile/src/test/java/com/google/samples/apps/iosched/ui/schedule/ScheduleViewModelTest.kt index 5a17598f85..f1bbda6e30 100644 --- a/mobile/src/test/java/com/google/samples/apps/iosched/ui/schedule/ScheduleViewModelTest.kt +++ b/mobile/src/test/java/com/google/samples/apps/iosched/ui/schedule/ScheduleViewModelTest.kt @@ -25,8 +25,8 @@ import com.google.samples.apps.iosched.shared.data.tag.TagRepository import com.google.samples.apps.iosched.shared.model.Session import com.google.samples.apps.iosched.shared.model.Tag import com.google.samples.apps.iosched.shared.util.TimeUtils.ConferenceDay -import com.google.samples.apps.iosched.util.LiveDataTestUtil -import com.google.samples.apps.iosched.util.SyncTaskExecutorRule +import com.google.samples.apps.iosched.test.util.SyncTaskExecutorRule +import com.google.samples.apps.iosched.test.util.LiveDataTestUtil import org.junit.Assert.assertEquals import org.junit.Assert.assertFalse import org.junit.Assert.assertTrue diff --git a/settings.gradle b/settings.gradle index 824ff3427e..3908250aeb 100644 --- a/settings.gradle +++ b/settings.gradle @@ -14,4 +14,4 @@ * limitations under the License. */ -include ':mobile', ':shared', ':tv' +include ':mobile', ':tv', ':shared', ':test-shared' diff --git a/shared/build.gradle b/shared/build.gradle index 0ad4374552..550a70c9f1 100644 --- a/shared/build.gradle +++ b/shared/build.gradle @@ -50,16 +50,12 @@ android { dataBinding { enabled true } + } dependencies { implementation fileTree(dir: 'libs', include: ['*.jar']) - // UI - implementation "com.android.support:appcompat-v7:$rootProject.supportLibraryVersion" - implementation "com.android.support:support-v4:$rootProject.supportLibraryVersion" - implementation "com.android.support.constraint:constraint-layout:$rootProject.constraintLayoutVersion" - // Architecture Components implementation "android.arch.lifecycle:extensions:$rootProject.archLifecycleVersion" implementation "android.arch.lifecycle:livedata:$rootProject.archLifecycleVersion" @@ -78,6 +74,7 @@ dependencies { kapt "com.google.dagger:dagger-compiler:$rootProject.dagger" kapt "com.google.dagger:dagger-android-processor:$rootProject.dagger" + // ThreeTenBP for the shared module only. Date and time API for Java. testImplementation "org.threeten:threetenbp:$rootProject.threetenbpVersion" compileOnly "org.threeten:threetenbp:$rootProject.threetenbpVersion:no-tzdb" @@ -85,8 +82,15 @@ dependencies { // Unit tests testImplementation "android.arch.core:core-testing:$rootProject.archLifecycleVersion" testImplementation "junit:junit:$rootProject.junitVersion" +} - // Instrumentation tests - androidTestImplementation "com.android.support.test.espresso:espresso-core:$rootProject.espressoVersion" - androidTestImplementation "com.android.support.test:runner:$rootProject.runnerVersion" +// Force Dagger's transitive dependencies to use the project's version of the support libraries. +configurations.all { + resolutionStrategy { + eachDependency { details -> + if (details.requested.group == 'com.android.support') { + details.useVersion supportLibraryVersion + } + } + } } diff --git a/shared/src/main/java/com/google/samples/apps/iosched/ui/schedule/SessionFilters.kt b/shared/src/main/java/com/google/samples/apps/iosched/ui/schedule/SessionFilters.kt index 878ab5e4b2..62d42c2a18 100644 --- a/shared/src/main/java/com/google/samples/apps/iosched/ui/schedule/SessionFilters.kt +++ b/shared/src/main/java/com/google/samples/apps/iosched/ui/schedule/SessionFilters.kt @@ -40,7 +40,7 @@ class SessionFilters { */ fun matchesSessionTags(sessionTags: List): Boolean { var match = true - filteredTags.groupBy { it.category }.forEach { category, tagsInCategory -> + filteredTags.groupBy { it.category }.forEach { _, tagsInCategory -> if (sessionTags.intersect(tagsInCategory).isEmpty()) { match = false return@forEach diff --git a/shared/src/test/java/com/google/samples/apps/iosched/ui/schedule/SessionFiltersTest.kt b/shared/src/test/java/com/google/samples/apps/iosched/ui/schedule/SessionFiltersTest.kt index 780899d7f5..50f0e62ecb 100644 --- a/shared/src/test/java/com/google/samples/apps/iosched/ui/schedule/SessionFiltersTest.kt +++ b/shared/src/test/java/com/google/samples/apps/iosched/ui/schedule/SessionFiltersTest.kt @@ -17,8 +17,8 @@ package com.google.samples.apps.iosched.ui.schedule import com.google.samples.apps.iosched.shared.model.Tag -import junit.framework.Assert.assertFalse -import junit.framework.Assert.assertTrue +import org.junit.Assert.assertFalse +import org.junit.Assert.assertTrue import org.junit.Before import org.junit.Test diff --git a/test-shared/.gitignore b/test-shared/.gitignore new file mode 100644 index 0000000000..796b96d1c4 --- /dev/null +++ b/test-shared/.gitignore @@ -0,0 +1 @@ +/build diff --git a/test-shared/build.gradle b/test-shared/build.gradle new file mode 100644 index 0000000000..ca5172de5e --- /dev/null +++ b/test-shared/build.gradle @@ -0,0 +1,48 @@ +/* + * Copyright 2018 Google LLC + * + * 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 + * + * https://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. + */ + +apply plugin: 'com.android.library' +apply plugin: 'kotlin-android' + +android { + compileSdkVersion rootProject.compileSdkVersion + defaultConfig { + minSdkVersion rootProject.minSdkVersion + targetSdkVersion rootProject.targetSdkVersion + versionCode 1 + versionName "1.0" + testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" + + } + + buildTypes { + release { + minifyEnabled false + proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' + } + } +} + +dependencies { + + // Kotlin + implementation "org.jetbrains.kotlin:kotlin-stdlib-jre7:$rootProject.kotlinVersion" + + // Architecture Components + implementation "android.arch.lifecycle:extensions:$rootProject.archLifecycleVersion" + implementation "android.arch.lifecycle:livedata:$rootProject.archLifecycleVersion" + implementation "android.arch.lifecycle:viewmodel:$rootProject.archLifecycleVersion" +} diff --git a/test-shared/proguard-rules.pro b/test-shared/proguard-rules.pro new file mode 100644 index 0000000000..f1b424510d --- /dev/null +++ b/test-shared/proguard-rules.pro @@ -0,0 +1,21 @@ +# Add project specific ProGuard rules here. +# You can control the set of applied configuration files using the +# proguardFiles setting in build.gradle. +# +# For more details, see +# http://developer.android.com/guide/developing/tools/proguard.html + +# If your project uses WebView with JS, uncomment the following +# and specify the fully qualified class name to the JavaScript interface +# class: +#-keepclassmembers class fqcn.of.javascript.interface.for.webview { +# public *; +#} + +# Uncomment this to preserve the line number information for +# debugging stack traces. +#-keepattributes SourceFile,LineNumberTable + +# If you keep the line number information, uncomment this to +# hide the original source file name. +#-renamesourcefileattribute SourceFile diff --git a/test-shared/src/main/AndroidManifest.xml b/test-shared/src/main/AndroidManifest.xml new file mode 100644 index 0000000000..14ccef158a --- /dev/null +++ b/test-shared/src/main/AndroidManifest.xml @@ -0,0 +1,18 @@ + + + diff --git a/mobile/src/test/java/com/google/samples/apps/iosched/util/LiveDataTestUtil.kt b/test-shared/src/main/java/com/google/samples/apps/iosched/test/util/LiveDataTestUtil.kt similarity index 96% rename from mobile/src/test/java/com/google/samples/apps/iosched/util/LiveDataTestUtil.kt rename to test-shared/src/main/java/com/google/samples/apps/iosched/test/util/LiveDataTestUtil.kt index 1978046d11..fd74a3d257 100644 --- a/mobile/src/test/java/com/google/samples/apps/iosched/util/LiveDataTestUtil.kt +++ b/test-shared/src/main/java/com/google/samples/apps/iosched/test/util/LiveDataTestUtil.kt @@ -14,7 +14,7 @@ * limitations under the License. */ -package com.google.samples.apps.iosched.util +package com.google.samples.apps.iosched.test.util import android.arch.lifecycle.LiveData import android.arch.lifecycle.Observer diff --git a/tv/build.gradle b/tv/build.gradle index cc66a050ce..4726c77395 100644 --- a/tv/build.gradle +++ b/tv/build.gradle @@ -38,6 +38,12 @@ android { staging { initWith debug + + // Specifies a sorted list of fallback build types that the + // plugin should try to use when a dependency does not include a + // "staging" build type. + // Used with :test-shared, which doesn't have a staging variant. + matchingFallbacks = ['debug'] } } dataBinding { @@ -47,6 +53,7 @@ android { dependencies { implementation project(":shared") + testImplementation project(':test-shared') // UI implementation "com.android.support:appcompat-v7:$rootProject.supportLibraryVersion"