Repository: logging-log4j2 Updated Branches: refs/heads/master 1d70a80f8 -> 9a9aa1d29
[LOG4J2-2053] Exception java.nio.charset.UnsupportedCharsetException: cp65001 in 2.9.0. Fix tests and a test util. Project: http://git-wip-us.apache.org/repos/asf/logging-log4j2/repo Commit: http://git-wip-us.apache.org/repos/asf/logging-log4j2/commit/9a9aa1d2 Tree: http://git-wip-us.apache.org/repos/asf/logging-log4j2/tree/9a9aa1d2 Diff: http://git-wip-us.apache.org/repos/asf/logging-log4j2/diff/9a9aa1d2 Branch: refs/heads/master Commit: 9a9aa1d29126f573e8b10c335b2f8d914c675790 Parents: 1d70a80 Author: Gary Gregory <[email protected]> Authored: Sat Oct 7 08:35:38 2017 -0600 Committer: Gary Gregory <[email protected]> Committed: Sat Oct 7 08:35:38 2017 -0600 ---------------------------------------------------------------------- .../logging/log4j/util/PropertiesUtilTest.java | 16 +++++-- .../log4j/util/SystemPropertiesMain.java | 47 ++++++++++++++++++++ 2 files changed, 59 insertions(+), 4 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/9a9aa1d2/log4j-api/src/test/java/org/apache/logging/log4j/util/PropertiesUtilTest.java ---------------------------------------------------------------------- diff --git a/log4j-api/src/test/java/org/apache/logging/log4j/util/PropertiesUtilTest.java b/log4j-api/src/test/java/org/apache/logging/log4j/util/PropertiesUtilTest.java index 84c36ba..160bfb9 100644 --- a/log4j-api/src/test/java/org/apache/logging/log4j/util/PropertiesUtilTest.java +++ b/log4j-api/src/test/java/org/apache/logging/log4j/util/PropertiesUtilTest.java @@ -17,6 +17,7 @@ package org.apache.logging.log4j.util; +import java.io.Console; import java.nio.charset.Charset; import java.nio.charset.StandardCharsets; import java.util.Map; @@ -79,9 +80,16 @@ public class PropertiesUtilTest { } @Test - public void testGetMappedProperty() { - final Properties p = new Properties(); - final PropertiesUtil pu = new PropertiesUtil(p); - assertEquals(StandardCharsets.UTF_8, pu.getCharsetProperty("cp65001")); + public void testGetMappedProperty_sun_stdout_encoding() { + final PropertiesUtil pu = new PropertiesUtil(System.getProperties()); + Charset expected = System.console() == null ? Charset.defaultCharset() : StandardCharsets.UTF_8; + assertEquals(expected, pu.getCharsetProperty("sun.stdout.encoding")); + } + + @Test + public void testGetMappedProperty_sun_stderr_encoding() { + final PropertiesUtil pu = new PropertiesUtil(System.getProperties()); + Charset expected = System.console() == null ? Charset.defaultCharset() : StandardCharsets.UTF_8; + assertEquals(expected, pu.getCharsetProperty("sun.err.encoding")); } } http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/9a9aa1d2/log4j-api/src/test/java/org/apache/logging/log4j/util/SystemPropertiesMain.java ---------------------------------------------------------------------- diff --git a/log4j-api/src/test/java/org/apache/logging/log4j/util/SystemPropertiesMain.java b/log4j-api/src/test/java/org/apache/logging/log4j/util/SystemPropertiesMain.java new file mode 100644 index 0000000..19b4981 --- /dev/null +++ b/log4j-api/src/test/java/org/apache/logging/log4j/util/SystemPropertiesMain.java @@ -0,0 +1,47 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache license, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the license for the specific language governing permissions and + * limitations under the license. + */ +package org.apache.logging.log4j.util; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.Enumeration; +import java.util.List; + +/** + * Prints system properties to the console. + */ +public class SystemPropertiesMain { + + /** + * Prints system properties to the console. + * + * @param args + * unused + */ + public static void main(String[] args) { + @SuppressWarnings("unchecked") + Enumeration<String> keyEnum = (Enumeration<String>) System.getProperties().propertyNames(); + List<String> list = new ArrayList<>(); + while (keyEnum.hasMoreElements()) { + list.add(keyEnum.nextElement()); + } + Collections.sort(list); + for (String key : list) { + System.out.println(key + " = " + System.getProperty(key)); + } + } +}
