Skip to content

Commit

Permalink
Reuse StringUtils.EMPTY in tests
Browse files Browse the repository at this point in the history
  • Loading branch information
garydgregory committed Mar 31, 2024
1 parent 19b6210 commit 52cdb17
Show file tree
Hide file tree
Showing 19 changed files with 65 additions and 46 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
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;

Expand Down Expand Up @@ -446,13 +447,13 @@ public void testToString() {

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);
}
Expand All @@ -462,13 +463,13 @@ public void testToStringDelimiter() {

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, ",", "[", "]");
Expand All @@ -483,38 +484,38 @@ public void testToStringDelimiter() {
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")
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@

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;

Expand Down Expand Up @@ -294,7 +295,7 @@ public void testLongestCommonSubsequenceWithString() {
"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";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
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;

/**
Expand Down Expand Up @@ -607,7 +608,7 @@ public void testGetString() {
if ("noKey".equals(key)) {
return "default";
}
return "";
return StringUtils.EMPTY;
}));
assertEquals("default", MapUtils.getString(null, "noKey", "default"));
}
Expand Down Expand Up @@ -990,7 +991,7 @@ public void testSafeAddToMap() {
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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import java.util.List;
import java.util.ListIterator;

import org.apache.commons.lang3.StringUtils;
import org.easymock.EasyMock;
import org.easymock.IExpectationSetters;

Expand Down Expand Up @@ -57,7 +58,7 @@ protected final void verify() {
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());
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
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;

/**
Expand Down Expand Up @@ -166,7 +167,7 @@ public void testInstantiateTransformerNull() {
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));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
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;

/**
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@

import org.apache.commons.collections4.AbstractObjectTest;
import org.apache.commons.lang3.ArrayUtils;
import org.apache.commons.lang3.StringUtils;
import org.junit.jupiter.api.Test;

/**
Expand Down Expand Up @@ -341,7 +342,7 @@ public E[] getFullElements() {
@SuppressWarnings("unchecked")
public E[] getFullNonNullElements() {
return (E[]) new Object[] {
"",
StringUtils.EMPTY,
"One",
Integer.valueOf(2),
"Three",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
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;
Expand Down Expand Up @@ -170,7 +171,7 @@ public void testEquals() {
assertEquals(mk1, mk1);
assertEquals(mk1, mk2);
assertNotEquals(mk1, mk3);
assertNotEquals("", mk1);
assertNotEquals(StringUtils.EMPTY, mk1);
assertNotEquals(null, mk1);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
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;

/**
Expand All @@ -59,7 +60,7 @@ public static class BulkTestSubList<E> extends AbstractListTest<E> {
private final AbstractListTest<E> outer;

public BulkTestSubList(final AbstractListTest<E> outer) {
super("");
super(StringUtils.EMPTY);
this.outer = outer;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
import java.util.TreeSet;

import org.apache.commons.collections4.set.UnmodifiableSet;
import org.apache.commons.lang3.StringUtils;
import org.junit.jupiter.api.Test;

/**
Expand Down Expand Up @@ -67,7 +68,7 @@ public String getCompatibilityVersion() {
public E[] getFullNonNullElements() {
// override to avoid duplicate "One"
return (E[]) new Object[] {
"",
StringUtils.EMPTY,
"One",
Integer.valueOf(2),
"Three",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
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;

Expand Down Expand Up @@ -330,7 +331,7 @@ public void verify() {
}
public class TestMapKeySet extends AbstractSetTest<K> {
public TestMapKeySet() {
super("");
super(StringUtils.EMPTY);
}

@Override
Expand Down Expand Up @@ -410,7 +411,7 @@ public void verify() {

public class TestMapValues extends AbstractCollectionTest<V> {
public TestMapValues() {
super("");
super(StringUtils.EMPTY);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import java.util.Map;
import java.util.Set;

import org.apache.commons.lang3.StringUtils;
import org.junit.jupiter.api.Test;

/**
Expand Down Expand Up @@ -82,7 +83,7 @@ public void testInitialCapacityZero() {
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" },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
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;

/**
Expand Down Expand Up @@ -482,19 +483,19 @@ public void testSetValueByIndex() {
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++) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
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;

Expand All @@ -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
Expand Down Expand Up @@ -177,7 +178,7 @@ public Map<K, Collection<V>> makeObject() {

public class TestMultiValuedMapEntries extends AbstractCollectionTest<Entry<K, V>> {
public TestMultiValuedMapEntries() {
super("");
super(StringUtils.EMPTY);
}

@SuppressWarnings("unchecked")
Expand Down Expand Up @@ -253,7 +254,7 @@ public void resetFull() {
public class TestMultiValuedMapKeys extends AbstractMultiSetTest<K> {

public TestMultiValuedMapKeys() {
super("");
super(StringUtils.EMPTY);
}

@Override
Expand Down Expand Up @@ -313,7 +314,7 @@ public void resetFull() {

public class TestMultiValuedMapKeySet extends AbstractSetTest<K> {
public TestMultiValuedMapKeySet() {
super("");
super(StringUtils.EMPTY);
}

@SuppressWarnings("unchecked")
Expand Down Expand Up @@ -360,7 +361,7 @@ public Set<K> makeObject() {

public class TestMultiValuedMapValues extends AbstractCollectionTest<V> {
public TestMultiValuedMapValues() {
super("");
super(StringUtils.EMPTY);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
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;

/**
Expand All @@ -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
Expand Down

0 comments on commit 52cdb17

Please sign in to comment.