|
| 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 | + * https://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 | + |
| 18 | +package org.apache.commons.lang3; |
| 19 | + |
| 20 | +import static org.junit.jupiter.api.Assertions.assertEquals; |
| 21 | +import static org.junit.jupiter.api.Assertions.assertNull; |
| 22 | + |
| 23 | +import org.junit.jupiter.api.Test; |
| 24 | + |
| 25 | +/** |
| 26 | + * Tests {@link StringUtils} trim methods. |
| 27 | + */ |
| 28 | +class StringUtilsTrimTest extends AbstractLangTest { |
| 29 | + |
| 30 | + private static final String FOO = "foo"; |
| 31 | + |
| 32 | + @Test |
| 33 | + void testTrim() { |
| 34 | + assertEquals(FOO, StringUtils.trim(FOO + " ")); |
| 35 | + assertEquals(FOO, StringUtils.trim(" " + FOO + " ")); |
| 36 | + assertEquals(FOO, StringUtils.trim(" " + FOO)); |
| 37 | + assertEquals(FOO, StringUtils.trim(FOO + "")); |
| 38 | + assertEquals("", StringUtils.trim(" \t\r\n\b ")); |
| 39 | + assertEquals("", StringUtils.trim(StringUtilsTest.TRIMMABLE)); |
| 40 | + assertEquals(StringUtilsTest.NON_TRIMMABLE, StringUtils.trim(StringUtilsTest.NON_TRIMMABLE)); |
| 41 | + assertEquals("", StringUtils.trim("")); |
| 42 | + assertNull(StringUtils.trim(null)); |
| 43 | + } |
| 44 | + |
| 45 | + @Test |
| 46 | + void testTrimToEmpty() { |
| 47 | + assertEquals(FOO, StringUtils.trimToEmpty(FOO + " ")); |
| 48 | + assertEquals(FOO, StringUtils.trimToEmpty(" " + FOO + " ")); |
| 49 | + assertEquals(FOO, StringUtils.trimToEmpty(" " + FOO)); |
| 50 | + assertEquals(FOO, StringUtils.trimToEmpty(FOO + "")); |
| 51 | + assertEquals("", StringUtils.trimToEmpty(" \t\r\n\b ")); |
| 52 | + assertEquals("", StringUtils.trimToEmpty(StringUtilsTest.TRIMMABLE)); |
| 53 | + assertEquals(StringUtilsTest.NON_TRIMMABLE, StringUtils.trimToEmpty(StringUtilsTest.NON_TRIMMABLE)); |
| 54 | + assertEquals("", StringUtils.trimToEmpty("")); |
| 55 | + assertEquals("", StringUtils.trimToEmpty(null)); |
| 56 | + } |
| 57 | + |
| 58 | + @Test |
| 59 | + void testTrimToNull() { |
| 60 | + assertEquals(FOO, StringUtils.trimToNull(FOO + " ")); |
| 61 | + assertEquals(FOO, StringUtils.trimToNull(" " + FOO + " ")); |
| 62 | + assertEquals(FOO, StringUtils.trimToNull(" " + FOO)); |
| 63 | + assertEquals(FOO, StringUtils.trimToNull(FOO + "")); |
| 64 | + assertNull(StringUtils.trimToNull(" \t\r\n\b ")); |
| 65 | + assertNull(StringUtils.trimToNull(StringUtilsTest.TRIMMABLE)); |
| 66 | + assertEquals(StringUtilsTest.NON_TRIMMABLE, StringUtils.trimToNull(StringUtilsTest.NON_TRIMMABLE)); |
| 67 | + assertNull(StringUtils.trimToNull("")); |
| 68 | + assertNull(StringUtils.trimToNull(null)); |
| 69 | + } |
| 70 | +} |
0 commit comments