Skip to content

Commit

Permalink
chore: migrate assertions in all unit tests in PrepareBoostTaskTest f…
Browse files Browse the repository at this point in the history
…rom jUnit to AssertJ. (#45718)

Summary:
#45596

Migrated all the assertions to use `assertThat()` function from AssertJ.
Also updated the `prepareBoostTask_withMissingConfiguration_fails` test to use `assertThatThrownBy` to check if the tested task throws a given exception.

## Changelog:
Migrate tests to assertj in these files:

- `packages/gradle-plugin/react-native-gradle-plugin/src/test/kotlin/com/facebook/react/tasks/internal/PrepareBoostTaskTest.kt`

[INTERNAL] [CHANGED] - Migrated PrepareBoostTaskTest from junit.Assert to assertj.core.api.Assertions.

For more details, see:
https://reactnative.dev/contributing/changelogs-in-pull-requests

Pull Request resolved: #45718

Test Plan:
All tests pass when `./gradlew -p packages/gradle-plugin test` command is ran.

<img width="454" alt="image" src="https://github.com/user-attachments/assets/9e954f7b-2208-48a9-ae15-ab642252e6da">

Reviewed By: GijsWeterings

Differential Revision: D60284566

Pulled By: cortinico

fbshipit-source-id: 11af0a0ca574f935e6aab3a7855b5daaeab1a718
  • Loading branch information
Jakub Urban authored and facebook-github-bot committed Jul 26, 2024
1 parent f443511 commit 9bddcde
Showing 1 changed file with 11 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ package com.facebook.react.tasks.internal
import com.facebook.react.tests.createProject
import com.facebook.react.tests.createTestTask
import java.io.*
import org.junit.Assert.*
import org.assertj.core.api.Assertions.assertThat
import org.assertj.core.api.Assertions.assertThatThrownBy
import org.junit.Rule
import org.junit.Test
import org.junit.rules.TemporaryFolder
Expand All @@ -19,11 +20,13 @@ class PrepareBoostTaskTest {

@get:Rule val tempFolder = TemporaryFolder()

@Test(expected = IllegalStateException::class)
@Test
fun prepareBoostTask_withMissingConfiguration_fails() {
val task = createTestTask<PrepareBoostTask>()

task.taskAction()
assertThatThrownBy { task.taskAction() }
.isInstanceOf(IllegalStateException::class.java)
.hasMessage(
"Cannot query the value of task ':PrepareBoostTask' property 'boostVersion' because it has no value available.")
}

@Test
Expand All @@ -43,7 +46,7 @@ class PrepareBoostTaskTest {
}
task.taskAction()

assertTrue(output.listFiles()!!.any { it.name == "CMakeLists.txt" })
assertThat(output.listFiles()).extracting("name").contains("CMakeLists.txt")
}

@Test
Expand All @@ -62,7 +65,7 @@ class PrepareBoostTaskTest {
}
task.taskAction()

assertTrue(File(output, "asm/asm.S").exists())
assertThat(File(output, "asm/asm.S")).exists()
}

@Test
Expand All @@ -81,7 +84,7 @@ class PrepareBoostTaskTest {
}
task.taskAction()

assertTrue(File(output, "boost_1.0.0/boost/config.hpp").exists())
assertThat(File(output, "boost_1.0.0/boost/config.hpp")).exists()
}

@Test
Expand All @@ -100,6 +103,6 @@ class PrepareBoostTaskTest {
}
task.taskAction()

assertTrue(File(output, "boost_1.0.0/boost/config.hpp").exists())
assertThat(File(output, "boost_1.0.0/boost/config.hpp")).exists()
}
}

0 comments on commit 9bddcde

Please sign in to comment.