From 2f75cafbef393d77c233baf5bda8e35c13410c55 Mon Sep 17 00:00:00 2001 From: Wojtek Zieba Date: Wed, 15 Jan 2025 17:33:42 +0100 Subject: [PATCH] Introduce `fluxc-tests` module Which contains all unit tests from original `example` module. Also, this commit adds a number of changes to make unit tests run. `ArrayUtilsTest` is removed as `ArrayUtils` was an example-app only class. --- WooCommerce-Wear/build.gradle | 2 +- WooCommerce/build.gradle | 2 +- libs/fluxc-plugin/build.gradle | 23 +- .../fluxc/processor/EndpointProcessor.java | 2 +- libs/fluxc-tests/build.gradle | 231 +++++++++--------- .../fluxc/example/utils/ArrayUtilsTest.kt | 83 ------- libs/fluxc/build.gradle | 24 +- libs/login/build.gradle | 38 --- settings.gradle | 2 +- 9 files changed, 120 insertions(+), 287 deletions(-) delete mode 100644 libs/fluxc-tests/src/test/java/org/wordpress/android/fluxc/example/utils/ArrayUtilsTest.kt diff --git a/WooCommerce-Wear/build.gradle b/WooCommerce-Wear/build.gradle index 4a81ec232ee..a65a9b1ac46 100644 --- a/WooCommerce-Wear/build.gradle +++ b/WooCommerce-Wear/build.gradle @@ -125,7 +125,7 @@ dependencies { // Project implementation project(":libs:commons") implementation(project(":libs:fluxc")) - implementation(project(":libs:plugins:woocommerce")) + implementation(project(":libs:fluxc-plugin")) implementation(libs.wordpress.utils) { exclude group: "com.mcxiaoke.volley" exclude group: "com.android.support" diff --git a/WooCommerce/build.gradle b/WooCommerce/build.gradle index 94032a80287..a46dfec683a 100644 --- a/WooCommerce/build.gradle +++ b/WooCommerce/build.gradle @@ -246,7 +246,7 @@ dependencies { implementation(libs.automattic.tracks.crashlogging) implementation(project(":libs:fluxc")) - implementation(project(":libs:plugins:woocommerce")) + implementation(project(":libs:fluxc-plugin")) implementation(project(":libs:login")) implementation(libs.wordpress.aztec.main) { diff --git a/libs/fluxc-plugin/build.gradle b/libs/fluxc-plugin/build.gradle index 9d68256a86d..846f0aae784 100644 --- a/libs/fluxc-plugin/build.gradle +++ b/libs/fluxc-plugin/build.gradle @@ -4,28 +4,6 @@ plugins { alias(libs.plugins.kotlin.kapt) } -repositories { - maven { - url 'https://a8c-libs.s3.amazonaws.com/android' - content { - includeGroup "org.wordpress" - includeGroup "org.wordpress.fluxc" - includeGroup "org.wordpress.fluxc.plugins" - includeGroup "org.wordpress.wellsql" - includeGroup "org.wordpress.mediapicker" - includeGroup "com.automattic" - includeGroup "com.automattic.tracks" - } - } - - maven { - url "https://a8c-libs.s3.amazonaws.com/android/jcenter-mirror" - content { - includeVersion "com.android.volley", "volley", "1.1.1" - } - } -} - android { namespace "org.wordpress.android.fluxc.plugins.woocommerce" @@ -105,6 +83,7 @@ dependencies { testImplementation libs.mockito.core testImplementation libs.mockito.kotlin testImplementation libs.kotlinx.coroutines.test + testImplementation libs.kotlin.test.junit androidTestImplementation libs.androidx.room.testing androidTestImplementation libs.androidx.test.main.runner diff --git a/libs/fluxc-processor/src/main/java/org/wordpress/android/fluxc/processor/EndpointProcessor.java b/libs/fluxc-processor/src/main/java/org/wordpress/android/fluxc/processor/EndpointProcessor.java index ea9122c6029..612f0f1e677 100644 --- a/libs/fluxc-processor/src/main/java/org/wordpress/android/fluxc/processor/EndpointProcessor.java +++ b/libs/fluxc-processor/src/main/java/org/wordpress/android/fluxc/processor/EndpointProcessor.java @@ -91,7 +91,7 @@ public void init(ProcessingEnvironment processingEnv) { generateWPAPIEndpointFile(); generateWPORGAPIEndpointFile(); generateJPAPIEndpointFile(); - } else if (outputPath.contains(fs + "plugins" + fs + "woocommerce" + fs + "build" + fs)) { + } else if (outputPath.contains(fs + "libs" + fs + "fluxc-plugin" + fs + "build" + fs)) { generateWCWPAPIPluginEndpointFile(); } } catch (IOException e) { diff --git a/libs/fluxc-tests/build.gradle b/libs/fluxc-tests/build.gradle index 4dd86c85b28..7f88ea9b1b8 100644 --- a/libs/fluxc-tests/build.gradle +++ b/libs/fluxc-tests/build.gradle @@ -1,28 +1,23 @@ plugins { - alias(sharedLibs.plugins.android.application) - alias(sharedLibs.plugins.kotlin.android) - alias(sharedLibs.plugins.kotlin.parcelize) - alias(sharedLibs.plugins.kotlin.kapt) + alias(libs.plugins.android.library) + alias(libs.plugins.kotlin.android) + alias(libs.plugins.kotlin.parcelize) + alias(libs.plugins.kotlin.kapt) } android { namespace "org.wordpress.android.fluxc.example" - compileSdkVersion rootProject.compileSdkVersion + compileSdkVersion gradle.ext.compileSdkVersion compileOptions { - sourceCompatibility JavaVersion.VERSION_1_8 - targetCompatibility JavaVersion.VERSION_1_8 - } - - kotlinOptions { - jvmTarget = JavaVersion.VERSION_1_8.toString() + sourceCompatibility libs.versions.java.get() + targetCompatibility libs.versions.java.get() } defaultConfig { - applicationId "org.wordpress.android.fluxc.example" - minSdkVersion rootProject.minSdkVersion - targetSdkVersion rootProject.targetSdkVersion + minSdkVersion gradle.ext.minSdkVersion + targetSdkVersion gradle.ext.targetSdkVersion versionCode 1 versionName "1.0" @@ -64,131 +59,131 @@ android { enable += 'UnknownNullness' } - buildFeatures { - buildConfig true - viewBinding true - compose true - } +// buildFeatures { +// buildConfig true +// viewBinding true +// compose true +// } - composeOptions { - kotlinCompilerExtensionVersion = sharedLibs.versions.androidx.compose.compiler.get() - } +// composeOptions { +// kotlinCompilerExtensionVersion = sharedLibs.versions.androidx.compose.compiler.get() +// } - sourceSets { - // Adds exported schema location as test app assets. - getByName("androidTest").assets.srcDirs += "$projectDir/../fluxc/schemas" - } -} - -if (["tests.properties", "tests.properties-extra"].any { file(it).exists() }) { - throw new InvalidUserDataException("'example/tests.properties' and 'example/tests.properties-extra' property files are deprecated. Please see 'example/properties-example/README.md' for details.") -} - -android.buildTypes.all { buildType -> - // Add properties named "wp.xxx" to our BuildConfig - Properties apiProperties = loadPropertiesOrUseExampleProperties("api.properties", - "example app can't access WordPress.com servers") - apiProperties.any { property -> - if (property.key.toLowerCase().startsWith("wp.")) { - buildType.buildConfigField "String", property.key.replace("wp.", "").replace(".", "_").toUpperCase(), - "\"${property.value}\"" - } - } - - // Load test properties and add them to BuildConfig - Properties testProperties = loadPropertiesOrUseExampleProperties("tests.properties", - "tests won't pass") - testProperties.any { property -> - buildType.buildConfigField "String", property.key.replace(".", "_").toUpperCase(), "\"${property.value}\"" - } +// sourceSets { +// // Adds exported schema location as test app assets. +// getByName("androidTest").assets.srcDirs += "$projectDir/../fluxc/schemas" +// } } +//if (["tests.properties", "tests.properties-extra"].any { file(it).exists() }) { +// throw new InvalidUserDataException("'example/tests.properties' and 'example/tests.properties-extra' property files are deprecated. Please see 'example/properties-example/README.md' for details.") +//} +// +//android.buildTypes.all { buildType -> +// // Add properties named "wp.xxx" to our BuildConfig +// Properties apiProperties = loadPropertiesOrUseExampleProperties("api.properties", +// "example app can't access WordPress.com servers") +// apiProperties.any { property -> +// if (property.key.toLowerCase().startsWith("wp.")) { +// buildType.buildConfigField "String", property.key.replace("wp.", "").replace(".", "_").toUpperCase(), +// "\"${property.value}\"" +// } +// } +// +// // Load test properties and add them to BuildConfig +// Properties testProperties = loadPropertiesOrUseExampleProperties("tests.properties", +// "tests won't pass") +// testProperties.any { property -> +// buildType.buildConfigField "String", property.key.replace(".", "_").toUpperCase(), "\"${property.value}\"" +// } +//} +// dependencies { - implementation project(':fluxc') - implementation project(':plugins:woocommerce') + implementation project(':libs:fluxc') + implementation project(':libs:fluxc-plugin') - implementation sharedLibs.androidx.appcompat - implementation sharedLibs.androidx.swiperefreshlayout - implementation sharedLibs.androidx.recyclerview - implementation sharedLibs.androidx.constraintlayout - implementation sharedLibs.androidx.annotation - implementation sharedLibs.androidx.lifecycle.runtime.ktx +// implementation libs.androidx.appcompat +// implementation libs.androidx.swiperefreshlayout +// implementation libs.androidx.recyclerview +// implementation libs.androidx.constraintlayout +// implementation libs.androidx.annotation +// implementation libs.androidx.lifecycle.runtime.ktx - implementation(sharedLibs.wordpress.utils) { + testImplementation(libs.wordpress.utils) { // Using official volley package exclude group: "com.mcxiaoke.volley" exclude group: "com.android.support" } - implementation sharedLibs.google.gson + testImplementation libs.google.gson - testImplementation sharedLibs.androidx.room.runtime - androidTestImplementation sharedLibs.androidx.room.runtime - androidTestImplementation sharedLibs.androidx.room.testing + testImplementation libs.androidx.room.runtime +// androidTestImplementation libs.androidx.room.runtime +// androidTestImplementation libs.androidx.room.testing // Dagger - implementation sharedLibs.google.dagger - kapt sharedLibs.google.dagger.compiler - compileOnly sharedLibs.glassfish.javax.annotation - implementation sharedLibs.google.dagger.android.support - kapt sharedLibs.google.dagger.android.processor - - testImplementation sharedLibs.junit - testImplementation sharedLibs.kotlin.test.junit - testImplementation sharedLibs.robolectric - testImplementation sharedLibs.androidx.test.core - testImplementation sharedLibs.mockito.core - testImplementation sharedLibs.mockito.kotlin - testImplementation sharedLibs.assertj.core - testImplementation sharedLibs.androidx.arch.core.testing - - implementation platform(sharedLibs.androidx.compose.bom) - implementation sharedLibs.androidx.compose.material - implementation sharedLibs.androidx.compose.ui.tooling - - androidTestImplementation sharedLibs.assertj.core - androidTestImplementation sharedLibs.androidx.arch.core.testing - androidTestCompileOnly sharedLibs.glassfish.javax.annotation - // Test orchestrator - androidTestImplementation sharedLibs.androidx.test.runner - androidTestUtil sharedLibs.androidx.test.orchestrator - - androidTestImplementation "com.goterl:lazysodium-android:5.0.2@aar" - androidTestImplementation "net.java.dev.jna:jna:5.5.0@aar" +// implementation libs.google.dagger +// kapt libs.google.dagger.compiler +// compileOnly libs.glassfish.javax.annotation +// implementation libs.google.dagger.android.support +// kapt libs.google.dagger.android.processor + + testImplementation libs.junit + testImplementation libs.kotlin.test.junit + testImplementation libs.robolectric + testImplementation libs.androidx.test.main.core + testImplementation libs.mockito.core + testImplementation libs.mockito.kotlin + testImplementation libs.assertj.core + testImplementation libs.androidx.arch.core.testing + +// implementation platform(libs.androidx.compose.bom) +// implementation libs.androidx.compose.material +// implementation libs.androidx.compose.ui.tooling + +// androidTestImplementation libs.assertj.core +// androidTestImplementation libs.androidx.arch.core.testing +// androidTestCompileOnly libs.glassfish.javax.annotation +// // Test orchestrator +// androidTestImplementation libs.androidx.test.runner +// androidTestUtil libs.androidx.test.orchestrator + +// androidTestImplementation "com.goterl:lazysodium-android:5.0.2@aar" +// androidTestImplementation "net.java.dev.jna:jna:5.5.0@aar" // Debug dependencies - debugImplementation sharedLibs.facebook.flipper - debugImplementation sharedLibs.facebook.soloader - debugImplementation sharedLibs.facebook.flipper.network.plugin - +// debugImplementation libs.facebook.flipper +// debugImplementation libs.facebook.soloader +// debugImplementation libs.facebook.flipper.network.plugin +// // Coroutines - implementation sharedLibs.kotlinx.coroutines.core - implementation sharedLibs.kotlinx.coroutines.android - - lintChecks sharedLibs.wordpress.lint -} - -def loadPropertiesOrUseExampleProperties(fileName, warningDetail) { - Properties properties = new Properties() - File propertiesFile = file(propertiesFilePath(fileName)) - if (propertiesFile.exists()) { - properties.load(new InputStreamReader(new FileInputStream(propertiesFile), "utf-8")) - } else { - def examplePropertiesFilePath = examplePropertiesFilePath(fileName) - logger.quiet("WARNING: you're using the '$examplePropertiesFilePath' file - $warningDetail") - properties.load(new InputStreamReader(new FileInputStream(file(examplePropertiesFilePath)), "utf-8")) - } - return properties -} - -def propertiesFilePath(fileName) { - return "properties/$fileName" -} +// implementation libs.kotlinx.coroutines.core +// implementation libs.kotlinx.coroutines.android -def examplePropertiesFilePath(fileName) { - return "properties-example/$fileName" +// lintChecks libs.wordpress.lint } +//def loadPropertiesOrUseExampleProperties(fileName, warningDetail) { +// Properties properties = new Properties() +// File propertiesFile = file(propertiesFilePath(fileName)) +// if (propertiesFile.exists()) { +// properties.load(new InputStreamReader(new FileInputStream(propertiesFile), "utf-8")) +// } else { +// def examplePropertiesFilePath = examplePropertiesFilePath(fileName) +// logger.quiet("WARNING: you're using the '$examplePropertiesFilePath' file - $warningDetail") +// properties.load(new InputStreamReader(new FileInputStream(file(examplePropertiesFilePath)), "utf-8")) +// } +// return properties +//} +// +//def propertiesFilePath(fileName) { +// return "properties/$fileName" +//} +// +//def examplePropertiesFilePath(fileName) { +// return "properties-example/$fileName" +//} +// tasks.register("combineTestsPropertiesWithExtraTestsProperties") { doLast { Properties properties = new Properties() diff --git a/libs/fluxc-tests/src/test/java/org/wordpress/android/fluxc/example/utils/ArrayUtilsTest.kt b/libs/fluxc-tests/src/test/java/org/wordpress/android/fluxc/example/utils/ArrayUtilsTest.kt deleted file mode 100644 index 154ce6fcc09..00000000000 --- a/libs/fluxc-tests/src/test/java/org/wordpress/android/fluxc/example/utils/ArrayUtilsTest.kt +++ /dev/null @@ -1,83 +0,0 @@ -package org.wordpress.android.fluxc.example.utils - -import org.assertj.core.api.Assertions.assertThat - -import org.junit.Test - -class ArrayUtilsTest { - /* CONTAINS */ - - @Test - fun `given valid string, when checking contains start of array, then the result is true`() { - val stringArray = arrayOf("one", "two", "three", "four", "five") - - val result = ArrayUtils.contains(stringArray, "three") - - assertThat(result).isEqualTo(true) - } - - @Test - fun `given valid string, when checking contains middle of array, then the result is true`() { - val stringArray = arrayOf("one", "two", "three", "four", "five") - - val result = ArrayUtils.contains(stringArray, "one") - - assertThat(result).isEqualTo(true) - } - - @Test - fun `given valid string, when checking contains end of array, then the result is true`() { - val stringArray = arrayOf("one", "two", "three", "four", "five") - - val result = ArrayUtils.contains(stringArray, "five") - - assertThat(result).isEqualTo(true) - } - - @Test - fun `given invalid string, when checking contains of array, then the result is false`() { - val stringArray = arrayOf("one", "two", "three", "four", "five") - - val result = ArrayUtils.contains(stringArray, "ottff") - - assertThat(result).isEqualTo(false) - } - - /* INDEX OF */ - - @Test - fun `given valid string, when getting the index start of array, then the result is the expected one`() { - val stringArray = arrayOf("one", "two", "three", "four", "five") - - val result = ArrayUtils.indexOf(stringArray, "three") - - assertThat(result).isEqualTo(2) - } - - @Test - fun `given valid string, when getting the index middle of array, then the result is the expected one`() { - val stringArray = arrayOf("one", "two", "three", "four", "five") - - val result = ArrayUtils.indexOf(stringArray, "one") - - assertThat(result).isEqualTo(0) - } - - @Test - fun `given valid string, when getting the index end of array, then the result is the expected one`() { - val stringArray = arrayOf("one", "two", "three", "four", "five") - - val result = ArrayUtils.indexOf(stringArray, "five") - - assertThat(result).isEqualTo(4) - } - - @Test - fun `given invalid string, when getting the index of array, then the resulting index is minus one`() { - val stringArray = arrayOf("one", "two", "three", "four", "five") - - val result = ArrayUtils.indexOf(stringArray, "ottff") - - assertThat(result).isEqualTo(-1) - } -} diff --git a/libs/fluxc/build.gradle b/libs/fluxc/build.gradle index 81fd12a9562..fc6f6365a19 100644 --- a/libs/fluxc/build.gradle +++ b/libs/fluxc/build.gradle @@ -5,28 +5,6 @@ plugins { alias(libs.plugins.kotlin.kapt) } -repositories { - maven { - url 'https://a8c-libs.s3.amazonaws.com/android' - content { - includeGroup "org.wordpress" - includeGroup "org.wordpress.fluxc" - includeGroup "org.wordpress.fluxc.plugins" - includeGroup "org.wordpress.wellsql" - includeGroup "org.wordpress.mediapicker" - includeGroup "com.automattic" - includeGroup "com.automattic.tracks" - } - } - - maven { - url "https://a8c-libs.s3.amazonaws.com/android/jcenter-mirror" - content { - includeVersion "com.android.volley", "volley", "1.1.1" - } - } -} - android { useLibrary 'org.apache.http.legacy' @@ -142,6 +120,8 @@ dependencies { testImplementation libs.mockito.core testImplementation libs.mockito.kotlin testImplementation libs.mockito.inline + testImplementation libs.assertj.core + testImplementation libs.androidx.arch.core.testing lintChecks libs.wordpress.lint } diff --git a/libs/login/build.gradle b/libs/login/build.gradle index 31a2e087347..bf5b9faa007 100644 --- a/libs/login/build.gradle +++ b/libs/login/build.gradle @@ -4,44 +4,6 @@ plugins { id "org.jetbrains.kotlin.kapt" } -repositories { - maven { - url "https://a8c-libs.s3.amazonaws.com/android" - content { - includeGroup "org.wordpress" - includeGroup "org.wordpress.fluxc" - includeGroup "org.wordpress.wellsql" - includeGroup "com.gravatar" - } - } - mavenCentral() - google() - jcenter() - maven { url "https://www.jitpack.io" } -} - -repositories { - maven { - url 'https://a8c-libs.s3.amazonaws.com/android' - content { - includeGroup "org.wordpress" - includeGroup "org.wordpress.fluxc" - includeGroup "org.wordpress.fluxc.plugins" - includeGroup "org.wordpress.wellsql" - includeGroup "org.wordpress.mediapicker" - includeGroup "com.automattic" - includeGroup "com.automattic.tracks" - } - } - - maven { - url "https://a8c-libs.s3.amazonaws.com/android/jcenter-mirror" - content { - includeVersion "com.android.volley", "volley", "1.1.1" - } - } -} - android { compileOptions { sourceCompatibility libs.versions.java.get() diff --git a/settings.gradle b/settings.gradle index e6d6a509b1e..bd65125e8cd 100644 --- a/settings.gradle +++ b/settings.gradle @@ -75,7 +75,7 @@ include ':libs:commons' include ':libs:cardreader' include ':libs:apifaker' include ':WooCommerce' -include ':libs:fluxc', ':libs:fluxc-annotations', ':libs:fluxc-processor', ':libs:plugins:woocommerce' +include ':libs:fluxc', ':libs:fluxc-annotations', ':libs:fluxc-processor', ':libs:fluxc-plugin', ':libs:fluxc-tests' include ':libs:login'