Skip to content

Commit

Permalink
Introduce fluxc-tests module
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
wzieba committed Jan 17, 2025
1 parent 4147a37 commit 2f75caf
Show file tree
Hide file tree
Showing 9 changed files with 120 additions and 287 deletions.
2 changes: 1 addition & 1 deletion WooCommerce-Wear/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion WooCommerce/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
23 changes: 1 addition & 22 deletions libs/fluxc-plugin/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
231 changes: 113 additions & 118 deletions libs/fluxc-tests/build.gradle
Original file line number Diff line number Diff line change
@@ -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"

Expand Down Expand Up @@ -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()
Expand Down
Loading

0 comments on commit 2f75caf

Please sign in to comment.