001/*
002 * Licensed under the Apache License, Version 2.0 (the "License");
003 * you may not use this file except in compliance with the License.
004 * You may obtain a copy of the License at
005 *
006 *     http://www.apache.org/licenses/LICENSE-2.0
007 *
008 * Unless required by applicable law or agreed to in writing, software
009 * distributed under the License is distributed on an "AS IS" BASIS,
010 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
011 * See the License for the specific language governing permissions and
012 * limitations under the License.
013 */
014package org.gbif.dwc.record;
015
016import org.junit.jupiter.api.Test;
017
018import static org.junit.jupiter.api.Assertions.assertEquals;
019import static org.junit.jupiter.api.Assertions.assertNull;
020
021public class CleanUtilsTest {
022
023  @Test
024  public void testCleanFalse() {
025    for (String x : new String[]{"", " ", "  ", ".", "a ", " Me & Bobby McGee"}) {
026      assertEquals(x, CleanUtils.clean(x, false, false));
027    }
028  }
029
030  @Test
031  public void testClean() {
032    assertNull(CleanUtils.clean("", true, true));
033    assertNull(CleanUtils.clean(null, true, true));
034    assertNull(CleanUtils.clean(" ", true, true));
035    assertNull(CleanUtils.clean("\\N", true, true));
036    assertNull(CleanUtils.clean("NULL", true, true));
037
038    assertEquals(" Me & Bobby McGee", CleanUtils.clean(" Me & Bobby McGee", true, true));
039    assertEquals("Me & Bobby McGee", CleanUtils.clean("Me & Bobby McGee", true, true));
040    assertEquals("Me & Bobby McGee", CleanUtils.clean("Me & Bobby McGee", true, true));
041    assertEquals("Me & Bobby McGee", CleanUtils.clean("Me & Bobby McGee", true, true));
042    assertEquals("Me & Bobby McGee", CleanUtils.clean("Me & Bobby McGee", true, true));
043
044    assertEquals("Me &amp", CleanUtils.clean("Me &amp", true, true));
045    assertEquals("Me &amp ;", CleanUtils.clean("Me &amp ;", true, true));
046    assertEquals("Me & amp;", CleanUtils.clean("Me & amp;", true, true));
047  }
048}