Added containsNull, containsEmpty, ContainsBlank methods. Added tests.
This commit is contained in:
parent
bd66e9c732
commit
3740f95409
3 changed files with 1167 additions and 842 deletions
File diff suppressed because it is too large
Load diff
|
@ -16,7 +16,7 @@
|
|||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with Devinsy-utils. If not, see <http://www.gnu.org/licenses/>
|
||||
*/
|
||||
package fr.devinsy.util;
|
||||
package fr.devinsy.util.strings;
|
||||
|
||||
import java.util.Iterator;
|
||||
|
174
test/fr/devinsy/util/strings/StringListUtilsTest.java
Normal file
174
test/fr/devinsy/util/strings/StringListUtilsTest.java
Normal file
|
@ -0,0 +1,174 @@
|
|||
/**
|
||||
* Copyright (C) 2013,2014 Christian Pierre MOMON
|
||||
*
|
||||
* This file is part of Devinsy-utils.
|
||||
*
|
||||
* Devinsy-utils is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Devinsy-utils is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with Devinsy-utils. If not, see <http://www.gnu.org/licenses/>
|
||||
*/
|
||||
package fr.devinsy.util.strings;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
|
||||
import org.apache.log4j.BasicConfigurator;
|
||||
import org.apache.log4j.Level;
|
||||
import org.apache.log4j.Logger;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Christian P. Momon
|
||||
*/
|
||||
public class StringListUtilsTest
|
||||
{
|
||||
private static org.apache.log4j.Logger logger = org.apache.log4j.Logger.getLogger(StringListUtilsTest.class);
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
@Before
|
||||
public void before()
|
||||
{
|
||||
BasicConfigurator.configure();
|
||||
Logger.getRootLogger().setLevel(Level.ERROR);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
@Test
|
||||
public void testContainsBlank01()
|
||||
{
|
||||
Assert.assertFalse(StringListUtils.containsBlank((Collection<String>) null));
|
||||
Assert.assertFalse(StringListUtils.containsBlank(new StringList("aaa", "bbb", "ccc")));
|
||||
Assert.assertTrue(StringListUtils.containsBlank(new StringList("aaa", null, "ccc")));
|
||||
Assert.assertTrue(StringListUtils.containsBlank(new StringList("aaa", "", "ccc")));
|
||||
Assert.assertTrue(StringListUtils.containsBlank(new StringList("aaa", " ", "ccc")));
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
@Test
|
||||
public void testContainsBlank02()
|
||||
{
|
||||
Assert.assertFalse(StringListUtils.containsBlank((String[]) null));
|
||||
Assert.assertFalse(StringListUtils.containsBlank("aaa", "bbb", "ccc"));
|
||||
Assert.assertTrue(StringListUtils.containsBlank("aaa", null, "ccc"));
|
||||
Assert.assertTrue(StringListUtils.containsBlank("aaa", "", "ccc"));
|
||||
Assert.assertTrue(StringListUtils.containsBlank("aaa", " ", "ccc"));
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
@Test
|
||||
public void testContainsBlank03()
|
||||
{
|
||||
Assert.assertFalse(StringListUtils.containsBlank((ArrayList<String>) null));
|
||||
ArrayList<String> source = new ArrayList<String>();
|
||||
source.add("aaa");
|
||||
source.add("bbb");
|
||||
source.add("ccc");
|
||||
Assert.assertFalse(StringListUtils.containsBlank(source));
|
||||
source.set(1, null);
|
||||
Assert.assertTrue(StringListUtils.containsBlank(source));
|
||||
source.set(1, "");
|
||||
Assert.assertTrue(StringListUtils.containsBlank(source));
|
||||
source.set(1, " ");
|
||||
Assert.assertTrue(StringListUtils.containsBlank(source));
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
@Test
|
||||
public void testContainsEmpty01()
|
||||
{
|
||||
Assert.assertFalse(StringListUtils.containsEmpty((Collection<String>) null));
|
||||
Assert.assertFalse(StringListUtils.containsEmpty(new StringList("aaa", "bbb", "ccc")));
|
||||
Assert.assertTrue(StringListUtils.containsEmpty(new StringList("aaa", null, "ccc")));
|
||||
Assert.assertTrue(StringListUtils.containsEmpty(new StringList("aaa", "", "ccc")));
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
@Test
|
||||
public void testContainsEmpty02()
|
||||
{
|
||||
Assert.assertFalse(StringListUtils.containsEmpty((String[]) null));
|
||||
Assert.assertFalse(StringListUtils.containsEmpty("aaa", "bbb", "ccc"));
|
||||
Assert.assertTrue(StringListUtils.containsEmpty("aaa", null, "ccc"));
|
||||
Assert.assertTrue(StringListUtils.containsEmpty("aaa", "", "ccc"));
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
@Test
|
||||
public void testContainsEmpty03()
|
||||
{
|
||||
Assert.assertFalse(StringListUtils.containsEmpty((ArrayList<String>) null));
|
||||
ArrayList<String> source = new ArrayList<String>();
|
||||
source.add("aaa");
|
||||
source.add("bbb");
|
||||
source.add("ccc");
|
||||
Assert.assertFalse(StringListUtils.containsEmpty(source));
|
||||
source.set(1, null);
|
||||
Assert.assertTrue(StringListUtils.containsEmpty(source));
|
||||
source.set(1, "");
|
||||
Assert.assertTrue(StringListUtils.containsEmpty(source));
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
@Test
|
||||
public void testContainsNull01()
|
||||
{
|
||||
Assert.assertFalse(StringListUtils.containsNull((Collection<String>) null));
|
||||
Assert.assertFalse(StringListUtils.containsNull(new StringList("aaa", "bbb", "ccc")));
|
||||
Assert.assertTrue(StringListUtils.containsNull(new StringList("aaa", null, "ccc")));
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
@Test
|
||||
public void testContainsNull02()
|
||||
{
|
||||
Assert.assertFalse(StringListUtils.containsNull((String[]) null));
|
||||
Assert.assertFalse(StringListUtils.containsNull("aaa", "bbb", "ccc"));
|
||||
Assert.assertTrue(StringListUtils.containsNull("aaa", null, "ccc"));
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
@Test
|
||||
public void testContainsNull03()
|
||||
{
|
||||
Assert.assertFalse(StringListUtils.containsNull((ArrayList<String>) null));
|
||||
ArrayList<String> source = new ArrayList<String>();
|
||||
source.add("aaa");
|
||||
source.add("bbb");
|
||||
source.add("ccc");
|
||||
Assert.assertFalse(StringListUtils.containsNull(source));
|
||||
source.set(1, null);
|
||||
Assert.assertTrue(StringListUtils.containsNull(source));
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue