diff --git a/gradle/plugin/src/functionalTest/java/org/hibernate/tool/gradle/java/JpaDefaultTest.java b/gradle/plugin/src/functionalTest/java/org/hibernate/tool/gradle/java/JpaDefaultTest.java index ea1a270e8e..4aea46cec7 100644 --- a/gradle/plugin/src/functionalTest/java/org/hibernate/tool/gradle/java/JpaDefaultTest.java +++ b/gradle/plugin/src/functionalTest/java/org/hibernate/tool/gradle/java/JpaDefaultTest.java @@ -23,7 +23,6 @@ public class JpaDefaultTest extends TestTemplate { private static final List GRADLE_INIT_PROJECT_ARGUMENTS = List.of( "init", "--type", "java-application", "--dsl", "groovy", "--test-framework", "junit-jupiter", "--java-version", "17"); - private File gradlePropertiesFile; private File gradleBuildFile; private File databaseFile; @@ -55,9 +54,9 @@ private void createGradleProject() throws Exception { runner.withProjectDir(getProjectDir()); BuildResult buildResult = runner.build(); assertTrue(buildResult.getOutput().contains("BUILD SUCCESSFUL")); - gradlePropertiesFile = new File(getProjectDir(), "gradle.properties"); - assertTrue(gradlePropertiesFile.exists()); - assertTrue(gradlePropertiesFile.isFile()); + setGradlePropertiesFile(new File(getProjectDir(), "gradle.properties")); + assertTrue(getGradlePropertiesFile().exists()); + assertTrue(getGradlePropertiesFile().isFile()); File appDir = new File(getProjectDir(), "app"); assertTrue(appDir.exists()); assertTrue(appDir.isDirectory()); @@ -81,10 +80,10 @@ private void editGradlePropertiesFile() throws Exception { // As this is enabled by default when initializing a new Gradle project, the setting needs to be commented out // in the gradle.properties file. StringBuffer gradlePropertiesFileContents = new StringBuffer( - new String(Files.readAllBytes(gradlePropertiesFile.toPath()))); + new String(Files.readAllBytes(getGradlePropertiesFile().toPath()))); int pos = gradlePropertiesFileContents.indexOf("org.gradle.configuration-cache=true"); gradlePropertiesFileContents.insert(pos, "#"); - Files.writeString(gradlePropertiesFile.toPath(), gradlePropertiesFileContents.toString()); + Files.writeString(getGradlePropertiesFile().toPath(), gradlePropertiesFileContents.toString()); } private void createDatabase() throws Exception { diff --git a/gradle/plugin/src/functionalTest/java/org/hibernate/tool/gradle/java/NoAnnotationsTest.java b/gradle/plugin/src/functionalTest/java/org/hibernate/tool/gradle/java/NoAnnotationsTest.java index e63dff25b0..e33fed26f3 100644 --- a/gradle/plugin/src/functionalTest/java/org/hibernate/tool/gradle/java/NoAnnotationsTest.java +++ b/gradle/plugin/src/functionalTest/java/org/hibernate/tool/gradle/java/NoAnnotationsTest.java @@ -23,7 +23,6 @@ public class NoAnnotationsTest extends TestTemplate { private static final List GRADLE_INIT_PROJECT_ARGUMENTS = List.of( "init", "--type", "java-application", "--dsl", "groovy", "--test-framework", "junit-jupiter", "--java-version", "17"); - private File gradlePropertiesFile; private File gradleBuildFile; private File databaseFile; @@ -55,9 +54,9 @@ private void createGradleProject() throws Exception { runner.withProjectDir(getProjectDir()); BuildResult buildResult = runner.build(); assertTrue(buildResult.getOutput().contains("BUILD SUCCESSFUL")); - gradlePropertiesFile = new File(getProjectDir(), "gradle.properties"); - assertTrue(gradlePropertiesFile.exists()); - assertTrue(gradlePropertiesFile.isFile()); + setGradlePropertiesFile(new File(getProjectDir(), "gradle.properties")); + assertTrue(getGradlePropertiesFile().exists()); + assertTrue(getGradlePropertiesFile().isFile()); File appDir = new File(getProjectDir(), "app"); assertTrue(appDir.exists()); assertTrue(appDir.isDirectory()); @@ -82,10 +81,10 @@ private void editGradlePropertiesFile() throws Exception { // As this is enabled by default when initializing a new Gradle project, the setting needs to be commented out // in the gradle.properties file. StringBuffer gradlePropertiesFileContents = new StringBuffer( - new String(Files.readAllBytes(gradlePropertiesFile.toPath()))); + new String(Files.readAllBytes(getGradlePropertiesFile().toPath()))); int pos = gradlePropertiesFileContents.indexOf("org.gradle.configuration-cache=true"); gradlePropertiesFileContents.insert(pos, "#"); - Files.writeString(gradlePropertiesFile.toPath(), gradlePropertiesFileContents.toString()); + Files.writeString(getGradlePropertiesFile().toPath(), gradlePropertiesFileContents.toString()); } private void createDatabase() throws Exception { diff --git a/gradle/plugin/src/functionalTest/java/org/hibernate/tool/gradle/java/NoGenerics.java b/gradle/plugin/src/functionalTest/java/org/hibernate/tool/gradle/java/NoGenerics.java index 215779bd0b..39799846f0 100644 --- a/gradle/plugin/src/functionalTest/java/org/hibernate/tool/gradle/java/NoGenerics.java +++ b/gradle/plugin/src/functionalTest/java/org/hibernate/tool/gradle/java/NoGenerics.java @@ -22,7 +22,6 @@ public class NoGenerics extends TestTemplate { private static final List GRADLE_INIT_PROJECT_ARGUMENTS = List.of( "init", "--type", "java-application", "--dsl", "groovy", "--test-framework", "junit-jupiter", "--java-version", "17"); - private File gradlePropertiesFile; private File gradleBuildFile; private File databaseFile; @@ -45,9 +44,9 @@ private void createGradleProject() throws Exception { runner.withProjectDir(getProjectDir()); BuildResult buildResult = runner.build(); assertTrue(buildResult.getOutput().contains("BUILD SUCCESSFUL")); - gradlePropertiesFile = new File(getProjectDir(), "gradle.properties"); - assertTrue(gradlePropertiesFile.exists()); - assertTrue(gradlePropertiesFile.isFile()); + setGradlePropertiesFile(new File(getProjectDir(), "gradle.properties")); + assertTrue(getGradlePropertiesFile().exists()); + assertTrue(getGradlePropertiesFile().isFile()); File appDir = new File(getProjectDir(), "app"); assertTrue(appDir.exists()); assertTrue(appDir.isDirectory()); @@ -72,10 +71,10 @@ private void editGradlePropertiesFile() throws Exception { // As this is enabled by default when initializing a new Gradle project, the setting needs to be commented out // in the gradle.properties file. StringBuffer gradlePropertiesFileContents = new StringBuffer( - new String(Files.readAllBytes(gradlePropertiesFile.toPath()))); + new String(Files.readAllBytes(getGradlePropertiesFile().toPath()))); int pos = gradlePropertiesFileContents.indexOf("org.gradle.configuration-cache=true"); gradlePropertiesFileContents.insert(pos, "#"); - Files.writeString(gradlePropertiesFile.toPath(), gradlePropertiesFileContents.toString()); + Files.writeString(getGradlePropertiesFile().toPath(), gradlePropertiesFileContents.toString()); } private void createDatabase() throws Exception { diff --git a/gradle/plugin/src/functionalTest/java/org/hibernate/tool/gradle/java/UseGenerics.java b/gradle/plugin/src/functionalTest/java/org/hibernate/tool/gradle/java/UseGenerics.java index d5c0c1a5c3..7e7e5f0838 100644 --- a/gradle/plugin/src/functionalTest/java/org/hibernate/tool/gradle/java/UseGenerics.java +++ b/gradle/plugin/src/functionalTest/java/org/hibernate/tool/gradle/java/UseGenerics.java @@ -22,7 +22,6 @@ public class UseGenerics extends TestTemplate { private static final List GRADLE_INIT_PROJECT_ARGUMENTS = List.of( "init", "--type", "java-application", "--dsl", "groovy", "--test-framework", "junit-jupiter", "--java-version", "17"); - private File gradlePropertiesFile; private File gradleBuildFile; private File databaseFile; @@ -45,9 +44,9 @@ private void createGradleProject() throws Exception { runner.withProjectDir(getProjectDir()); BuildResult buildResult = runner.build(); assertTrue(buildResult.getOutput().contains("BUILD SUCCESSFUL")); - gradlePropertiesFile = new File(getProjectDir(), "gradle.properties"); - assertTrue(gradlePropertiesFile.exists()); - assertTrue(gradlePropertiesFile.isFile()); + setGradlePropertiesFile(new File(getProjectDir(), "gradle.properties")); + assertTrue(getGradlePropertiesFile().exists()); + assertTrue(getGradlePropertiesFile().isFile()); File appDir = new File(getProjectDir(), "app"); assertTrue(appDir.exists()); assertTrue(appDir.isDirectory()); @@ -71,10 +70,10 @@ private void editGradlePropertiesFile() throws Exception { // As this is enabled by default when initializing a new Gradle project, the setting needs to be commented out // in the gradle.properties file. StringBuffer gradlePropertiesFileContents = new StringBuffer( - new String(Files.readAllBytes(gradlePropertiesFile.toPath()))); + new String(Files.readAllBytes(getGradlePropertiesFile().toPath()))); int pos = gradlePropertiesFileContents.indexOf("org.gradle.configuration-cache=true"); gradlePropertiesFileContents.insert(pos, "#"); - Files.writeString(gradlePropertiesFile.toPath(), gradlePropertiesFileContents.toString()); + Files.writeString(getGradlePropertiesFile().toPath(), gradlePropertiesFileContents.toString()); } private void createDatabase() throws Exception { diff --git a/gradle/plugin/src/functionalTest/java/org/hibernate/tool/gradle/tutorial/TutorialTest.java b/gradle/plugin/src/functionalTest/java/org/hibernate/tool/gradle/tutorial/TutorialTest.java index e8e75c089e..75ab709dff 100644 --- a/gradle/plugin/src/functionalTest/java/org/hibernate/tool/gradle/tutorial/TutorialTest.java +++ b/gradle/plugin/src/functionalTest/java/org/hibernate/tool/gradle/tutorial/TutorialTest.java @@ -23,7 +23,6 @@ public class TutorialTest extends TestTemplate { private static final List GRADLE_INIT_PROJECT_ARGUMENTS = List.of( "init", "--type", "java-application", "--dsl", "groovy", "--test-framework", "junit-jupiter", "--java-version", "17"); - private File gradlePropertiesFile; private File gradleBuildFile; private File databaseFile; @@ -55,9 +54,9 @@ private void createGradleProject() throws Exception { runner.withProjectDir(getProjectDir()); BuildResult buildResult = runner.build(); assertTrue(buildResult.getOutput().contains("BUILD SUCCESSFUL")); - gradlePropertiesFile = new File(getProjectDir(), "gradle.properties"); - assertTrue(gradlePropertiesFile.exists()); - assertTrue(gradlePropertiesFile.isFile()); + setGradlePropertiesFile(new File(getProjectDir(), "gradle.properties")); + assertTrue(getGradlePropertiesFile().exists()); + assertTrue(getGradlePropertiesFile().isFile()); File appDir = new File(getProjectDir(), "app"); assertTrue(appDir.exists()); assertTrue(appDir.isDirectory()); @@ -81,10 +80,10 @@ private void editGradlePropertiesFile() throws Exception { // As this is enabled by default when initializing a new Gradle project, the setting needs to be commented out // in the gradle.properties file. StringBuffer gradlePropertiesFileContents = new StringBuffer( - new String(Files.readAllBytes(gradlePropertiesFile.toPath()))); + new String(Files.readAllBytes(getGradlePropertiesFile().toPath()))); int pos = gradlePropertiesFileContents.indexOf("org.gradle.configuration-cache=true"); gradlePropertiesFileContents.insert(pos, "#"); - Files.writeString(gradlePropertiesFile.toPath(), gradlePropertiesFileContents.toString()); + Files.writeString(getGradlePropertiesFile().toPath(), gradlePropertiesFileContents.toString()); } private void createDatabase() throws Exception { diff --git a/gradle/plugin/src/functionalTest/java/org/hibernate/tool/it/gradle/TestTemplate.java b/gradle/plugin/src/functionalTest/java/org/hibernate/tool/it/gradle/TestTemplate.java index 5c15910c9a..a68b7dd5a6 100644 --- a/gradle/plugin/src/functionalTest/java/org/hibernate/tool/it/gradle/TestTemplate.java +++ b/gradle/plugin/src/functionalTest/java/org/hibernate/tool/it/gradle/TestTemplate.java @@ -9,8 +9,18 @@ public class TestTemplate { @TempDir private File projectDir; + private File gradlePropertiesFile; + protected File getProjectDir() { return projectDir; } + protected File getGradlePropertiesFile() { + return gradlePropertiesFile; + } + + protected void setGradlePropertiesFile(File f) { + this.gradlePropertiesFile = f; + } + }