From 8739d91fff148b59bad84193fc653038fd76ded2 Mon Sep 17 00:00:00 2001 From: Sergei Vorobyov Date: Thu, 28 Nov 2024 12:40:54 +0100 Subject: [PATCH] [Gradle|Exec] cleanup: migrate GradlePropertiesFileTest on Junit 5 GitOrigin-RevId: 7be25046c801fdde7d64db1233081c84665d2468 --- .../properties/GradlePropertiesFileTest.kt | 21 +++++----- .../GradlePropertiesFileTestCase.kt | 42 +++++-------------- 2 files changed, 22 insertions(+), 41 deletions(-) diff --git a/plugins/gradle/testSources/org/jetbrains/plugins/gradle/properties/GradlePropertiesFileTest.kt b/plugins/gradle/testSources/org/jetbrains/plugins/gradle/properties/GradlePropertiesFileTest.kt index 513c98ee0321..cef2d0280563 100644 --- a/plugins/gradle/testSources/org/jetbrains/plugins/gradle/properties/GradlePropertiesFileTest.kt +++ b/plugins/gradle/testSources/org/jetbrains/plugins/gradle/properties/GradlePropertiesFileTest.kt @@ -8,6 +8,7 @@ class GradlePropertiesFileTest : GradlePropertiesFileTestCase() { @Test fun testEmptyProjectGradlePropertiesFile() { + createGradlePropertiesFile {} assertGradlePropertiesFile { Assertions.assertNull(javaHomeProperty) Assertions.assertNull(gradleLoggingLevel) @@ -43,15 +44,15 @@ class GradlePropertiesFileTest : GradlePropertiesFileTestCase() { } assertGradlePropertiesFile { Assertions.assertEquals("javaHome", javaHomeProperty?.value) - Assertions.assertEquals(gradlePropertiesPath, javaHomeProperty?.location) + Assertions.assertEquals(projectPropertiesPath.toString(), javaHomeProperty?.location) Assertions.assertEquals("info", gradleLoggingLevel?.value) - Assertions.assertEquals(gradlePropertiesPath, gradleLoggingLevel?.location) + Assertions.assertEquals(projectPropertiesPath.toString(), gradleLoggingLevel?.location) Assertions.assertEquals(true, parallel?.value) - Assertions.assertEquals(gradlePropertiesPath, parallel?.location) + Assertions.assertEquals(projectPropertiesPath.toString(), parallel?.location) Assertions.assertEquals(true, isolatedProjects?.value) - Assertions.assertEquals(gradlePropertiesPath, isolatedProjects?.location) + Assertions.assertEquals(projectPropertiesPath.toString(), isolatedProjects?.location) Assertions.assertEquals( "-Xmx20G", jvmOptions?.value) - Assertions.assertEquals(gradlePropertiesPath, jvmOptions?.location) + Assertions.assertEquals(projectPropertiesPath.toString(), jvmOptions?.location) } } @@ -68,15 +69,15 @@ class GradlePropertiesFileTest : GradlePropertiesFileTestCase() { } assertGradlePropertiesFile { Assertions.assertEquals("value2", javaHomeProperty?.value) - Assertions.assertEquals(gradlePropertiesPath, javaHomeProperty?.location) + Assertions.assertEquals(projectPropertiesPath.toString(), javaHomeProperty?.location) Assertions.assertEquals("value3", gradleLoggingLevel?.value) - Assertions.assertEquals(gradlePropertiesPath, gradleLoggingLevel?.location) + Assertions.assertEquals(projectPropertiesPath.toString(), gradleLoggingLevel?.location) Assertions.assertEquals(true, parallel?.value) - Assertions.assertEquals(gradlePropertiesPath, parallel?.location) + Assertions.assertEquals(projectPropertiesPath.toString(), parallel?.location) Assertions.assertEquals(true, isolatedProjects?.value) - Assertions.assertEquals(gradlePropertiesPath, isolatedProjects?.location) + Assertions.assertEquals(projectPropertiesPath.toString(), isolatedProjects?.location) Assertions.assertEquals("-Xmx20G", jvmOptions?.value) - Assertions.assertEquals(gradlePropertiesPath, jvmOptions?.location) + Assertions.assertEquals(projectPropertiesPath.toString(), jvmOptions?.location) } } } \ No newline at end of file diff --git a/plugins/gradle/testSources/org/jetbrains/plugins/gradle/properties/GradlePropertiesFileTestCase.kt b/plugins/gradle/testSources/org/jetbrains/plugins/gradle/properties/GradlePropertiesFileTestCase.kt index a199c766f6d1..cd767ea0f8ad 100644 --- a/plugins/gradle/testSources/org/jetbrains/plugins/gradle/properties/GradlePropertiesFileTestCase.kt +++ b/plugins/gradle/testSources/org/jetbrains/plugins/gradle/properties/GradlePropertiesFileTestCase.kt @@ -1,13 +1,9 @@ // Copyright 2000-2022 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license. package org.jetbrains.plugins.gradle.properties -import com.intellij.testFramework.fixtures.IdeaTestFixtureFactory -import com.intellij.testFramework.fixtures.TempDirTestFixture import com.intellij.testFramework.junit5.TestApplication -import com.intellij.util.io.createDirectories -import org.junit.jupiter.api.AfterEach -import org.junit.jupiter.api.BeforeEach -import org.junit.jupiter.api.TestInfo +import com.intellij.util.io.createParentDirectories +import org.junit.jupiter.api.io.TempDir import java.nio.file.Path import java.util.* import kotlin.io.path.outputStream @@ -15,40 +11,24 @@ import kotlin.io.path.outputStream @TestApplication abstract class GradlePropertiesFileTestCase { - private lateinit var fileFixture: TempDirTestFixture + @TempDir + private lateinit var rootPath: Path - private lateinit var externalProjectNioPath: Path - private lateinit var gradlePropertiesNioPath: Path + val projectPath: Path + get() = rootPath.resolve("project") - val gradlePropertiesPath get() = gradlePropertiesNioPath.toString() - - @BeforeEach - fun setUpGradlePropertiesFileTestCase(testInfo: TestInfo) { - fileFixture = IdeaTestFixtureFactory.getFixtureFactory().createTempDirTestFixture() - fileFixture.setUp() - - val className = testInfo.testClass.get().simpleName - val methodName = testInfo.testMethod.get().name - - externalProjectNioPath = Path.of(fileFixture.tempDirPath, className, methodName, "project") - gradlePropertiesNioPath = externalProjectNioPath.resolve(GRADLE_PROPERTIES_FILE_NAME) - - externalProjectNioPath.createDirectories() - } - - @AfterEach - fun tearDownGradlePropertiesFileTestCase() { - fileFixture.tearDown() - } + val projectPropertiesPath: Path + get() = projectPath.resolve(GRADLE_PROPERTIES_FILE_NAME) fun createGradlePropertiesFile(configure: Properties.() -> Unit) { val properties = Properties() properties.configure() - properties.store(gradlePropertiesNioPath.outputStream(), null) + projectPropertiesPath.createParentDirectories() + properties.store(projectPropertiesPath.outputStream(), null) } fun assertGradlePropertiesFile(assertion: GradleProperties. () -> Unit) { - val properties = GradlePropertiesFile.getProperties(null, externalProjectNioPath) + val properties = GradlePropertiesFile.getProperties(null, projectPath) properties.assertion() } } \ No newline at end of file