|
| 1 | +/* |
| 2 | + * Copyright 2016, Google Inc. |
| 3 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | + * you may not use this file except in compliance with the License. |
| 5 | + * You may obtain a copy of the License at |
| 6 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 7 | + * Unless required by applicable law or agreed to in writing, software |
| 8 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 9 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 10 | + * See the License for the specific language governing permissions and |
| 11 | + * limitations under the License. |
| 12 | + */ |
| 13 | + |
| 14 | +package com.google.census; |
| 15 | + |
| 16 | +import static com.google.common.truth.Truth.assertThat; |
| 17 | + |
| 18 | +import java.util.Arrays; |
| 19 | +import org.junit.Test; |
| 20 | + |
| 21 | +public class StringSanitizationTest { |
| 22 | + @Test |
| 23 | + public void testMaxLength() { |
| 24 | + char[] string = new char[StringSanitization.MAX_LENGTH]; |
| 25 | + char[] truncString = new char[StringSanitization.MAX_LENGTH + 10]; |
| 26 | + Arrays.fill(string, 'v'); |
| 27 | + Arrays.fill(truncString, 'v'); |
| 28 | + assertThat(StringSanitization.sanitize(new String(truncString))).isEqualTo(new String(string)); |
| 29 | + } |
| 30 | + |
| 31 | + @Test |
| 32 | + public void testBadChar() { |
| 33 | + String string = "\2ab\3cd"; |
| 34 | + assertThat(StringSanitization.sanitize(string).toString()).isEqualTo("_ab_cd"); |
| 35 | + } |
| 36 | + |
| 37 | + @Test(expected=AssertionError.class) |
| 38 | + public void testConstructor() { |
| 39 | + new StringSanitization(); |
| 40 | + } |
| 41 | +} |
0 commit comments