diff --git a/formula-lint/src/test/java/com/instacart/formula/lint/WrongFormulaUsageDetectorTest.kt b/formula-lint/src/test/java/com/instacart/formula/lint/WrongFormulaUsageDetectorTest.kt index 3286e6c2f..a8c03f690 100644 --- a/formula-lint/src/test/java/com/instacart/formula/lint/WrongFormulaUsageDetectorTest.kt +++ b/formula-lint/src/test/java/com/instacart/formula/lint/WrongFormulaUsageDetectorTest.kt @@ -4,7 +4,9 @@ import com.android.tools.lint.checks.infrastructure.TestFile import com.android.tools.lint.checks.infrastructure.TestFiles.kotlin import com.android.tools.lint.checks.infrastructure.TestLintResult import com.android.tools.lint.checks.infrastructure.TestLintTask.lint +import com.android.tools.lint.checks.infrastructure.TestMode import com.instacart.formula.lint.WrongFormulaUsageDetector.Companion.issues +import com.intellij.lang.PsiBuilderUtil.expect import org.junit.Test class WrongFormulaUsageDetectorTest { @@ -95,6 +97,7 @@ class WrongFormulaUsageDetectorTest { return lint() .files(*array) .issues(*issues) + .skipTestModes(TestMode.SUPPRESSIBLE) .run() } diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index b45efb7d4..ad687780a 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -1,5 +1,5 @@ [versions] -android-gradle = "8.2.0" +android-gradle = "8.2.2" dokka-gradle = "1.9.10" kotlin = "1.9.10" @@ -10,12 +10,12 @@ compose-compiler = "1.5.3" androidX = "1.2.0" lifecycle = "2.2.0" -lifecycleKtx = '2.4.0-alpha03' +lifecycleKtx = '2.6.2' androidTest = "1.4.0" espresso = "3.4.0" robolectric = "4.11.1" -lint = "30.0.0" -autoService = "1.0-rc7" +lint = "31.2.2" +autoService = "1.1.1" [libraries] android-gradle = { module = "com.android.tools.build:gradle", version.ref = "android-gradle" } @@ -23,7 +23,7 @@ kotlin-gradle = { module = "org.jetbrains.kotlin:kotlin-gradle-plugin", version. dokka-gradle = { module = "org.jetbrains.dokka:dokka-gradle-plugin", version.ref = "dokka-gradle" } dokka-android-gradle = { module = "org.jetbrains.dokka:android-documentation-plugin", version.ref = "dokka-gradle" } maven-publish-gradle = { module = "com.vanniktech:gradle-maven-publish-plugin", version = "0.14.2" } -version-gradle = { module = "com.github.ben-manes:gradle-versions-plugin", version = "0.38.0" } +version-gradle = { module = "com.github.ben-manes:gradle-versions-plugin", version = "0.36.0" } # We need to fork the plugin to fix an incorrect usage of tasks.withType(Test) # https://github.com/vanniktech/gradle-android-junit-jacoco-plugin/compare/master...Laimiux:gradle-android-junit-jacoco-plugin:laimonas/gradle-8?expand=1 @@ -58,15 +58,15 @@ lifecycle-runtime-ktx = { module = "androidx.lifecycle:lifecycle-runtime-ktx", v espresso-core = { module = "androidx.test.espresso:espresso-core", version.ref = "espresso" } robolectric = { module = "org.robolectric:robolectric", version.ref = "robolectric" } -rxjava = { module = "io.reactivex.rxjava3:rxjava", version = "3.1.1" } +rxjava = { module = "io.reactivex.rxjava3:rxjava", version = "3.1.6" } rxandroid = { module = "io.reactivex.rxjava3:rxandroid", version = "3.0.0" } rxrelay = { module = "com.jakewharton.rxrelay3:rxrelay", version = "3.0.1" } -truth = { module = "com.google.truth:truth", version = "1.1.3" } +truth = { module = "com.google.truth:truth", version = "1.1.5" } junit = { module = "junit:junit", version = "4.13.2" } rxrelays = { module = "com.jakewharton.rxrelay3:rxrelay", version = "3.0.1" } -mockito-core = { module = "org.mockito:mockito-core", version = "5.7.0" } +mockito-core = { module = "org.mockito:mockito-core", version = "5.8.0" } mockito-kotlin = { module = "org.mockito.kotlin:mockito-kotlin", version = "5.2.1" } lint-core = { module = "com.android.tools.lint:lint", version.ref = "lint" } diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index bcc902a2f..2f5537019 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,6 +1,6 @@ #Wed Dec 13 14:59:32 PST 2023 distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-8.2-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-8.5-bin.zip zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists diff --git a/jacoco.sh b/jacoco.sh index 542fed57b..62696ba20 100755 --- a/jacoco.sh +++ b/jacoco.sh @@ -1,5 +1,5 @@ #!/bin/bash -# Should match with what we run in .circleci/config.yml +# Should match with what we run in .github/workflows/build-workflow.yml ./gradlew clean ./gradlew :formula:test ./gradlew :formula-android:testRelease diff --git a/jitpack.yml b/jitpack.yml index f78f664dd..7a1a87c79 100644 --- a/jitpack.yml +++ b/jitpack.yml @@ -1 +1,2 @@ -jdk: openjdk11 \ No newline at end of file +jdk: + - openjdk18 \ No newline at end of file diff --git a/samples/todoapp/build.gradle.kts b/samples/todoapp/build.gradle.kts index a9be059f0..941aa1fa4 100644 --- a/samples/todoapp/build.gradle.kts +++ b/samples/todoapp/build.gradle.kts @@ -43,8 +43,6 @@ dependencies { testImplementation(libs.junit) testImplementation(libs.truth) - testImplementation(libs.mockito.core) - testImplementation(libs.mockito.kotlin) testImplementation(libs.kotlin.reflect) testImplementation(project(":formula-test")) testImplementation(libs.androidx.test.runner) diff --git a/samples/todoapp/src/main/java/com/examples/todoapp/TodoAppComponent.kt b/samples/todoapp/src/main/java/com/examples/todoapp/TodoAppComponent.kt index 9c32e757e..0d755bffe 100644 --- a/samples/todoapp/src/main/java/com/examples/todoapp/TodoAppComponent.kt +++ b/samples/todoapp/src/main/java/com/examples/todoapp/TodoAppComponent.kt @@ -1,6 +1,7 @@ package com.examples.todoapp import com.examples.todoapp.data.TaskRepo +import com.examples.todoapp.data.TaskRepoImpl import com.examples.todoapp.tasks.TaskListFeatureFactory import com.examples.todoapp.tasks.TaskListFormula import com.instacart.formula.android.ActivityStoreContext @@ -8,7 +9,8 @@ import com.instacart.formula.android.ActivityStoreContext class TodoAppComponent( private val store: ActivityStoreContext ) : TaskListFeatureFactory.Dependencies { - private val repo: TaskRepo = TaskRepo() + + private val repo: TaskRepo = TaskRepoImpl() override fun taskRepo(): TaskRepo { return repo diff --git a/samples/todoapp/src/main/java/com/examples/todoapp/data/TaskRepo.kt b/samples/todoapp/src/main/java/com/examples/todoapp/data/TaskRepo.kt index eac9d83cb..31d6a6981 100644 --- a/samples/todoapp/src/main/java/com/examples/todoapp/data/TaskRepo.kt +++ b/samples/todoapp/src/main/java/com/examples/todoapp/data/TaskRepo.kt @@ -4,32 +4,12 @@ import com.examples.todoapp.tasks.TaskCompletedEvent import com.jakewharton.rxrelay3.BehaviorRelay import io.reactivex.rxjava3.core.Observable import io.reactivex.rxjava3.android.schedulers.AndroidSchedulers +import io.reactivex.rxjava3.core.Scheduler import java.util.concurrent.TimeUnit -class TaskRepo { - private val localStore: BehaviorRelay> = BehaviorRelay.createDefault( - listOf( - Task("Mow the lawn."), - Task("Go get a haircut.") - ) - ) +interface TaskRepo { - fun tasks(): Observable> { - // Fake initial network request - return Observable.timer(5, TimeUnit.SECONDS).observeOn(AndroidSchedulers.mainThread()).flatMap { - localStore - } - } + fun tasks(): Observable> - fun onTaskCompleted(event: TaskCompletedEvent) { - val updated = localStore.value!!.map { - if (it.id == event.taskId) { - it.copy(isCompleted = event.isCompleted) - } else { - it - } - } - - localStore.accept(updated) - } + fun onTaskCompleted(event: TaskCompletedEvent) } diff --git a/samples/todoapp/src/main/java/com/examples/todoapp/data/TaskRepoImpl.kt b/samples/todoapp/src/main/java/com/examples/todoapp/data/TaskRepoImpl.kt new file mode 100644 index 000000000..de8215f2b --- /dev/null +++ b/samples/todoapp/src/main/java/com/examples/todoapp/data/TaskRepoImpl.kt @@ -0,0 +1,35 @@ +package com.examples.todoapp.data + +import com.examples.todoapp.tasks.TaskCompletedEvent +import com.jakewharton.rxrelay3.BehaviorRelay +import io.reactivex.rxjava3.android.schedulers.AndroidSchedulers +import io.reactivex.rxjava3.core.Observable +import java.util.concurrent.TimeUnit + +class TaskRepoImpl : TaskRepo { + private val localStore: BehaviorRelay> = BehaviorRelay.createDefault( + listOf( + Task("Mow the lawn."), + Task("Go get a haircut.") + ) + ) + + override fun tasks(): Observable> { + // Fake initial network request + return Observable.timer(5, TimeUnit.SECONDS).observeOn(AndroidSchedulers.mainThread()).flatMap { + localStore + } + } + + override fun onTaskCompleted(event: TaskCompletedEvent) { + val updated = localStore.value!!.map { + if (it.id == event.taskId) { + it.copy(isCompleted = event.isCompleted) + } else { + it + } + } + + localStore.accept(updated) + } +} \ No newline at end of file diff --git a/samples/todoapp/src/main/java/com/examples/todoapp/tasks/TaskItemRenderModel.kt b/samples/todoapp/src/main/java/com/examples/todoapp/tasks/TaskItemRenderModel.kt index 5f23e9fcd..691ab0202 100644 --- a/samples/todoapp/src/main/java/com/examples/todoapp/tasks/TaskItemRenderModel.kt +++ b/samples/todoapp/src/main/java/com/examples/todoapp/tasks/TaskItemRenderModel.kt @@ -2,7 +2,7 @@ package com.examples.todoapp.tasks import com.instacart.formula.Listener -class TaskItemRenderModel( +data class TaskItemRenderModel( val id: String, val text: String, val isSelected: Boolean, diff --git a/samples/todoapp/src/test/java/com/examples/todoapp/tasks/TaskListFormulaTest.kt b/samples/todoapp/src/test/java/com/examples/todoapp/tasks/TaskListFormulaTest.kt index 417c3dfb4..f1fa8eec5 100644 --- a/samples/todoapp/src/test/java/com/examples/todoapp/tasks/TaskListFormulaTest.kt +++ b/samples/todoapp/src/test/java/com/examples/todoapp/tasks/TaskListFormulaTest.kt @@ -4,24 +4,21 @@ import com.examples.todoapp.data.Task import com.examples.todoapp.data.TaskRepo import com.google.common.truth.Truth.assertThat import com.instacart.formula.test.test -import com.nhaarman.mockito_kotlin.mock -import com.nhaarman.mockito_kotlin.whenever import io.reactivex.rxjava3.core.Observable import org.junit.Test class TaskListFormulaTest { - @Test fun `change filter type`() { - val repo = mock() - whenever(repo.tasks()).thenReturn(Observable.just( - listOf( - Task("Mow the lawn."), - Task("Go get a haircut.") - ) - )) + private val showToast = { toast: String -> + + } + + @Test + fun `change filter type`() { + val repo = TaskRepoFake() TaskListFormula(repo) - .test(TaskListFormula.Input(showToast = {})) + .test(TaskListFormula.Input(showToast = showToast)) .output { assertThat(items).hasSize(2) } @@ -32,4 +29,19 @@ class TaskListFormulaTest { assertThat(items).isEmpty() } } + + class TaskRepoFake : TaskRepo { + override fun tasks(): Observable> { + return Observable.just( + listOf( + Task("Mow the lawn."), + Task("Go get a haircut.") + ) + ) + } + + override fun onTaskCompleted(event: TaskCompletedEvent) { + // nothing to do + } + } }