Reuse StringUtils.EMPTY in tests

This commit is contained in:
Gary Gregory 2024-03-31 09:52:46 -04:00
parent 19b621029e
commit 52cdb17e69
19 changed files with 65 additions and 46 deletions

View File

@ -37,6 +37,7 @@ import java.util.List;
import java.util.Set;
import org.apache.commons.collections4.bag.HashBag;
import org.apache.commons.lang3.StringUtils;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
@ -446,13 +447,13 @@ public class IterableUtilsTest {
result = IterableUtils.toString(new ArrayList<>(), input -> {
fail("not supposed to reach here");
return "";
return StringUtils.EMPTY;
});
assertEquals("[]", result);
result = IterableUtils.toString(null, input -> {
fail("not supposed to reach here");
return "";
return StringUtils.EMPTY;
});
assertEquals("[]", result);
}
@ -462,13 +463,13 @@ public class IterableUtilsTest {
final Transformer<Integer, String> transformer = input -> Integer.toString(input * 2);
String result = IterableUtils.toString(iterableA, transformer, "", "", "");
String result = IterableUtils.toString(iterableA, transformer, StringUtils.EMPTY, StringUtils.EMPTY, StringUtils.EMPTY);
assertEquals("2446668888", result);
result = IterableUtils.toString(iterableA, transformer, ",", "", "");
result = IterableUtils.toString(iterableA, transformer, ",", StringUtils.EMPTY, StringUtils.EMPTY);
assertEquals("2,4,4,6,6,6,8,8,8,8", result);
result = IterableUtils.toString(iterableA, transformer, "", "[", "]");
result = IterableUtils.toString(iterableA, transformer, StringUtils.EMPTY, "[", "]");
assertEquals("[2446668888]", result);
result = IterableUtils.toString(iterableA, transformer, ",", "[", "]");
@ -483,38 +484,38 @@ public class IterableUtilsTest {
result = IterableUtils.toString(iterableA, transformer, ",,", "((", "))");
assertEquals("((2,,4,,4,,6,,6,,6,,8,,8,,8,,8))", result);
result = IterableUtils.toString(new ArrayList<>(), transformer, "", "(", ")");
result = IterableUtils.toString(new ArrayList<>(), transformer, StringUtils.EMPTY, "(", ")");
assertEquals("()", result);
result = IterableUtils.toString(new ArrayList<>(), transformer, "", "", "");
assertEquals("", result);
result = IterableUtils.toString(new ArrayList<>(), transformer, StringUtils.EMPTY, StringUtils.EMPTY, StringUtils.EMPTY);
assertEquals(StringUtils.EMPTY, result);
}
@Test
public void testToStringWithNullArguments() {
final String result = IterableUtils.toString(null, input -> {
fail("not supposed to reach here");
return "";
}, "", "(", ")");
return StringUtils.EMPTY;
}, StringUtils.EMPTY, "(", ")");
assertEquals("()", result);
assertAll(
() -> assertThrows(NullPointerException.class, () -> IterableUtils.toString(new ArrayList<>(), null, "", "(", ")"),
() -> assertThrows(NullPointerException.class, () -> IterableUtils.toString(new ArrayList<>(), null, StringUtils.EMPTY, "(", ")"),
"expecting NullPointerException"),
() -> assertThrows(NullPointerException.class, () ->
IterableUtils.toString(new ArrayList<>(), input -> {
fail("not supposed to reach here");
return "";
return StringUtils.EMPTY;
}, null, "(", ")"),
"expecting NullPointerException"),
() -> assertThrows(NullPointerException.class, () -> IterableUtils.toString(new ArrayList<>(), input -> {
fail("not supposed to reach here");
return "";
}, "", null, ")"),
return StringUtils.EMPTY;
}, StringUtils.EMPTY, null, ")"),
"expecting NullPointerException"),
() -> assertThrows(NullPointerException.class, () -> IterableUtils.toString(new ArrayList<>(), input -> {
fail("not supposed to reach here");
return "";
}, "", "(", null),
return StringUtils.EMPTY;
}, StringUtils.EMPTY, "(", null),
"expecting NullPointerException")
);
}

View File

@ -34,6 +34,7 @@ import java.util.List;
import org.apache.commons.collections4.functors.EqualPredicate;
import org.apache.commons.collections4.list.PredicatedList;
import org.apache.commons.lang3.StringUtils;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
@ -294,7 +295,7 @@ public class ListUtilsTest {
"failed to check for null argument")
);
String lcs = ListUtils.longestCommonSubsequence("", "");
String lcs = ListUtils.longestCommonSubsequence(StringUtils.EMPTY, StringUtils.EMPTY);
assertEquals(0, lcs.length());
final String banana = "BANANA";

View File

@ -50,6 +50,7 @@ import org.apache.commons.collections4.map.HashedMap;
import org.apache.commons.collections4.map.LazyMap;
import org.apache.commons.collections4.map.MultiValueMap;
import org.apache.commons.collections4.map.PredicatedMap;
import org.apache.commons.lang3.StringUtils;
import org.junit.jupiter.api.Test;
/**
@ -607,7 +608,7 @@ public class MapUtilsTest {
if ("noKey".equals(key)) {
return "default";
}
return "";
return StringUtils.EMPTY;
}));
assertEquals("default", MapUtils.getString(null, "noKey", "default"));
}
@ -990,7 +991,7 @@ public class MapUtilsTest {
MapUtils.safeAddToMap(inMap, "key1", "value1");
MapUtils.safeAddToMap(inMap, "key2", null);
assertEquals("value1", inMap.get("key1"));
assertEquals("", inMap.get("key2"));
assertEquals(StringUtils.EMPTY, inMap.get("key2"));
}
@Test

View File

@ -20,6 +20,7 @@ import java.util.ArrayList;
import java.util.List;
import java.util.ListIterator;
import org.apache.commons.lang3.StringUtils;
import org.easymock.EasyMock;
import org.easymock.IExpectationSetters;
@ -57,7 +58,7 @@ public abstract class MockTestCase {
try {
EasyMock.verify(i.next());
} catch (final AssertionError e) {
throw new AssertionError(i.previousIndex() + 1 + ""
throw new AssertionError(i.previousIndex() + 1 + StringUtils.EMPTY
+ e.getMessage());
}
}

View File

@ -38,6 +38,7 @@ import org.apache.commons.collections4.functors.FalsePredicate;
import org.apache.commons.collections4.functors.NOPTransformer;
import org.apache.commons.collections4.functors.StringValueTransformer;
import org.apache.commons.collections4.functors.TruePredicate;
import org.apache.commons.lang3.StringUtils;
import org.junit.jupiter.api.Test;
/**
@ -166,7 +167,7 @@ public class TransformerUtilsTest {
assertThrows(FunctorException.class, () -> finalTrans.transform(String.class));
trans = TransformerUtils.instantiateTransformer();
assertEquals("", trans.transform(String.class));
assertEquals(StringUtils.EMPTY, trans.transform(String.class));
trans = TransformerUtils.instantiateTransformer(new Class[] { Long.TYPE }, new Object[] {1000L});
assertEquals(new Date(1000L), trans.transform(Date.class));

View File

@ -39,6 +39,7 @@ import org.apache.commons.collections4.BulkTest;
import org.apache.commons.collections4.collection.AbstractCollectionTest;
import org.apache.commons.collections4.set.AbstractSetTest;
import org.apache.commons.lang3.ArrayUtils;
import org.apache.commons.lang3.StringUtils;
import org.junit.jupiter.api.Test;
/**
@ -71,7 +72,7 @@ public abstract class AbstractBagTest<T> extends AbstractCollectionTest<T> {
public class TestBagUniqueSet extends AbstractSetTest<T> {
public TestBagUniqueSet() {
super("");
super(StringUtils.EMPTY);
}
@Override

View File

@ -46,6 +46,7 @@ import java.util.function.Predicate;
import org.apache.commons.collections4.AbstractObjectTest;
import org.apache.commons.lang3.ArrayUtils;
import org.apache.commons.lang3.StringUtils;
import org.junit.jupiter.api.Test;
/**
@ -341,7 +342,7 @@ public abstract class AbstractCollectionTest<E> extends AbstractObjectTest {
@SuppressWarnings("unchecked")
public E[] getFullNonNullElements() {
return (E[]) new Object[] {
"",
StringUtils.EMPTY,
"One",
Integer.valueOf(2),
"Three",

View File

@ -37,6 +37,7 @@ import java.util.Collection;
import java.util.HashMap;
import java.util.Map;
import org.apache.commons.lang3.StringUtils;
import org.junit.jupiter.api.DynamicTest;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.TestFactory;
@ -170,7 +171,7 @@ public class MultiKeyTest {
assertEquals(mk1, mk1);
assertEquals(mk1, mk2);
assertNotEquals(mk1, mk3);
assertNotEquals("", mk1);
assertNotEquals(StringUtils.EMPTY, mk1);
assertNotEquals(null, mk1);
}

View File

@ -39,6 +39,7 @@ import java.util.NoSuchElementException;
import org.apache.commons.collections4.BulkTest;
import org.apache.commons.collections4.collection.AbstractCollectionTest;
import org.apache.commons.collections4.iterators.AbstractListIteratorTest;
import org.apache.commons.lang3.StringUtils;
import org.junit.jupiter.api.Test;
/**
@ -59,7 +60,7 @@ public abstract class AbstractListTest<E> extends AbstractCollectionTest<E> {
private final AbstractListTest<E> outer;
public BulkTestSubList(final AbstractListTest<E> outer) {
super("");
super(StringUtils.EMPTY);
this.outer = outer;
}

View File

@ -33,6 +33,7 @@ import java.util.Set;
import java.util.TreeSet;
import org.apache.commons.collections4.set.UnmodifiableSet;
import org.apache.commons.lang3.StringUtils;
import org.junit.jupiter.api.Test;
/**
@ -67,7 +68,7 @@ public class SetUniqueListTest<E> extends AbstractListTest<E> {
public E[] getFullNonNullElements() {
// override to avoid duplicate "One"
return (E[]) new Object[] {
"",
StringUtils.EMPTY,
"One",
Integer.valueOf(2),
"Three",

View File

@ -44,6 +44,7 @@ import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.collections4.collection.AbstractCollectionTest;
import org.apache.commons.collections4.keyvalue.DefaultMapEntry;
import org.apache.commons.collections4.set.AbstractSetTest;
import org.apache.commons.lang3.StringUtils;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.Test;
@ -330,7 +331,7 @@ public abstract class AbstractMapTest<K, V> extends AbstractObjectTest {
}
public class TestMapKeySet extends AbstractSetTest<K> {
public TestMapKeySet() {
super("");
super(StringUtils.EMPTY);
}
@Override
@ -410,7 +411,7 @@ public abstract class AbstractMapTest<K, V> extends AbstractObjectTest {
public class TestMapValues extends AbstractCollectionTest<V> {
public TestMapValues() {
super("");
super(StringUtils.EMPTY);
}
@Override

View File

@ -25,6 +25,7 @@ import java.util.Locale;
import java.util.Map;
import java.util.Set;
import org.apache.commons.lang3.StringUtils;
import org.junit.jupiter.api.Test;
/**
@ -82,7 +83,7 @@ public class CaseInsensitiveMapTest<K, V> extends AbstractIterableMapTest<K, V>
public void testLocaleIndependence() {
final Locale orig = Locale.getDefault();
final Locale[] locales = { Locale.ENGLISH, new Locale("tr", "", ""), Locale.getDefault() };
final Locale[] locales = { Locale.ENGLISH, new Locale("tr", StringUtils.EMPTY, StringUtils.EMPTY), Locale.getDefault() };
final String[][] data = {
{ "i", "I" },

View File

@ -31,6 +31,7 @@ import java.util.TreeMap;
import org.apache.commons.collections4.BulkTest;
import org.apache.commons.collections4.MapIterator;
import org.apache.commons.collections4.list.AbstractListTest;
import org.apache.commons.lang3.StringUtils;
import org.junit.jupiter.api.Test;
/**
@ -482,19 +483,19 @@ public class ListOrderedMapTest<K, V> extends AbstractOrderedMapTest<K, V> {
resetEmpty();
ListOrderedMap<K, V> lom = getMap();
try {
lom.setValue(0, (V) "");
lom.setValue(0, (V) StringUtils.EMPTY);
} catch (final IndexOutOfBoundsException ex) {}
try {
lom.setValue(-1, (V) "");
lom.setValue(-1, (V) StringUtils.EMPTY);
} catch (final IndexOutOfBoundsException ex) {}
resetFull();
lom = getMap();
try {
lom.setValue(-1, (V) "");
lom.setValue(-1, (V) StringUtils.EMPTY);
} catch (final IndexOutOfBoundsException ex) {}
try {
lom.setValue(lom.size(), (V) "");
lom.setValue(lom.size(), (V) StringUtils.EMPTY);
} catch (final IndexOutOfBoundsException ex) {}
for (int i = 0; i < lom.size(); i++) {

View File

@ -48,6 +48,7 @@ import org.apache.commons.collections4.collection.AbstractCollectionTest;
import org.apache.commons.collections4.map.AbstractMapTest;
import org.apache.commons.collections4.multiset.AbstractMultiSetTest;
import org.apache.commons.collections4.set.AbstractSetTest;
import org.apache.commons.lang3.StringUtils;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;
@ -63,7 +64,7 @@ public abstract class AbstractMultiValuedMapTest<K, V> extends AbstractObjectTes
public class TestMultiValuedMapAsMap extends AbstractMapTest<K, Collection<V>> {
public TestMultiValuedMapAsMap() {
super("");
super(StringUtils.EMPTY);
}
@Override
@ -177,7 +178,7 @@ public abstract class AbstractMultiValuedMapTest<K, V> extends AbstractObjectTes
public class TestMultiValuedMapEntries extends AbstractCollectionTest<Entry<K, V>> {
public TestMultiValuedMapEntries() {
super("");
super(StringUtils.EMPTY);
}
@SuppressWarnings("unchecked")
@ -253,7 +254,7 @@ public abstract class AbstractMultiValuedMapTest<K, V> extends AbstractObjectTes
public class TestMultiValuedMapKeys extends AbstractMultiSetTest<K> {
public TestMultiValuedMapKeys() {
super("");
super(StringUtils.EMPTY);
}
@Override
@ -313,7 +314,7 @@ public abstract class AbstractMultiValuedMapTest<K, V> extends AbstractObjectTes
public class TestMultiValuedMapKeySet extends AbstractSetTest<K> {
public TestMultiValuedMapKeySet() {
super("");
super(StringUtils.EMPTY);
}
@SuppressWarnings("unchecked")
@ -360,7 +361,7 @@ public abstract class AbstractMultiValuedMapTest<K, V> extends AbstractObjectTes
public class TestMultiValuedMapValues extends AbstractCollectionTest<V> {
public TestMultiValuedMapValues() {
super("");
super(StringUtils.EMPTY);
}
@Override

View File

@ -38,6 +38,7 @@ import org.apache.commons.collections4.MultiSet;
import org.apache.commons.collections4.collection.AbstractCollectionTest;
import org.apache.commons.collections4.set.AbstractSetTest;
import org.apache.commons.lang3.ArrayUtils;
import org.apache.commons.lang3.StringUtils;
import org.junit.jupiter.api.Test;
/**
@ -64,7 +65,7 @@ public abstract class AbstractMultiSetTest<T> extends AbstractCollectionTest<T>
public class TestMultiSetUniqueSet extends AbstractSetTest<T> {
public TestMultiSetUniqueSet() {
super("");
super(StringUtils.EMPTY);
}
@Override

View File

@ -38,6 +38,7 @@ import java.util.Properties;
import org.apache.commons.io.input.NullReader;
import org.apache.commons.lang3.ArrayUtils;
import org.apache.commons.lang3.StringUtils;
import org.junit.jupiter.api.Test;
public class EmptyPropertiesTest {
@ -62,7 +63,7 @@ public class EmptyPropertiesTest {
private String removeLine2(final String x) {
final String[] s = x.split("\\R", 2);
return s[0] + System.lineSeparator() + (s.length > 2 ? s[2] : "");
return s[0] + System.lineSeparator() + (s.length > 2 ? s[2] : StringUtils.EMPTY);
}
@Test

View File

@ -24,6 +24,7 @@ import java.util.Arrays;
import java.util.List;
import java.util.Random;
import org.apache.commons.lang3.StringUtils;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
@ -83,7 +84,7 @@ public class SequencesComparatorTest {
before = Arrays.asList(
"bottle",
"nematode knowledge",
"",
StringUtils.EMPTY,
"aa",
"prefixed string",
"ABCABBA",
@ -94,7 +95,7 @@ public class SequencesComparatorTest {
after = Arrays.asList(
"noodle",
"empty bottle",
"",
StringUtils.EMPTY,
"C",
"prefix",
"CBABAC",

View File

@ -31,6 +31,7 @@ import org.apache.commons.collections4.BulkTest;
import org.apache.commons.collections4.MapIterator;
import org.apache.commons.collections4.Transformer;
import org.apache.commons.collections4.functors.NOPTransformer;
import org.apache.commons.lang3.StringUtils;
import org.junit.jupiter.api.Test;
/**
@ -110,7 +111,7 @@ public class TransformedSplitMapTest extends BulkTest {
new HashMap<>(), intToString, objectToClass);
final Integer[] k = { 0, 1, 2, 3, 4, 5, 6 };
final Object[] v = { "", new Object(), new HashMap<>(), 0, BigInteger.TEN, null,
final Object[] v = { StringUtils.EMPTY, new Object(), new HashMap<>(), 0, BigInteger.TEN, null,
new Object[0] };
assertEquals(0, map.size());

View File

@ -36,6 +36,7 @@ import java.util.SortedMap;
import org.apache.commons.collections4.Trie;
import org.apache.commons.collections4.map.AbstractSortedMapTest;
import org.apache.commons.lang3.StringUtils;
import org.junit.jupiter.api.Test;
/**
@ -67,7 +68,7 @@ public class PatriciaTrieTest<V> extends AbstractSortedMapTest<String, V> {
final PatriciaTrie<String> trie = new PatriciaTrie<>();
final String[] keys = {
"",
StringUtils.EMPTY,
"Albert", "Xavier", "XyZ", "Anna", "Alien", "Alberto",
"Alberts", "Allie", "Alliese", "Alabama", "Banane",
"Blabla", "Amber", "Ammun", "Akka", "Akko", "Albertoo",
@ -272,7 +273,7 @@ public class PatriciaTrieTest<V> extends AbstractSortedMapTest<String, V> {
iterator = map.values().iterator();
assertFalse(iterator.hasNext());
map = trie.prefixMap("");
map = trie.prefixMap(StringUtils.EMPTY);
assertSame(trie, map); // stricter than necessary, but a good check
map = trie.prefixMap("\0");
@ -423,7 +424,7 @@ public class PatriciaTrieTest<V> extends AbstractSortedMapTest<String, V> {
final char char_b = 'b'; // 1100010
final PatriciaTrie<String> trie = new PatriciaTrie<>();
final String prefixString = "" + char_b;
final String prefixString = StringUtils.EMPTY + char_b;
final String longerString = prefixString + u8000;
assertEquals(1, prefixString.length());