Skip to content

Commit

Permalink
Remove the workaround for projectRoot
Browse files Browse the repository at this point in the history
  • Loading branch information
Goooler committed Jan 9, 2025
1 parent c9933c5 commit bcbfbba
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ class ApplicationTest : BasePluginTest() {
val zip = path("build/distributions/myapp-shadow-1.0.zip")
assertThat(zip).exists()

val entries = ZipFile(zip.toFile()).entries.toList().map { it.name }
val entries = ZipFile(zip.toFile()).use { it.entries }.toList().map { it.name }
assertThat(entries).containsAtLeast(
"myapp-shadow-1.0/lib/myapp-1.0-all.jar",
"myapp-shadow-1.0/lib/a-1.0.jar",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,11 @@ import org.junit.jupiter.api.AfterEach
import org.junit.jupiter.api.BeforeAll
import org.junit.jupiter.api.BeforeEach
import org.junit.jupiter.api.TestInstance
import org.junit.jupiter.api.io.TempDir

@TestInstance(TestInstance.Lifecycle.PER_CLASS)
abstract class BasePluginTest {
@TempDir
lateinit var projectRoot: Path
lateinit var localRepo: AppendableMavenRepository

Expand All @@ -64,20 +66,12 @@ abstract class BasePluginTest {

@BeforeEach
open fun setup() {
projectRoot = createTempDirectory()

projectScriptPath.writeText(getDefaultProjectBuildScript(withGroup = true, withVersion = true))
settingsScriptPath.writeText(getDefaultSettingsBuildScript())
}

@ExperimentalPathApi
@AfterEach
fun cleanup() {
runCatching {
// TODO: workaround for https://github.com/junit-team/junit5/issues/2811.
projectRoot.deleteRecursively()
}

println(projectScriptPath.readText())
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -210,16 +210,17 @@ class RelocationTest : BasePluginTest() {
)
}

val classLoader = URLClassLoader(
URLClassLoader(
arrayOf(outputShadowJar.toUri().toURL()),
ClassLoader.getSystemClassLoader().parent,
)
assertFailure {
// check that the class can be loaded. If the file was not relocated properly, we should get a NoDefClassFound
// Isolated class loader with only the JVM system jars and the output jar from the test project
classLoader.loadClass("shadow.ShadowTest")
fail("Should not reach here.")
}.isInstanceOf(AssertionFailedError::class)
).use { classLoader ->
assertFailure {
// check that the class can be loaded. If the file was not relocated properly, we should get a NoDefClassFound
// Isolated class loader with only the JVM system jars and the output jar from the test project
classLoader.loadClass("shadow.ShadowTest")
fail("Should not reach here.")
}.isInstanceOf(AssertionFailedError::class)
}
}

@Test
Expand Down

0 comments on commit bcbfbba

Please sign in to comment.