diff --git a/packages/gradle-plugin/gradle/libs.versions.toml b/packages/gradle-plugin/gradle/libs.versions.toml index 584509981d29cd..4544a5df14e910 100644 --- a/packages/gradle-plugin/gradle/libs.versions.toml +++ b/packages/gradle-plugin/gradle/libs.versions.toml @@ -5,6 +5,7 @@ guava = "31.0.1-jre" javapoet = "1.13.0" junit = "4.13.2" kotlin = "1.9.24" +assertj = "3.25.1" [libraries] kotlin-gradle-plugin = { module = "org.jetbrains.kotlin:kotlin-gradle-plugin", version.ref = "kotlin" } @@ -13,6 +14,7 @@ gson = { module = "com.google.code.gson:gson", version.ref = "gson" } guava = { module = "com.google.guava:guava", version.ref = "guava" } javapoet = { module = "com.squareup:javapoet", version.ref = "javapoet" } junit = {module = "junit:junit", version.ref = "junit" } +assertj = { module = "org.assertj:assertj-core", version.ref = "assertj" } [plugins] kotlin-jvm = { id = "org.jetbrains.kotlin.jvm", version.ref = "kotlin" } diff --git a/packages/gradle-plugin/react-native-gradle-plugin/build.gradle.kts b/packages/gradle-plugin/react-native-gradle-plugin/build.gradle.kts index 28055c6209252a..8506b017d289ef 100644 --- a/packages/gradle-plugin/react-native-gradle-plugin/build.gradle.kts +++ b/packages/gradle-plugin/react-native-gradle-plugin/build.gradle.kts @@ -48,6 +48,7 @@ dependencies { implementation(libs.javapoet) testImplementation(libs.junit) + testImplementation(libs.assertj) testImplementation(project(":shared-testutil")) } diff --git a/packages/gradle-plugin/settings-plugin/build.gradle.kts b/packages/gradle-plugin/settings-plugin/build.gradle.kts index 39b65d466cffd8..58a7d069f30089 100644 --- a/packages/gradle-plugin/settings-plugin/build.gradle.kts +++ b/packages/gradle-plugin/settings-plugin/build.gradle.kts @@ -38,6 +38,7 @@ dependencies { implementation(libs.javapoet) testImplementation(libs.junit) + testImplementation(libs.assertj) testImplementation(project(":shared-testutil")) } diff --git a/packages/gradle-plugin/settings-plugin/src/test/kotlin/com/facebook/react/ReactSettingsExtensionTest.kt b/packages/gradle-plugin/settings-plugin/src/test/kotlin/com/facebook/react/ReactSettingsExtensionTest.kt index 3f89e1b935cf92..e203bff1e813d6 100644 --- a/packages/gradle-plugin/settings-plugin/src/test/kotlin/com/facebook/react/ReactSettingsExtensionTest.kt +++ b/packages/gradle-plugin/settings-plugin/src/test/kotlin/com/facebook/react/ReactSettingsExtensionTest.kt @@ -10,12 +10,10 @@ package com.facebook.react import com.facebook.react.ReactSettingsExtension.Companion.checkAndUpdateLockfiles import com.facebook.react.ReactSettingsExtension.Companion.computeSha256 import com.facebook.react.ReactSettingsExtension.Companion.getLibrariesToAutolink -import groovy.test.GroovyTestCase.assertEquals import java.io.File +import org.assertj.core.api.Assertions.assertThat import org.gradle.testfixtures.ProjectBuilder import org.intellij.lang.annotations.Language -import org.junit.Assert.assertFalse -import org.junit.Assert.assertTrue import org.junit.Rule import org.junit.Test import org.junit.rules.TemporaryFolder @@ -34,10 +32,8 @@ class ReactSettingsExtensionTest { } """ .trimIndent()) - - assertEquals( - "838aa9a72a16fdd55b0d49b510a82e264a30f59333b5fdd97c7798a29146f6a8", - computeSha256(validFile)) + assertThat(computeSha256(validFile)) + .isEqualTo("838aa9a72a16fdd55b0d49b510a82e264a30f59333b5fdd97c7798a29146f6a8") } @Test @@ -52,7 +48,7 @@ class ReactSettingsExtensionTest { .trimIndent()) val map = getLibrariesToAutolink(validJsonFile) - assertEquals(0, map.keys.size) + assertThat(map.keys).isEmpty() } @Test @@ -97,11 +93,9 @@ class ReactSettingsExtensionTest { .trimIndent()) val map = getLibrariesToAutolink(validJsonFile) - assertEquals(1, map.keys.size) - assertTrue(":react-native_oss-library-example" in map.keys) - assertEquals( - File("./node_modules/@react-native/oss-library-example/android"), - map[":react-native_oss-library-example"]) + assertThat(map.keys).containsExactly(":react-native_oss-library-example") + assertThat(map[":react-native_oss-library-example"]) + .isEqualTo(File("./node_modules/@react-native/oss-library-example/android")) } @Test @@ -130,14 +124,14 @@ class ReactSettingsExtensionTest { .trimIndent()) val map = getLibrariesToAutolink(validJsonFile) - assertEquals(0, map.keys.size) + assertThat(map.keys).isEmpty() } @Test fun checkAndUpdateLockfiles_withNothingToCheck_returnsFalse() { val project = ProjectBuilder.builder().build() val noFiles = project.files() - assertFalse(checkAndUpdateLockfiles(noFiles, tempFolder.root)) + assertThat(checkAndUpdateLockfiles(noFiles, tempFolder.root)).isFalse() } @Test @@ -147,11 +141,10 @@ class ReactSettingsExtensionTest { tempFolder.newFile("yarn.lock").apply { writeText("I'm a lockfile") } val lockfileCollection = project.files("yarn.lock") - assertTrue(checkAndUpdateLockfiles(lockfileCollection, buildFolder)) - assertTrue(File(buildFolder, "yarn.lock.sha").exists()) - assertEquals( - "76046b72442ee7eb130627e56c3db7c9907eef4913b17ad130335edc0eb702a8", - File(buildFolder, "yarn.lock.sha").readText()) + assertThat(checkAndUpdateLockfiles(lockfileCollection, buildFolder)).isTrue() + assertThat(File(buildFolder, "yarn.lock.sha").exists()).isTrue() + assertThat(File(buildFolder, "yarn.lock.sha").readText()) + .isEqualTo("76046b72442ee7eb130627e56c3db7c9907eef4913b17ad130335edc0eb702a8") } @Test @@ -164,11 +157,10 @@ class ReactSettingsExtensionTest { tempFolder.newFile("yarn.lock").apply { writeText("I'm a lockfile") } val lockfileCollection = project.files("yarn.lock") - assertTrue(checkAndUpdateLockfiles(lockfileCollection, buildFolder)) - assertTrue(File(buildFolder, "yarn.lock.sha").exists()) - assertEquals( - "76046b72442ee7eb130627e56c3db7c9907eef4913b17ad130335edc0eb702a8", - File(buildFolder, "yarn.lock.sha").readText()) + assertThat(checkAndUpdateLockfiles(lockfileCollection, buildFolder)).isTrue() + assertThat(File(buildFolder, "yarn.lock.sha").exists()).isTrue() + assertThat(File(buildFolder, "yarn.lock.sha").readText()) + .isEqualTo("76046b72442ee7eb130627e56c3db7c9907eef4913b17ad130335edc0eb702a8") } @Test @@ -182,11 +174,10 @@ class ReactSettingsExtensionTest { tempFolder.newFile("yarn.lock").apply { writeText("I'm a lockfile") } val lockfileCollection = project.files("yarn.lock") - assertFalse(checkAndUpdateLockfiles(lockfileCollection, buildFolder)) - assertTrue(File(buildFolder, "yarn.lock.sha").exists()) - assertEquals( - "76046b72442ee7eb130627e56c3db7c9907eef4913b17ad130335edc0eb702a8", - File(buildFolder, "yarn.lock.sha").readText()) + assertThat(checkAndUpdateLockfiles(lockfileCollection, buildFolder)).isFalse() + assertThat(File(buildFolder, "yarn.lock.sha").exists()).isTrue() + assertThat(File(buildFolder, "yarn.lock.sha").readText()) + .isEqualTo("76046b72442ee7eb130627e56c3db7c9907eef4913b17ad130335edc0eb702a8") } @Test @@ -200,15 +191,13 @@ class ReactSettingsExtensionTest { tempFolder.newFile("package-lock.json").apply { writeText("and I'm another lockfile") } val lockfileCollection = project.files("yarn.lock", "package-lock.json") - assertTrue(checkAndUpdateLockfiles(lockfileCollection, buildFolder)) - assertTrue(File(buildFolder, "yarn.lock.sha").exists()) - assertTrue(File(buildFolder, "package-lock.json.sha").exists()) - assertEquals( - "76046b72442ee7eb130627e56c3db7c9907eef4913b17ad130335edc0eb702a8", - File(buildFolder, "yarn.lock.sha").readText()) - assertEquals( - "9be5bca432b81becf4f54451aea021add68376330581eaa93ab9a0b3e4e29a3b", - File(buildFolder, "package-lock.json.sha").readText()) + assertThat(checkAndUpdateLockfiles(lockfileCollection, buildFolder)).isTrue() + assertThat(File(buildFolder, "yarn.lock.sha").exists()).isTrue() + assertThat(File(buildFolder, "package-lock.json.sha").exists()).isTrue() + assertThat(File(buildFolder, "yarn.lock.sha").readText()) + .isEqualTo("76046b72442ee7eb130627e56c3db7c9907eef4913b17ad130335edc0eb702a8") + assertThat(File(buildFolder, "package-lock.json.sha").readText()) + .isEqualTo("9be5bca432b81becf4f54451aea021add68376330581eaa93ab9a0b3e4e29a3b") } @Test @@ -225,15 +214,13 @@ class ReactSettingsExtensionTest { tempFolder.newFile("package-lock.json").apply { writeText("and I'm another lockfile") } val lockfileCollection = project.files("yarn.lock", "package-lock.json") - assertFalse(checkAndUpdateLockfiles(lockfileCollection, buildFolder)) - assertTrue(File(buildFolder, "yarn.lock.sha").exists()) - assertTrue(File(buildFolder, "package-lock.json.sha").exists()) - assertEquals( - "76046b72442ee7eb130627e56c3db7c9907eef4913b17ad130335edc0eb702a8", - File(buildFolder, "yarn.lock.sha").readText()) - assertEquals( - "9be5bca432b81becf4f54451aea021add68376330581eaa93ab9a0b3e4e29a3b", - File(buildFolder, "package-lock.json.sha").readText()) + assertThat(checkAndUpdateLockfiles(lockfileCollection, buildFolder)).isFalse() + assertThat(File(buildFolder, "yarn.lock.sha").exists()).isTrue() + assertThat(File(buildFolder, "package-lock.json.sha").exists()).isTrue() + assertThat(File(buildFolder, "yarn.lock.sha").readText()) + .isEqualTo("76046b72442ee7eb130627e56c3db7c9907eef4913b17ad130335edc0eb702a8") + assertThat(File(buildFolder, "package-lock.json.sha").readText()) + .isEqualTo("9be5bca432b81becf4f54451aea021add68376330581eaa93ab9a0b3e4e29a3b") } private fun createJsonFile(@Language("JSON") input: String) = diff --git a/packages/gradle-plugin/shared/build.gradle.kts b/packages/gradle-plugin/shared/build.gradle.kts index fa76599233ef37..f0758ad0be5de3 100644 --- a/packages/gradle-plugin/shared/build.gradle.kts +++ b/packages/gradle-plugin/shared/build.gradle.kts @@ -18,6 +18,7 @@ dependencies { implementation(libs.gson) implementation(libs.guava) testImplementation(libs.junit) + testImplementation(libs.assertj) testImplementation(project(":shared-testutil")) }