<commit_before>/*
 * Copyright 2002-2017 the original author or authors.
 *
 * Licensed 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.
 */
/*
 * iBankApp
 *
 * License : Apache License,Version 2.0, January 2004
 *
 * See the LICENSE file in English or LICENSE.zh_CN in chinese
 * in the root directory or <http://www.apache.org/licenses/>.
 */

package org.ibankapp.base.util.test;

import static org.junit.Assert.assertArrayEquals;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertSame;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;

import java.util.Arrays;
import java.util.Locale;
import java.util.Properties;
import org.ibankapp.base.util.StringUtils;
import org.junit.Assert;
import org.junit.Test;

/**
 * The tests of StringUtils.
 *
 * @author <NAME>
 * @author <NAME>
 * @author <NAME>
 */
public class StringUtilsTests {

  @Test
  public void testHasTextBlank() throws Exception {
    String blank = "          ";
    assertEquals(false, StringUtils.hasText(blank));
  }

  @Test
  public void testHasTextNullEmpty() throws Exception {
    assertEquals(false, StringUtils.hasText(null));
    assertEquals(false, StringUtils.hasText(""));
  }

  @Test
  public void testHasTextValid() throws Exception {
    assertEquals(true, StringUtils.hasText("t"));
  }

  @Test
  public void testContainsWhitespace() throws Exception {
    assertFalse(StringUtils.containsWhitespace(null));
    assertFalse(StringUtils.containsWhitespace(""));
    assertFalse(StringUtils.containsWhitespace("a"));
    assertFalse(StringUtils.containsWhitespace("abc"));
    assertTrue(StringUtils.containsWhitespace(" "));
    assertTrue(StringUtils.containsWhitespace(" a"));
    assertTrue(StringUtils.containsWhitespace("abc "));
    assertTrue(StringUtils.containsWhitespace("a b"));
    assertTrue(StringUtils.containsWhitespace("a  b"));
  }

  @Test
  public void testTrimWhitespace() throws Exception {
    assertEquals(null, StringUtils.trimWhitespace(null));
    assertEquals("", StringUtils.trimWhitespace(""));
    assertEquals("", StringUtils.trimWhitespace(" "));
    assertEquals("", StringUtils.trimWhitespace("\t"));
    assertEquals("a", StringUtils.trimWhitespace(" a"));
    assertEquals("a", StringUtils.trimWhitespace("a "));
    assertEquals("a", StringUtils.trimWhitespace(" a "));
    assertEquals("a b", StringUtils.trimWhitespace(" a b "));
    assertEquals("a b  c", StringUtils.trimWhitespace(" a b  c "));
  }

  @Test
  public void testTrimAllWhitespace() throws Exception {
    assertEquals("", StringUtils.trimAllWhitespace(""));
    assertEquals("", StringUtils.trimAllWhitespace(" "));
    assertEquals("", StringUtils.trimAllWhitespace("\t"));
    assertEquals("a", StringUtils.trimAllWhitespace(" a"));
    assertEquals("a", StringUtils.trimAllWhitespace("a "));
    assertEquals("a", StringUtils.trimAllWhitespace(" a "));
    assertEquals("ab", StringUtils.trimAllWhitespace(" a b "));
    assertEquals("abc", StringUtils.trimAllWhitespace(" a b  c "));
  }

  @Test
  public void testTrimLeadingWhitespace() throws Exception {
    assertEquals(null, StringUtils.trimLeadingWhitespace(null));
    assertEquals("", StringUtils.trimLeadingWhitespace(""));
    assertEquals("", StringUtils.trimLeadingWhitespace(" "));
    assertEquals("", StringUtils.trimLeadingWhitespace("\t"));
    assertEquals("a", StringUtils.trimLeadingWhitespace(" a"));
    assertEquals("a ", StringUtils.trimLeadingWhitespace("a "));
    assertEquals("a ", StringUtils.trimLeadingWhitespace(" a "));
    assertEquals("a b ", StringUtils.trimLeadingWhitespace(" a b "));
    assertEquals("a b  c ", StringUtils.trimLeadingWhitespace(" a b  c "));
  }

  @Test
  public void testTrimTrailingWhitespace() throws Exception {
    assertEquals(null, StringUtils.trimTrailingWhitespace(null));
    assertEquals("", StringUtils.trimTrailingWhitespace(""));
    assertEquals("", StringUtils.trimTrailingWhitespace(" "));
    assertEquals("", StringUtils.trimTrailingWhitespace("\t"));
    assertEquals("a", StringUtils.trimTrailingWhitespace("a "));
    assertEquals(" a", StringUtils.trimTrailingWhitespace(" a"));
    assertEquals(" a", StringUtils.trimTrailingWhitespace(" a "));
    assertEquals(" a b", StringUtils.trimTrailingWhitespace(" a b "));
    assertEquals(" a b  c", StringUtils.trimTrailingWhitespace(" a b  c "));
  }

  @Test
  public void testTrimLeadingCharacter() throws Exception {
    assertEquals(null, StringUtils.trimLeadingCharacter(null, ' '));<commit_msg>增加StringUtils测试案例<commit_after>/*
 * Copyright 2002-2017 the original author or authors.
 *
 * Licensed 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.
 */
/*
 * iBankApp
 *
 * License : Apache License,Version 2.0, January 2004
 *
 * See the LICENSE file in English or LICENSE.zh_CN in chinese
 * in the root directory or <http://www.apache.org/licenses/>.
 */

package org.ibankapp.base.util.test;

import static org.junit.Assert.assertArrayEquals;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertSame;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;

import java.util.Arrays;
import java.util.Locale;
import java.util.Properties;
import org.ibankapp.base.util.StringUtils;
import org.junit.Assert;
import org.junit.Test;

/**
 * The tests of StringUtils.
 *
 * @author <NAME>
 * @author <NAME>
 * @author <NAME>
 */
public class StringUtilsTests {

  @Test
  public void testHasTextBlank() throws Exception {
    String blank = "          ";
    assertEquals(false, StringUtils.hasText(blank));
  }

  @Test
  public void testHasTextNullEmpty() throws Exception {
    assertEquals(false, StringUtils.hasText(null));
    assertEquals(false, StringUtils.hasText(""));
  }

  @Test
  public void testHasTextValid() throws Exception {
    assertEquals(true, StringUtils.hasText("t"));
  }

  @Test
  public void testContainsWhitespace() throws Exception {
    assertFalse(StringUtils.containsWhitespace(null));
    assertFalse(StringUtils.containsWhitespace(""));
    assertFalse(StringUtils.containsWhitespace("a"));
    assertFalse(StringUtils.containsWhitespace("abc"));
    assertTrue(StringUtils.containsWhitespace(" "));
    assertTrue(StringUtils.containsWhitespace(" a"));
    assertTrue(StringUtils.containsWhitespace("abc "));
    assertTrue(StringUtils.containsWhitespace("a b"));
    assertTrue(StringUtils.containsWhitespace("a  b"));
  }

  @Test
  public void testTrimWhitespace() throws Exception {
    assertEquals(null, StringUtils.trimWhitespace(null));
    assertEquals("", StringUtils.trimWhitespace(""));
    assertEquals("", StringUtils.trimWhitespace(" "));
    assertEquals("", StringUtils.trimWhitespace("\t"));
    assertEquals("a", StringUtils.trimWhitespace(" a"));
    assertEquals("a", StringUtils.trimWhitespace("a "));
    assertEquals("a", StringUtils.trimWhitespace(" a "));
    assertEquals("a b", StringUtils.trimWhitespace(" a b "));
    assertEquals("a b  c", StringUtils.trimWhitespace(" a b  c "));
  }

  @Test
  public void testTrimAllWhitespace() throws Exception {
    assertEquals("", StringUtils.trimAllWhitespace(""));
    assertEquals("", StringUtils.trimAllWhitespace(" "));
    assertEquals("", StringUtils.trimAllWhitespace("\t"));
    assertEquals("a", StringUtils.trimAllWhitespace(" a"));
    assertEquals("a", StringUtils.trimAllWhitespace("a "));
    assertEquals("a", StringUtils.trimAllWhitespace(" a "));
    assertEquals("ab", StringUtils.trimAllWhitespace(" a b "));
    assertEquals("abc", StringUtils.trimAllWhitespace(" a b  c "));
    assertEquals("abc",StringUtils.trimAllWhitespace(" a b \n c "));
  }

  @Test
  public void testTrimLeadingWhitespace() throws Exception {
    assertEquals(null, StringUtils.trimLeadingWhitespace(null));
    assertEquals("", StringUtils.trimLeadingWhitespace(""));
    assertEquals("", StringUtils.trimLeadingWhitespace(" "));
    assertEquals("", StringUtils.trimLeadingWhitespace("\t"));
    assertEquals("a", StringUtils.trimLeadingWhitespace(" a"));
    assertEquals("a ", StringUtils.trimLeadingWhitespace("a "));
    assertEquals("a ", StringUtils.trimLeadingWhitespace(" a "));
    assertEquals("a b ", StringUtils.trimLeadingWhitespace(" a b "));
    assertEquals("a b  c ", StringUtils.trimLeadingWhitespace(" a b  c "));
  }

  @Test
  public void testTrimTrailingWhitespace() throws Exception {
    assertEquals(null, StringUtils.trimTrailingWhitespace(null));
    assertEquals("", StringUtils.trimTrailingWhitespace(""));
    assertEquals("", StringUtils.trimTrailingWhitespace(" "));
    assertEquals("", StringUtils.trimTrailingWhitespace("\t"));
    assertEquals("a", StringUtils.trimTrailingWhitespace("a "));
    assertEquals(" a", StringUtils.trimTrailingWhitespace(" a"));
    assertEquals(" a", StringUtils.trimTrailingWhitespace(" a "));
    assertEquals(" a b", StringUtils.trimTrailingWhitespace(" a b "));
    assertEquals(" a b  c", StringUtils.trimTrailingWhitespace(" a b  c "));
  }

  @Test
  public void testTrimLeadingCharacter() throws Exception {
    assertEquals(null, StringUtils.trimLeadingCharacter(null, ' '));
{'fraction_non_alphanumeric': 0.13293631735664202, 'fraction_numerical': 0.0034578810873114973, 'mean_word_length': 4.96676217765043, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 4, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5833518', 'n_tokens_mistral': 2992, 'n_tokens_neox': 2953, 'n_words': 703}