Repository: logging-log4j2
Updated Branches:
  refs/heads/master b5662cf22 -> 551cf8399


Unit test for JsonUtils


Project: http://git-wip-us.apache.org/repos/asf/logging-log4j2/repo
Commit: http://git-wip-us.apache.org/repos/asf/logging-log4j2/commit/551cf839
Tree: http://git-wip-us.apache.org/repos/asf/logging-log4j2/tree/551cf839
Diff: http://git-wip-us.apache.org/repos/asf/logging-log4j2/diff/551cf839

Branch: refs/heads/master
Commit: 551cf83998b73f033fb00a8602839d8395f4f8b9
Parents: b5662cf
Author: Mikael StÃ¥ldal <[email protected]>
Authored: Fri Nov 18 17:49:29 2016 +0100
Committer: Mikael StÃ¥ldal <[email protected]>
Committed: Fri Nov 18 17:59:42 2016 +0100

----------------------------------------------------------------------
 .../logging/log4j/core/util/JsonUtilsTest.java  | 74 ++++++++++++++++++++
 1 file changed, 74 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/551cf839/log4j-core/src/test/java/org/apache/logging/log4j/core/util/JsonUtilsTest.java
----------------------------------------------------------------------
diff --git 
a/log4j-core/src/test/java/org/apache/logging/log4j/core/util/JsonUtilsTest.java
 
b/log4j-core/src/test/java/org/apache/logging/log4j/core/util/JsonUtilsTest.java
new file mode 100644
index 0000000..fdfb28e
--- /dev/null
+++ 
b/log4j-core/src/test/java/org/apache/logging/log4j/core/util/JsonUtilsTest.java
@@ -0,0 +1,74 @@
+/*
+ * 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.core.util;
+
+import org.junit.Test;
+
+import static org.junit.Assert.*;
+
+/**
+ * This class is borrowed from <a 
href="https://github.com/FasterXML/jackson-core";>Jackson</a>.
+ */
+public class JsonUtilsTest {
+
+    @Test
+    public void testQuoteCharSequenceAsString() throws Exception
+    {
+        StringBuilder output = new StringBuilder();
+        StringBuilder builder = new StringBuilder();
+        builder.append("foobar");
+        JsonUtils.quoteAsString(builder, output);
+        assertEquals("foobar", output.toString());
+        builder.setLength(0);
+        output.setLength(0);
+        builder.append("\"x\"");
+        JsonUtils.quoteAsString(builder, output);
+        assertEquals("\\\"x\\\"", output.toString());
+    }
+
+    // For [JACKSON-853]
+    @Test
+    public void testQuoteLongCharSequenceAsString() throws Exception
+    {
+        StringBuilder output = new StringBuilder();
+        StringBuilder input = new StringBuilder();
+        StringBuilder sb2 = new StringBuilder();
+        for (int i = 0; i < 1111; ++i) {
+            input.append('"');
+            sb2.append("\\\"");
+        }
+        String exp = sb2.toString();
+        JsonUtils.quoteAsString(input, output);
+        assertEquals(2*input.length(), output.length());
+        assertEquals(exp, output.toString());
+
+    }
+
+    // [JACKSON-884]
+    @Test
+    public void testCharSequenceWithCtrlChars() throws Exception
+    {
+        char[] input = new char[] { 0, 1, 2, 3, 4 };
+        StringBuilder builder = new StringBuilder();
+        builder.append(input);
+        StringBuilder output = new StringBuilder();
+        JsonUtils.quoteAsString(builder, output);
+        assertEquals("\\u0000\\u0001\\u0002\\u0003\\u0004", output.toString());
+    }
+
+}

Reply via email to