You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by or...@apache.org on 2022/10/03 15:58:37 UTC

[camel] 08/11: CAMEL-18575: use JUnit's 5 TempDir annotation in camel-jaxb

This is an automated email from the ASF dual-hosted git repository.

orpiske pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/camel.git

commit f812558136f1e255756cee79d0628130f05403dd
Author: Otavio Rodolfo Piske <an...@gmail.com>
AuthorDate: Mon Oct 3 14:55:34 2022 +0200

    CAMEL-18575: use JUnit's 5 TempDir annotation in camel-jaxb
---
 .../example/ExplicitEncodingAndXMLCharFilteringTest.java      | 10 +++++++---
 .../org/apache/camel/example/ExplicitFileEncodingTest.java    | 11 ++++++++---
 2 files changed, 15 insertions(+), 6 deletions(-)

diff --git a/components/camel-jaxb/src/test/java/org/apache/camel/example/ExplicitEncodingAndXMLCharFilteringTest.java b/components/camel-jaxb/src/test/java/org/apache/camel/example/ExplicitEncodingAndXMLCharFilteringTest.java
index 4c0115f177e..a5f7487372e 100644
--- a/components/camel-jaxb/src/test/java/org/apache/camel/example/ExplicitEncodingAndXMLCharFilteringTest.java
+++ b/components/camel-jaxb/src/test/java/org/apache/camel/example/ExplicitEncodingAndXMLCharFilteringTest.java
@@ -21,6 +21,7 @@ import java.io.InputStream;
 import java.io.InputStreamReader;
 import java.io.Reader;
 import java.nio.charset.StandardCharsets;
+import java.nio.file.Path;
 
 import javax.xml.bind.JAXBContext;
 import javax.xml.bind.Unmarshaller;
@@ -30,10 +31,13 @@ import org.apache.camel.component.mock.MockEndpoint;
 import org.apache.camel.converter.jaxb.JaxbDataFormat;
 import org.apache.camel.test.junit5.CamelTestSupport;
 import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.io.TempDir;
 
 import static org.junit.jupiter.api.Assertions.assertEquals;
 
 public class ExplicitEncodingAndXMLCharFilteringTest extends CamelTestSupport {
+    @TempDir
+    Path testDirectory;
 
     @Test
     public void testIsoAndCharacterFiltering() throws Exception {
@@ -46,14 +50,14 @@ public class ExplicitEncodingAndXMLCharFilteringTest extends CamelTestSupport {
         order.setPrice(2.22);
 
         MockEndpoint result = getMockEndpoint("mock:file");
-        result.expectedFileExists(testFile("output.xml"));
+        result.expectedFileExists(testDirectory.resolve("output.xml"));
 
         template.sendBody("direct:start", order);
         assertMockEndpointsSatisfied();
 
         JAXBContext jaxbContext = JAXBContext.newInstance("org.apache.camel.example");
         Unmarshaller unmarshaller = jaxbContext.createUnmarshaller();
-        InputStream inputStream = new FileInputStream(testFile("output.xml").toFile());
+        InputStream inputStream = new FileInputStream(testDirectory.resolve("output.xml").toFile());
         Reader reader = new InputStreamReader(inputStream, StandardCharsets.ISO_8859_1);
         PurchaseOrder obj = (PurchaseOrder) unmarshaller.unmarshal(reader);
         assertEquals(expected, obj.getName());
@@ -70,7 +74,7 @@ public class ExplicitEncodingAndXMLCharFilteringTest extends CamelTestSupport {
 
                 from("direct:start")
                         .marshal(jaxb)
-                        .to(fileUri("?fileName=output.xml&charset=iso-8859-1"));
+                        .to(fileUri(testDirectory, "?fileName=output.xml&charset=iso-8859-1"));
             }
         };
     }
diff --git a/components/camel-jaxb/src/test/java/org/apache/camel/example/ExplicitFileEncodingTest.java b/components/camel-jaxb/src/test/java/org/apache/camel/example/ExplicitFileEncodingTest.java
index ba55d201c42..b39b89db75e 100644
--- a/components/camel-jaxb/src/test/java/org/apache/camel/example/ExplicitFileEncodingTest.java
+++ b/components/camel-jaxb/src/test/java/org/apache/camel/example/ExplicitFileEncodingTest.java
@@ -16,6 +16,8 @@
  */
 package org.apache.camel.example;
 
+import java.nio.file.Path;
+
 import javax.xml.bind.JAXBContext;
 import javax.xml.bind.Unmarshaller;
 
@@ -24,10 +26,13 @@ import org.apache.camel.component.mock.MockEndpoint;
 import org.apache.camel.converter.jaxb.JaxbDataFormat;
 import org.apache.camel.test.junit5.CamelTestSupport;
 import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.io.TempDir;
 
 import static org.junit.jupiter.api.Assertions.assertEquals;
 
 public class ExplicitFileEncodingTest extends CamelTestSupport {
+    @TempDir
+    Path testDirectory;
 
     @Test
     public void testISOFileEncoding() throws Exception {
@@ -39,14 +44,14 @@ public class ExplicitFileEncodingTest extends CamelTestSupport {
         order.setPrice(2.22);
 
         MockEndpoint result = getMockEndpoint("mock:file");
-        result.expectedFileExists(testFile("output.txt"));
+        result.expectedFileExists(testDirectory.resolve("output.txt"));
 
         template.sendBody("direct:start", order);
         assertMockEndpointsSatisfied();
 
         JAXBContext jaxbContext = JAXBContext.newInstance("org.apache.camel.example");
         Unmarshaller unmarshaller = jaxbContext.createUnmarshaller();
-        PurchaseOrder obj = (PurchaseOrder) unmarshaller.unmarshal(testFile("output.txt").toFile());
+        PurchaseOrder obj = (PurchaseOrder) unmarshaller.unmarshal(testDirectory.resolve("output.txt").toFile());
         assertEquals(obj.getName(), name);
     }
 
@@ -60,7 +65,7 @@ public class ExplicitFileEncodingTest extends CamelTestSupport {
 
                 from("direct:start")
                         .marshal(jaxb)
-                        .to(fileUri("?fileName=output.txt&charset=iso-8859-1"));
+                        .to(fileUri(testDirectory, "?fileName=output.txt&charset=iso-8859-1"));
             }
         };
     }