Skip to content

Commit e9d9a11

Browse files
committed
HBX-3080: Refactor the Gradle integration tests to factor out common code
- Create method 'addHibernateToolsExtension(StringBuffer)' in class TestTemplate - Pull up method 'editGradleBuildFile()' Signed-off-by: Koen Aers <[email protected]>
1 parent bb16d5a commit e9d9a11

File tree

6 files changed

+16
-44
lines changed

6 files changed

+16
-44
lines changed

gradle/plugin/src/functionalTest/java/org/hibernate/tool/gradle/java/JpaDefaultTest.java

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -41,14 +41,6 @@ private void verifyDatabase() throws Exception {
4141
assertEquals("foo", resultSet.getString(2));
4242
}
4343

44-
private void editGradleBuildFile() throws Exception {
45-
StringBuffer gradleBuildFileContents = new StringBuffer(
46-
new String(Files.readAllBytes(getGradleBuildFile().toPath())));
47-
addHibernateToolsPluginLine(gradleBuildFileContents);
48-
addH2DatabaseDependencyLine(gradleBuildFileContents);
49-
Files.writeString(getGradleBuildFile().toPath(), gradleBuildFileContents.toString());
50-
}
51-
5244
private void editGradlePropertiesFile() throws Exception {
5345
// The Hibernate Tools Gradle plugin does not support the configuration cache.
5446
// As this is enabled by default when initializing a new Gradle project, the setting needs to be commented out

gradle/plugin/src/functionalTest/java/org/hibernate/tool/gradle/java/NoAnnotationsTest.java

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -41,15 +41,6 @@ private void verifyDatabase() throws Exception {
4141
assertEquals("foo", resultSet.getString(2));
4242
}
4343

44-
private void editGradleBuildFile() throws Exception {
45-
StringBuffer gradleBuildFileContents = new StringBuffer(
46-
new String(Files.readAllBytes(getGradleBuildFile().toPath())));
47-
addHibernateToolsPluginLine(gradleBuildFileContents);
48-
addH2DatabaseDependencyLine(gradleBuildFileContents);
49-
addHibernateToolsExtension(gradleBuildFileContents);
50-
Files.writeString(getGradleBuildFile().toPath(), gradleBuildFileContents.toString());
51-
}
52-
5344
private void editGradlePropertiesFile() throws Exception {
5445
// The Hibernate Tools Gradle plugin does not support the configuration cache.
5546
// As this is enabled by default when initializing a new Gradle project, the setting needs to be commented out
@@ -111,7 +102,7 @@ private void verifyProject() throws Exception {
111102
assertTrue(generatedPersonJavaFileContents.contains("public class Person "));
112103
}
113104

114-
private void addHibernateToolsExtension(StringBuffer gradleBuildFileContents) {
105+
protected void addHibernateToolsExtension(StringBuffer gradleBuildFileContents) {
115106
int pos = gradleBuildFileContents.indexOf("dependencies {");
116107
pos = gradleBuildFileContents.indexOf("}", pos);
117108
StringBuffer hibernateToolsExtension = new StringBuffer();

gradle/plugin/src/functionalTest/java/org/hibernate/tool/gradle/java/NoGenerics.java

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -31,15 +31,6 @@ public void testTutorial() throws Exception {
3131
verifyProject();
3232
}
3333

34-
private void editGradleBuildFile() throws Exception {
35-
StringBuffer gradleBuildFileContents = new StringBuffer(
36-
new String(Files.readAllBytes(getGradleBuildFile().toPath())));
37-
addHibernateToolsPluginLine(gradleBuildFileContents);
38-
addH2DatabaseDependencyLine(gradleBuildFileContents);
39-
addHibernateToolsExtension(gradleBuildFileContents);
40-
Files.writeString(getGradleBuildFile().toPath(), gradleBuildFileContents.toString());
41-
}
42-
4334
private void editGradlePropertiesFile() throws Exception {
4435
// The Hibernate Tools Gradle plugin does not support the configuration cache.
4536
// As this is enabled by default when initializing a new Gradle project, the setting needs to be commented out
@@ -111,7 +102,7 @@ private void verifyProject() throws Exception {
111102
assertTrue(generatedItemJavaFileContents.contains("public class Item "));
112103
}
113104

114-
private void addHibernateToolsExtension(StringBuffer gradleBuildFileContents) {
105+
protected void addHibernateToolsExtension(StringBuffer gradleBuildFileContents) {
115106
int pos = gradleBuildFileContents.indexOf("dependencies {");
116107
pos = gradleBuildFileContents.indexOf("}", pos);
117108
StringBuffer hibernateToolsExtension = new StringBuffer();

gradle/plugin/src/functionalTest/java/org/hibernate/tool/gradle/java/UseGenerics.java

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -31,14 +31,6 @@ public void testTutorial() throws Exception {
3131
verifyProject();
3232
}
3333

34-
private void editGradleBuildFile() throws Exception {
35-
StringBuffer gradleBuildFileContents = new StringBuffer(
36-
new String(Files.readAllBytes(getGradleBuildFile().toPath())));
37-
addHibernateToolsPluginLine(gradleBuildFileContents);
38-
addH2DatabaseDependencyLine(gradleBuildFileContents);
39-
Files.writeString(getGradleBuildFile().toPath(), gradleBuildFileContents.toString());
40-
}
41-
4234
private void editGradlePropertiesFile() throws Exception {
4335
// The Hibernate Tools Gradle plugin does not support the configuration cache.
4436
// As this is enabled by default when initializing a new Gradle project, the setting needs to be commented out

gradle/plugin/src/functionalTest/java/org/hibernate/tool/gradle/tutorial/TutorialTest.java

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -41,14 +41,6 @@ private void verifyDatabase() throws Exception {
4141
assertEquals("foo", resultSet.getString(2));
4242
}
4343

44-
private void editGradleBuildFile() throws Exception {
45-
StringBuffer gradleBuildFileContents = new StringBuffer(
46-
new String(Files.readAllBytes(getGradleBuildFile().toPath())));
47-
addHibernateToolsPluginLine(gradleBuildFileContents);
48-
addH2DatabaseDependencyLine(gradleBuildFileContents);
49-
Files.writeString(getGradleBuildFile().toPath(), gradleBuildFileContents.toString());
50-
}
51-
5244
private void editGradlePropertiesFile() throws Exception {
5345
// The Hibernate Tools Gradle plugin does not support the configuration cache.
5446
// As this is enabled by default when initializing a new Gradle project, the setting needs to be commented out

gradle/plugin/src/functionalTest/java/org/hibernate/tool/it/gradle/TestTemplate.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import static org.junit.jupiter.api.Assertions.assertTrue;
55

66
import java.io.File;
7+
import java.nio.file.Files;
78
import java.util.List;
89

910
import org.junit.jupiter.api.io.TempDir;
@@ -51,6 +52,15 @@ protected void createGradleProject() throws Exception {
5152
assertFalse(getDatabaseFile().exists());
5253
}
5354

55+
protected void editGradleBuildFile() throws Exception {
56+
StringBuffer gradleBuildFileContents = new StringBuffer(
57+
new String(Files.readAllBytes(getGradleBuildFile().toPath())));
58+
addHibernateToolsPluginLine(gradleBuildFileContents);
59+
addH2DatabaseDependencyLine(gradleBuildFileContents);
60+
addHibernateToolsExtension(gradleBuildFileContents);
61+
Files.writeString(getGradleBuildFile().toPath(), gradleBuildFileContents.toString());
62+
}
63+
5464
protected String constructH2DatabaseDependencyLine() {
5565
return " implementation 'com.h2database:h2:" + System.getenv("H2_VERSION") + "'";
5666
}
@@ -76,4 +86,8 @@ protected void addHibernateToolsPluginLine(StringBuffer gradleBuildFileContents)
7686
gradleBuildFileContents.insert(pos, constructHibernateToolsPluginLine() + "\n");
7787
}
7888

89+
protected void addHibernateToolsExtension(StringBuffer gradleBuildFileContents) {
90+
91+
}
92+
7993
}

0 commit comments

Comments
 (0)