From 6c0be214c6dbce22e0cc784385e47dae0d69c15b Mon Sep 17 00:00:00 2001 From: EdoardoP92 Date: Wed, 20 Dec 2023 20:16:36 +0100 Subject: [PATCH 1/3] fixes FileSystemException --- ...aAnnotatedQueryMethodIntegrationTests.java | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) diff --git a/spring-data-jpa/src/test/java/org/springframework/data/jpa/repository/query/EclipseLinkMetaAnnotatedQueryMethodIntegrationTests.java b/spring-data-jpa/src/test/java/org/springframework/data/jpa/repository/query/EclipseLinkMetaAnnotatedQueryMethodIntegrationTests.java index 7c5d31b1bd..9dde14c23b 100644 --- a/spring-data-jpa/src/test/java/org/springframework/data/jpa/repository/query/EclipseLinkMetaAnnotatedQueryMethodIntegrationTests.java +++ b/spring-data-jpa/src/test/java/org/springframework/data/jpa/repository/query/EclipseLinkMetaAnnotatedQueryMethodIntegrationTests.java @@ -19,17 +19,18 @@ import jakarta.persistence.EntityManagerFactory; -import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStreamReader; import java.io.Reader; import java.nio.charset.StandardCharsets; +import java.nio.file.Files; import java.nio.file.Path; import java.util.Properties; import javax.sql.DataSource; import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; @@ -58,12 +59,12 @@ import org.springframework.transaction.PlatformTransactionManager; import org.springframework.transaction.annotation.Transactional; import org.springframework.util.FileCopyUtils; -import org.springframework.util.FileSystemUtils; /** * Verify that {@link Meta}-annotated methods properly embed comments into EclipseLink queries. * * @author Greg Turnquist + * @author Edoardo Patti * @since 3.0 */ @ExtendWith(SpringExtension.class) @@ -74,16 +75,12 @@ class EclipseLinkMetaAnnotatedQueryMethodIntegrationTests { @Autowired RoleRepositoryWithMeta repository; private static final ResourceLoader RESOURCE_LOADER = new DefaultResourceLoader(); - private static final String LOG_FILE = "test-eclipselink-meta.log"; + private static String LOG_FILE; - @BeforeEach - void cleanoutLogfile() throws IOException { - new FileOutputStream(LOG_FILE).close(); - } - - @AfterAll - static void deleteLogfile() throws IOException { - FileSystemUtils.deleteRecursively(Path.of(LOG_FILE)); + @BeforeAll + static void createLogfile() throws IOException { + Path logFile = Files.createTempFile("test-eclipselink-meta", ".log"); + LOG_FILE = logFile.toAbsolutePath().toString(); } @Test // GH-775 From 4caab7aaebc4e9914e6b044c668a2f900bed013f Mon Sep 17 00:00:00 2001 From: EdoardoP92 Date: Fri, 5 Jan 2024 10:29:09 +0100 Subject: [PATCH 2/3] adds File.deleteOnExit() --- ...ipseLinkMetaAnnotatedQueryMethodIntegrationTests.java | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/spring-data-jpa/src/test/java/org/springframework/data/jpa/repository/query/EclipseLinkMetaAnnotatedQueryMethodIntegrationTests.java b/spring-data-jpa/src/test/java/org/springframework/data/jpa/repository/query/EclipseLinkMetaAnnotatedQueryMethodIntegrationTests.java index 9dde14c23b..bccaa5233c 100644 --- a/spring-data-jpa/src/test/java/org/springframework/data/jpa/repository/query/EclipseLinkMetaAnnotatedQueryMethodIntegrationTests.java +++ b/spring-data-jpa/src/test/java/org/springframework/data/jpa/repository/query/EclipseLinkMetaAnnotatedQueryMethodIntegrationTests.java @@ -31,7 +31,6 @@ import org.junit.jupiter.api.AfterAll; import org.junit.jupiter.api.BeforeAll; -import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; import org.springframework.beans.factory.annotation.Autowired; @@ -77,12 +76,18 @@ class EclipseLinkMetaAnnotatedQueryMethodIntegrationTests { private static final ResourceLoader RESOURCE_LOADER = new DefaultResourceLoader(); private static String LOG_FILE; + private static Path logFile; + @BeforeAll static void createLogfile() throws IOException { - Path logFile = Files.createTempFile("test-eclipselink-meta", ".log"); + logFile = Files.createTempFile("test-eclipselink-meta", ".log"); LOG_FILE = logFile.toAbsolutePath().toString(); } + @AfterAll static void deleteLogFile(){ + logFile.toFile().deleteOnExit(); + } + @Test // GH-775 void findAllShouldLogAComment() { From 5d72955a35080d59f9c364d6f2155a55652e885b Mon Sep 17 00:00:00 2001 From: EdoardoP92 Date: Fri, 5 Jan 2024 10:37:30 +0100 Subject: [PATCH 3/3] fixes code style --- .../EclipseLinkMetaAnnotatedQueryMethodIntegrationTests.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/spring-data-jpa/src/test/java/org/springframework/data/jpa/repository/query/EclipseLinkMetaAnnotatedQueryMethodIntegrationTests.java b/spring-data-jpa/src/test/java/org/springframework/data/jpa/repository/query/EclipseLinkMetaAnnotatedQueryMethodIntegrationTests.java index bccaa5233c..b771fd9943 100644 --- a/spring-data-jpa/src/test/java/org/springframework/data/jpa/repository/query/EclipseLinkMetaAnnotatedQueryMethodIntegrationTests.java +++ b/spring-data-jpa/src/test/java/org/springframework/data/jpa/repository/query/EclipseLinkMetaAnnotatedQueryMethodIntegrationTests.java @@ -84,7 +84,8 @@ static void createLogfile() throws IOException { LOG_FILE = logFile.toAbsolutePath().toString(); } - @AfterAll static void deleteLogFile(){ + @AfterAll + static void deleteLogFile(){ logFile.toFile().deleteOnExit(); }