Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -7,40 +7,31 @@

package com.facebook.react.model

import org.junit.Assert.assertEquals
import org.assertj.core.api.Assertions.assertThat
import org.junit.Test

class ModelAutolinkingDependenciesJsonTest {

@Test
fun nameCleansed_withoutScope() {
assertEquals("name", ModelAutolinkingDependenciesJson("", "name", null).nameCleansed)
assertEquals(
"react_native", ModelAutolinkingDependenciesJson("", "react~native", null).nameCleansed)
assertEquals(
"react_native", ModelAutolinkingDependenciesJson("", "react*native", null).nameCleansed)
assertEquals(
"react_native", ModelAutolinkingDependenciesJson("", "react!native", null).nameCleansed)
assertEquals(
"react_native", ModelAutolinkingDependenciesJson("", "react'native", null).nameCleansed)
assertEquals(
"react_native", ModelAutolinkingDependenciesJson("", "react(native", null).nameCleansed)
assertEquals(
"react_native", ModelAutolinkingDependenciesJson("", "react)native", null).nameCleansed)
assertEquals(
"react_native",
ModelAutolinkingDependenciesJson("", "react~*!'()native", null).nameCleansed)
assertThat(ModelAutolinkingDependenciesJson("", "name", null).nameCleansed).isEqualTo("name")
assertThat(ModelAutolinkingDependenciesJson("", "react~native", null).nameCleansed).isEqualTo("react_native")
assertThat(ModelAutolinkingDependenciesJson("", "react*native", null).nameCleansed).isEqualTo("react_native")
assertThat(ModelAutolinkingDependenciesJson("", "react!native", null).nameCleansed).isEqualTo("react_native")
assertThat(ModelAutolinkingDependenciesJson("", "react'native", null).nameCleansed).isEqualTo("react_native")
assertThat(ModelAutolinkingDependenciesJson("", "react(native", null).nameCleansed).isEqualTo("react_native")
assertThat(ModelAutolinkingDependenciesJson("", "react)native", null).nameCleansed).isEqualTo("react_native")
assertThat(ModelAutolinkingDependenciesJson("", "react~*!'()native", null).nameCleansed).isEqualTo("react_native")
}

@Test
fun nameCleansed_withScope() {
assertEquals(
"react-native_package",
ModelAutolinkingDependenciesJson("", "@react-native/package", null).nameCleansed)
assertEquals(
"this_is_a_more_complicated_example_of_weird_packages",
ModelAutolinkingDependenciesJson(
"", "@this*is~a(more)complicated/example!of~weird)packages", null)
.nameCleansed)
assertThat(
ModelAutolinkingDependenciesJson("", "@react-native/package", null).nameCleansed).isEqualTo(
"react-native_package")
assertThat(
ModelAutolinkingDependenciesJson(
"", "@this*is~a(more)complicated/example!of~weird)packages", null).nameCleansed).isEqualTo(
"this_is_a_more_complicated_example_of_weird_packages")
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import com.facebook.react.utils.DependencyUtils.readVersionAndGroupStrings
import java.net.URI
import org.gradle.api.artifacts.repositories.MavenArtifactRepository
import org.gradle.testfixtures.ProjectBuilder
import org.junit.Assert.*
import org.assertj.core.api.Assertions.assertThat
import org.junit.Rule
import org.junit.Test
import org.junit.rules.TemporaryFolder
Expand All @@ -35,10 +35,10 @@ class DependencyUtilsTest {

configureRepositories(project, tempFolder.root)

assertNotNull(
assertThat(
project.repositories.firstOrNull {
it is MavenArtifactRepository && it.url == localMavenURI
})
}).isNotNull()
}

@Test
Expand All @@ -48,10 +48,10 @@ class DependencyUtilsTest {

configureRepositories(project, tempFolder.root)

assertNotNull(
assertThat(
project.repositories.firstOrNull {
it is MavenArtifactRepository && it.url == repositoryURI
})
}).isNotNull()
}

@Test
Expand All @@ -64,10 +64,10 @@ class DependencyUtilsTest {

configureRepositories(project, reactNativeDir)

assertNotNull(
assertThat(
project.repositories.firstOrNull {
it is MavenArtifactRepository && it.url == repositoryURI
})
}).isNotNull()
}

@Test
Expand All @@ -77,10 +77,10 @@ class DependencyUtilsTest {

configureRepositories(project, tempFolder.root)

assertNotNull(
assertThat(
project.repositories.firstOrNull {
it is MavenArtifactRepository && it.url == repositoryURI
})
}).isNotNull()
}

@Test
Expand All @@ -90,10 +90,10 @@ class DependencyUtilsTest {

configureRepositories(project, tempFolder.root)

assertNotNull(
assertThat(
project.repositories.firstOrNull {
it is MavenArtifactRepository && it.url == repositoryURI
})
}).isNotNull()
}

@Test
Expand All @@ -103,10 +103,10 @@ class DependencyUtilsTest {

configureRepositories(project, tempFolder.root)

assertNotNull(
assertThat(
project.repositories.firstOrNull {
it is MavenArtifactRepository && it.url == repositoryURI
})
}).isNotNull()
}

@Test
Expand All @@ -127,7 +127,7 @@ class DependencyUtilsTest {
project.repositories.indexOfFirst {
it is MavenArtifactRepository && it.url == mavenCentralURI
}
assertTrue(indexOfLocalRepo < indexOfMavenCentral)
assertThat(indexOfLocalRepo < indexOfMavenCentral).isTrue()
}

@Test
Expand All @@ -146,7 +146,7 @@ class DependencyUtilsTest {
project.repositories.indexOfFirst {
it is MavenArtifactRepository && it.url == mavenCentralURI
}
assertTrue(indexOfSnapshotRepo < indexOfMavenCentral)
assertThat(indexOfSnapshotRepo < indexOfMavenCentral).isTrue()
}

@Test
Expand All @@ -158,14 +158,14 @@ class DependencyUtilsTest {

configureRepositories(appProject, tempFolder.root)

assertNotNull(
assertThat(
appProject.repositories.firstOrNull {
it is MavenArtifactRepository && it.url == repositoryURI
})
assertNotNull(
}).isNotNull()
assertThat(
libProject.repositories.firstOrNull {
it is MavenArtifactRepository && it.url == repositoryURI
})
}).isNotNull()
}

@Test
Expand All @@ -184,9 +184,8 @@ class DependencyUtilsTest {

// We need to make sure we have Maven Central defined twice, one by the library,
// and another is the override by RNGP.
assertEquals(
2,
libProject.repositories.count { it is MavenArtifactRepository && it.url == repositoryURI })
assertThat(
libProject.repositories.count { it is MavenArtifactRepository && it.url == repositoryURI }).isEqualTo(2)
}

@Test
Expand All @@ -195,7 +194,7 @@ class DependencyUtilsTest {

configureDependencies(project, "")

assertTrue(project.configurations.first().resolutionStrategy.forcedModules.isEmpty())
assertThat(project.configurations.first().resolutionStrategy.forcedModules.isEmpty()).isTrue()
}

@Test
Expand All @@ -205,8 +204,8 @@ class DependencyUtilsTest {
configureDependencies(project, "1.2.3")

val forcedModules = project.configurations.first().resolutionStrategy.forcedModules
assertTrue(forcedModules.any { it.toString() == "com.facebook.react:react-android:1.2.3" })
assertTrue(forcedModules.any { it.toString() == "com.facebook.react:hermes-android:1.2.3" })
assertThat(forcedModules.any { it.toString() == "com.facebook.react:react-android:1.2.3" }).isTrue()
assertThat(forcedModules.any { it.toString() == "com.facebook.react:hermes-android:1.2.3" }).isTrue()
}

@Test
Expand All @@ -221,10 +220,10 @@ class DependencyUtilsTest {

val appForcedModules = appProject.configurations.first().resolutionStrategy.forcedModules
val libForcedModules = libProject.configurations.first().resolutionStrategy.forcedModules
assertTrue(appForcedModules.any { it.toString() == "com.facebook.react:react-android:1.2.3" })
assertTrue(appForcedModules.any { it.toString() == "com.facebook.react:hermes-android:1.2.3" })
assertTrue(libForcedModules.any { it.toString() == "com.facebook.react:react-android:1.2.3" })
assertTrue(libForcedModules.any { it.toString() == "com.facebook.react:hermes-android:1.2.3" })
assertThat(appForcedModules.any { it.toString() == "com.facebook.react:react-android:1.2.3" }).isTrue()
assertThat(appForcedModules.any { it.toString() == "com.facebook.react:hermes-android:1.2.3" }).isTrue()
assertThat(libForcedModules.any { it.toString() == "com.facebook.react:react-android:1.2.3" }).isTrue()
assertThat(libForcedModules.any { it.toString() == "com.facebook.react:hermes-android:1.2.3" }).isTrue()
}

@Test
Expand All @@ -239,52 +238,54 @@ class DependencyUtilsTest {

val appForcedModules = appProject.configurations.first().resolutionStrategy.forcedModules
val libForcedModules = libProject.configurations.first().resolutionStrategy.forcedModules
assertTrue(appForcedModules.any { it.toString() == "io.github.test:react-android:1.2.3" })
assertTrue(appForcedModules.any { it.toString() == "io.github.test:hermes-android:1.2.3" })
assertTrue(libForcedModules.any { it.toString() == "io.github.test:react-android:1.2.3" })
assertTrue(libForcedModules.any { it.toString() == "io.github.test:hermes-android:1.2.3" })
assertThat(appForcedModules.any { it.toString() == "io.github.test:react-android:1.2.3" }).isTrue()
assertThat(appForcedModules.any { it.toString() == "io.github.test:hermes-android:1.2.3" }).isTrue()
assertThat(libForcedModules.any { it.toString() == "io.github.test:react-android:1.2.3" }).isTrue()
assertThat(libForcedModules.any { it.toString() == "io.github.test:hermes-android:1.2.3" }).isTrue()
}

@Test
fun getDependencySubstitutions_withDefaultGroup_substitutesCorrectly() {
val dependencySubstitutions = getDependencySubstitutions("0.42.0")

assertEquals(dependencySubstitutions[0].first, "com.facebook.react:react-native")
assertEquals(dependencySubstitutions[0].second, "com.facebook.react:react-android:0.42.0")
assertEquals(
dependencySubstitutions[0].third,
"The react-native artifact was deprecated in favor of react-android due to https://github.com/facebook/react-native/issues/35210.")
assertEquals(dependencySubstitutions[1].first, "com.facebook.react:hermes-engine")
assertEquals(dependencySubstitutions[1].second, "com.facebook.react:hermes-android:0.42.0")
assertEquals(
dependencySubstitutions[1].third,
"The hermes-engine artifact was deprecated in favor of hermes-android due to https://github.com/facebook/react-native/issues/35210.")
assertThat("com.facebook.react:react-native").isEqualTo(dependencySubstitutions[0].first)
assertThat("com.facebook.react:react-android:0.42.0").isEqualTo(dependencySubstitutions[0].second)
assertThat(
"The react-native artifact was deprecated in favor of react-android due to
https://github.com/facebook/react-native/issues/35210.").isEqualTo(
dependencySubstitutions[0].third)
assertThat("com.facebook.react:hermes-engine").isEqualTo(dependencySubstitutions[1].first)
assertThat("com.facebook.react:hermes-android:0.42.0").isEqualTo(dependencySubstitutions[1].second)
assertThat("The hermes-engine artifact was deprecated in favor of hermes-android
due to https://github.com/facebook/react-native/issues/35210.").isEqualTo(
dependencySubstitutions[1].third)
}

@Test
fun getDependencySubstitutions_withCustomGroup_substitutesCorrectly() {
val dependencySubstitutions = getDependencySubstitutions("0.42.0", "io.github.test")

assertEquals(dependencySubstitutions[0].first, "com.facebook.react:react-native")
assertEquals(dependencySubstitutions[0].second, "io.github.test:react-android:0.42.0")
assertEquals(
dependencySubstitutions[0].third,
"The react-native artifact was deprecated in favor of react-android due to https://github.com/facebook/react-native/issues/35210.")
assertEquals(dependencySubstitutions[1].first, "com.facebook.react:hermes-engine")
assertEquals(dependencySubstitutions[1].second, "io.github.test:hermes-android:0.42.0")
assertEquals(
dependencySubstitutions[1].third,
"The hermes-engine artifact was deprecated in favor of hermes-android due to https://github.com/facebook/react-native/issues/35210.")
assertEquals(dependencySubstitutions[2].first, "com.facebook.react:react-android")
assertEquals(dependencySubstitutions[2].second, "io.github.test:react-android:0.42.0")
assertEquals(
dependencySubstitutions[2].third,
"The react-android dependency was modified to use the correct Maven group.")
assertEquals(dependencySubstitutions[3].first, "com.facebook.react:hermes-android")
assertEquals(dependencySubstitutions[3].second, "io.github.test:hermes-android:0.42.0")
assertEquals(
dependencySubstitutions[3].third,
"The hermes-android dependency was modified to use the correct Maven group.")
assertThat("com.facebook.react:react-native").isEqualTo(dependencySubstitutions[0].first)
assertThat("io.github.test:react-android:0.42.0").isEqualTo(dependencySubstitutions[0].second)
assertThat(
"The react-native artifact was deprecated in favor of react-android due to
https://github.com/facebook/react-native/issues/35210.").isEqualTo(
dependencySubstitutions[0].third)
assertThat("com.facebook.react:hermes-engine").isEqualTo(dependencySubstitutions[1].first)
assertThat("io.github.test:hermes-android:0.42.0").isEqualTo(dependencySubstitutions[1].second)
assertThat("The hermes-engine artifact was deprecated in favor of hermes-android
due to https://github.com/facebook/react-native/issues/35210.").isEqualTo(
dependencySubstitutions[1].third)
assertThat("com.facebook.react:react-android").isEqualTo(dependencySubstitutions[2].first)
assertThat("io.github.test:react-android:0.42.0").isEqualTo(dependencySubstitutions[2].second)
assertThat(
"The react-android dependency was modified to use the correct Maven group.").isEqualTo(
dependencySubstitutions[2].third)
assertThat("com.facebook.react:hermes-android").isEqualTo(dependencySubstitutions[3].first)
assertThat("io.github.test:hermes-android:0.42.0").isEqualTo(dependencySubstitutions[3].second)
assertThat(
"The hermes-android dependency was modified to use the correct Maven group.").isEqualTo(
dependencySubstitutions[3].third)
}

@Test
Expand All @@ -301,7 +302,7 @@ class DependencyUtilsTest {

val versionString = readVersionAndGroupStrings(propertiesFile).first

assertEquals("1000.0.0", versionString)
assertThat(versionString).isEqualTo("1000.0.0")
}

@Test
Expand All @@ -318,7 +319,7 @@ class DependencyUtilsTest {

val versionString = readVersionAndGroupStrings(propertiesFile).first

assertEquals("0.0.0-20221101-2019-cfe811ab1-SNAPSHOT", versionString)
assertThat(versionString).isEqualTo("0.0.0-20221101-2019-cfe811ab1-SNAPSHOT")
}

@Test
Expand All @@ -333,7 +334,7 @@ class DependencyUtilsTest {
}

val versionString = readVersionAndGroupStrings(propertiesFile).first
assertEquals("", versionString)
assertThat(versionString).isEqualTo("")
}

@Test
Expand All @@ -349,7 +350,7 @@ class DependencyUtilsTest {
}

val versionString = readVersionAndGroupStrings(propertiesFile).first
assertEquals("", versionString)
assertThat(versionString).isEqualTo("")
}

@Test
Expand All @@ -366,7 +367,7 @@ class DependencyUtilsTest {

val groupString = readVersionAndGroupStrings(propertiesFile).second

assertEquals("io.github.test", groupString)
assertThat(groupString).isEqualTo("io.github.test")
}

@Test
Expand All @@ -382,15 +383,15 @@ class DependencyUtilsTest {

val groupString = readVersionAndGroupStrings(propertiesFile).second

assertEquals("com.facebook.react", groupString)
assertThat(groupString).isEqualTo("com.facebook.react")
}

@Test
fun mavenRepoFromUrl_worksCorrectly() {
val process = createProject()
val mavenRepo = process.mavenRepoFromUrl("https://hello.world")

assertEquals(URI.create("https://hello.world"), mavenRepo.url)
assertThat(mavenRepo.url).isEqualTo(URI.create("https://hello.world"))
}

@Test
Expand All @@ -399,6 +400,6 @@ class DependencyUtilsTest {
val repoFolder = tempFolder.newFolder("maven-repo")
val mavenRepo = process.mavenRepoFromURI(repoFolder.toURI())

assertEquals(repoFolder.toURI(), mavenRepo.url)
assertThat(mavenRepo.url).isEqualTo(repoFolder.toURI())
}
}
Loading