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

rmannibucau pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/johnzon.git


The following commit(s) were added to refs/heads/master by this push:
     new 8cb5377  simplifying some mappe dependencies, no main code change
8cb5377 is described below

commit 8cb53770e58cc2bdd26c26bdade4eae9cb995544
Author: Romain Manni-Bucau <rmannibu...@gmail.com>
AuthorDate: Mon Apr 25 09:02:24 2022 +0200

    simplifying some mappe dependencies, no main code change
---
 johnzon-mapper/pom.xml                             | 22 +------
 .../org/apache/johnzon/mapper/NoWarningTest.java   | 73 +++++++++++++++++-----
 johnzon-mapper/src/test/resources/JPATest.xml      |  2 +-
 3 files changed, 61 insertions(+), 36 deletions(-)

diff --git a/johnzon-mapper/pom.xml b/johnzon-mapper/pom.xml
index acaa20f..f4e3427 100644
--- a/johnzon-mapper/pom.xml
+++ b/johnzon-mapper/pom.xml
@@ -35,34 +35,16 @@
       <version>${project.version}</version>
     </dependency>
 
-    <dependency>
-      <groupId>com.github.stefanbirkner</groupId>
-      <artifactId>system-rules</artifactId>
-      <version>1.8.0</version>
-      <scope>test</scope>
-      <exclusions>
-        <exclusion>
-          <groupId>commons-io</groupId>
-          <artifactId>commons-io</artifactId>
-        </exclusion>
-      </exclusions>
-    </dependency>
-    <dependency>
-      <groupId>commons-io</groupId>
-      <artifactId>commons-io</artifactId>
-      <version>2.4</version>
-      <scope>test</scope>
-    </dependency>
     <dependency>
       <groupId>org.apache.openjpa</groupId>
       <artifactId>openjpa</artifactId>
-      <version>2.4.0</version>
+      <version>3.2.2</version>
       <scope>test</scope>
     </dependency>
     <dependency>
       <groupId>com.h2database</groupId>
       <artifactId>h2</artifactId>
-      <version>1.3.166</version>
+      <version>2.1.210</version>
       <scope>test</scope>
     </dependency>
   </dependencies>
diff --git 
a/johnzon-mapper/src/test/java/org/apache/johnzon/mapper/NoWarningTest.java 
b/johnzon-mapper/src/test/java/org/apache/johnzon/mapper/NoWarningTest.java
index fcb3656..3ffb94e 100644
--- a/johnzon-mapper/src/test/java/org/apache/johnzon/mapper/NoWarningTest.java
+++ b/johnzon-mapper/src/test/java/org/apache/johnzon/mapper/NoWarningTest.java
@@ -19,29 +19,68 @@
 package org.apache.johnzon.mapper;
 
 import java.io.ByteArrayOutputStream;
+import java.io.PrintStream;
+import java.io.UnsupportedEncodingException;
 import java.util.HashMap;
 import java.util.Map;
+import java.util.logging.Handler;
+import java.util.logging.LogRecord;
+import java.util.logging.Logger;
 
 import javax.json.Json;
 
-import org.junit.Rule;
+import org.junit.After;
+import org.junit.Before;
 import org.junit.Test;
-import org.junit.contrib.java.lang.system.StandardErrorStreamLog;
-import org.junit.contrib.java.lang.system.StandardOutputStreamLog;
 
 import static org.junit.Assert.assertTrue;
 import static org.junit.Assert.assertFalse;
 
 public class NoWarningTest {
-    
-    @Rule
-    public final StandardOutputStreamLog out = new StandardOutputStreamLog();
+    public ByteArrayOutputStream out;
+    public ByteArrayOutputStream err;
+    private PrintStream oldOut;
+    private PrintStream oldErr;
+    private Handler handler;
+
+    @Before
+    public void capture() {
+        out = new ByteArrayOutputStream();
+        err = new ByteArrayOutputStream();
+        oldOut = System.out;
+        oldErr = System.err;
+        System.setOut(new PrintStream(out));
+        final PrintStream stderr = new PrintStream(err);
+        System.setErr(stderr);
+        handler = new Handler() {
+            @Override
+            public void publish(final LogRecord record) {
+                stderr.println(record.getMessage());
+                oldErr.println(record.getMessage());
+            }
+
+            @Override
+            public void flush() {
+                // no-op
+            }
 
-    @Rule
-    public final StandardErrorStreamLog err = new StandardErrorStreamLog();
+            @Override
+            public void close() throws SecurityException {
+                flush();
+            }
+        };
+        Logger.getLogger("").addHandler(handler);
+    }
+
+    @After
+    public void reset() {
+        System.setOut(oldOut);
+        System.setErr(oldErr);
+        Logger.getLogger("").removeHandler(handler);
+    }
 
     @Test
-    public void noWarn() {
+    public void noWarn() throws UnsupportedEncodingException {
         new MapperBuilder()
                 .setEncoding("UTF-8")
                 .setSupportConstructors(true)
@@ -52,19 +91,23 @@ public class NoWarningTest {
                 .setMaxSize(789465)
                 .setSkipNull(true)
                 .setSupportsComments(true)
-                .build();
+                .build()
+                .close();
         // no warn log
-        assertTrue(out.getLog().isEmpty());
-        assertTrue(err.getLog().isEmpty());
+        assertTrue(out.toString("UTF-8").isEmpty());
+        assertTrue(err.toString("UTF-8").isEmpty());
     }
     
     @Test
-    public void warn() {
+    public void warn() throws UnsupportedEncodingException {
         Map<String, Object> unsupportedConfig = new HashMap<String, Object>();
         unsupportedConfig.put("xxx.yyy.zzz", "");
-        Json.createGeneratorFactory(unsupportedConfig).createGenerator(new 
ByteArrayOutputStream());
+        Json.createGeneratorFactory(unsupportedConfig)
+                .createGenerator(new ByteArrayOutputStream())
+                .write(0)
+                .close();
         //warn log
-        String log = out.getLog()+err.getLog();
+        String log = out.toString("UTF-8") + err.toString("UTF-8");
         assertFalse(log.isEmpty());
         assertTrue(log.contains("xxx.yyy.zzz"));
     }
diff --git a/johnzon-mapper/src/test/resources/JPATest.xml 
b/johnzon-mapper/src/test/resources/JPATest.xml
index 7073a3c..4650dc8 100644
--- a/johnzon-mapper/src/test/resources/JPATest.xml
+++ b/johnzon-mapper/src/test/resources/JPATest.xml
@@ -26,7 +26,7 @@
     <exclude-unlisted-classes>true</exclude-unlisted-classes>
     <properties>
       <property name="javax.persistence.jdbc.driver" value="org.h2.Driver" />
-      <property name="javax.persistence.jdbc.url" value="jdbc:h2:target/h2-3" 
/>
+      <property name="javax.persistence.jdbc.url" 
value="jdbc:h2:mem:jpa;DB_CLOSE_DELAY=-1" />
       <property name="javax.persistence.jdbc.user" value="sa" />
       <property name="openjpa.RuntimeUnenhancedClasses" value="supported" />
       <property name="openjpa.jdbc.SynchronizeMappings" 
value="buildSchema(ForeignKeys=true)"/>

Reply via email to