1+ /*
2+ * Licensed to the Apache Software Foundation (ASF) under one or more
3+ * contributor license agreements. See the NOTICE file distributed with
4+ * this work for additional information regarding copyright ownership.
5+ * The ASF licenses this file to You under the Apache License, Version 2.0
6+ * (the "License"); you may not use this file except in compliance with
7+ * the License. You may obtain a copy of the License at
8+ *
9+ * http://www.apache.org/licenses/LICENSE-2.0
10+ *
11+ * Unless required by applicable law or agreed to in writing, software
12+ * distributed under the License is distributed on an "AS IS" BASIS,
13+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+ * See the License for the specific language governing permissions and
15+ * limitations under the License.
16+ */
17+ package org .apache .juli ;
18+
19+ import org .junit .Assert ;
20+ import org .junit .Test ;
21+
22+ public class TestLogUtil {
23+
24+ @ Test
25+ public void testEscapeForLoggingEmptyString () {
26+ doTestEscapeForLogging ("" );
27+ }
28+
29+
30+ @ Test
31+ public void testEscapeForLoggingNone () {
32+ doTestEscapeForLogging ("No escaping" );
33+ }
34+
35+
36+ @ Test
37+ public void testEscapeForLoggingControlStart () {
38+ doTestEscapeForLogging ("\u0006 Text" , "\\ u0006Text" );
39+ }
40+
41+
42+ @ Test
43+ public void testEscapeForLoggingControlMiddle () {
44+ doTestEscapeForLogging ("Text\u0006 Text" , "Text\\ u0006Text" );
45+ }
46+
47+
48+ @ Test
49+ public void testEscapeForLoggingControlEnd () {
50+ doTestEscapeForLogging ("Text\u0006 " , "Text\\ u0006" );
51+ }
52+
53+
54+ @ Test
55+ public void testEscapeForLoggingControlOnly () {
56+ doTestEscapeForLogging ("\u0006 " , "\\ u0006" );
57+ }
58+
59+
60+ @ Test
61+ public void testEscapeForLoggingControlsStart () {
62+ doTestEscapeForLogging ("\u0006 \u0007 Text" , "\\ u0006\\ u0007Text" );
63+ }
64+
65+
66+ @ Test
67+ public void testEscapeForLoggingControlsMiddle () {
68+ doTestEscapeForLogging ("Text\u0006 \u0007 Text" , "Text\\ u0006\\ u0007Text" );
69+ }
70+
71+
72+ @ Test
73+ public void testEscapeForLoggingControlsEnd () {
74+ doTestEscapeForLogging ("Text\u0006 \u0007 " , "Text\\ u0006\\ u0007" );
75+ }
76+
77+
78+ @ Test
79+ public void testEscapeForLoggingControlsOnly () {
80+ doTestEscapeForLogging ("\u0006 \u0007 " , "\\ u0006\\ u0007" );
81+ }
82+
83+
84+ private void doTestEscapeForLogging (String input ) {
85+ doTestEscapeForLogging (input , input );
86+ }
87+
88+
89+ private void doTestEscapeForLogging (String input , String expected ) {
90+ String result = LogUtil .escape (input );
91+ Assert .assertEquals (expected , result );
92+ }
93+ }
0 commit comments