[LANG-1600] Restore handling of collections for non-JSON ToStringStyle (#610)
* [LANG-1600] add test cases for non-empty collections, maps, and arrays * break out those test cases into separate methods for legibility * addresses issue introduced in LANG-1542 with commit1dddec8
* [LANG-1600] restore non-json-style handling of appendDetail() for Collection * addresses issue introduced in LANG-1542 with commit1dddec8
This commit is contained in:
parent
47f96a3c95
commit
772f97c437
|
@ -626,16 +626,6 @@ public abstract class ToStringStyle implements Serializable {
|
|||
* {@code toString}, not {@code null}
|
||||
*/
|
||||
protected void appendDetail(final StringBuffer buffer, final String fieldName, final Collection<?> coll) {
|
||||
if (coll != null && !coll.isEmpty()) {
|
||||
buffer.append(arrayStart);
|
||||
int i = 0;
|
||||
for (final Object item : coll) {
|
||||
appendDetail(buffer, fieldName, i++, item);
|
||||
}
|
||||
buffer.append(arrayEnd);
|
||||
return;
|
||||
}
|
||||
|
||||
buffer.append(coll);
|
||||
}
|
||||
|
||||
|
@ -2597,6 +2587,21 @@ public abstract class ToStringStyle implements Serializable {
|
|||
appendDetail(buffer, fieldName, valueAsString);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void appendDetail(final StringBuffer buffer, final String fieldName, final Collection<?> coll) {
|
||||
if (coll != null && !coll.isEmpty()) {
|
||||
buffer.append(getArrayStart());
|
||||
int i = 0;
|
||||
for (final Object item : coll) {
|
||||
appendDetail(buffer, fieldName, i++, item);
|
||||
}
|
||||
buffer.append(getArrayEnd());
|
||||
return;
|
||||
}
|
||||
|
||||
buffer.append(coll);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void appendDetail(final StringBuffer buffer, final String fieldName, final Map<?, ?> map) {
|
||||
if (map != null && !map.isEmpty()) {
|
||||
|
|
|
@ -18,8 +18,8 @@ package org.apache.commons.lang3.builder;
|
|||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
|
||||
import org.apache.commons.lang3.builder.ToStringStyleTest.Person;
|
||||
import org.junit.jupiter.api.AfterEach;
|
||||
|
@ -71,12 +71,38 @@ public class DefaultToStringStyleTest {
|
|||
assertEquals(baseStr + "[a=3]", new ToStringBuilder(base).append("a", i3).toString());
|
||||
assertEquals(baseStr + "[a=3,b=4]", new ToStringBuilder(base).append("a", i3).append("b", i4).toString());
|
||||
assertEquals(baseStr + "[a=<Integer>]", new ToStringBuilder(base).append("a", i3, false).toString());
|
||||
assertEquals(baseStr + "[a=<size=0>]", new ToStringBuilder(base).append("a", new ArrayList<>(), false).toString());
|
||||
assertEquals(baseStr + "[a=[]]", new ToStringBuilder(base).append("a", new ArrayList<>(), true).toString());
|
||||
assertEquals(baseStr + "[a=<size=0>]", new ToStringBuilder(base).append("a", new HashMap<>(), false).toString());
|
||||
assertEquals(baseStr + "[a={}]", new ToStringBuilder(base).append("a", new HashMap<>(), true).toString());
|
||||
assertEquals(baseStr + "[a=<size=0>]", new ToStringBuilder(base).append("a", (Object) new String[0], false).toString());
|
||||
assertEquals(baseStr + "[a={}]", new ToStringBuilder(base).append("a", (Object) new String[0], true).toString());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCollection() {
|
||||
final Integer i3 = Integer.valueOf(3);
|
||||
final Integer i4 = Integer.valueOf(4);
|
||||
assertEquals(baseStr + "[a=<size=0>]", new ToStringBuilder(base).append("a", Collections.emptyList(), false).toString());
|
||||
assertEquals(baseStr + "[a=[]]", new ToStringBuilder(base).append("a", Collections.emptyList(), true).toString());
|
||||
assertEquals(baseStr + "[a=<size=1>]", new ToStringBuilder(base).append("a", Collections.singletonList(i3), false).toString());
|
||||
assertEquals(baseStr + "[a=[3]]", new ToStringBuilder(base).append("a", Collections.singletonList(i3), true).toString());
|
||||
assertEquals(baseStr + "[a=<size=2>]", new ToStringBuilder(base).append("a", Arrays.asList(i3, i4), false).toString());
|
||||
assertEquals(baseStr + "[a=[3, 4]]", new ToStringBuilder(base).append("a", Arrays.asList(i3, i4), true).toString());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMap() {
|
||||
assertEquals(baseStr + "[a=<size=0>]", new ToStringBuilder(base).append("a", Collections.emptyMap(), false).toString());
|
||||
assertEquals(baseStr + "[a={}]", new ToStringBuilder(base).append("a", Collections.emptyMap(), true).toString());
|
||||
assertEquals(baseStr + "[a=<size=1>]", new ToStringBuilder(base).append("a", Collections.singletonMap("k", "v"), false).toString());
|
||||
assertEquals(baseStr + "[a={k=v}]", new ToStringBuilder(base).append("a", Collections.singletonMap("k", "v"), true).toString());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testArray() {
|
||||
final Integer i3 = Integer.valueOf(3);
|
||||
final Integer i4 = Integer.valueOf(4);
|
||||
assertEquals(baseStr + "[a=<size=0>]", new ToStringBuilder(base).append("a", (Object) new Integer[0], false).toString());
|
||||
assertEquals(baseStr + "[a={}]", new ToStringBuilder(base).append("a", (Object) new Integer[0], true).toString());
|
||||
assertEquals(baseStr + "[a=<size=1>]", new ToStringBuilder(base).append("a", (Object) new Integer[] {i3}, false).toString());
|
||||
assertEquals(baseStr + "[a={3}]", new ToStringBuilder(base).append("a", (Object) new Integer[] {i3}, true).toString());
|
||||
assertEquals(baseStr + "[a=<size=2>]", new ToStringBuilder(base).append("a", (Object) new Integer[] {i3, i4}, false).toString());
|
||||
assertEquals(baseStr + "[a={3,4}]", new ToStringBuilder(base).append("a", (Object) new Integer[] {i3, i4}, true).toString());
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
|
@ -18,8 +18,8 @@ package org.apache.commons.lang3.builder;
|
|||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
|
||||
import org.apache.commons.lang3.builder.ToStringStyleTest.Person;
|
||||
import org.junit.jupiter.api.AfterEach;
|
||||
|
@ -71,12 +71,38 @@ public class MultiLineToStringStyleTest {
|
|||
assertEquals(baseStr + "[" + System.lineSeparator() + " a=3" + System.lineSeparator() + "]", new ToStringBuilder(base).append("a", i3).toString());
|
||||
assertEquals(baseStr + "[" + System.lineSeparator() + " a=3" + System.lineSeparator() + " b=4" + System.lineSeparator() + "]", new ToStringBuilder(base).append("a", i3).append("b", i4).toString());
|
||||
assertEquals(baseStr + "[" + System.lineSeparator() + " a=<Integer>" + System.lineSeparator() + "]", new ToStringBuilder(base).append("a", i3, false).toString());
|
||||
assertEquals(baseStr + "[" + System.lineSeparator() + " a=<size=0>" + System.lineSeparator() + "]", new ToStringBuilder(base).append("a", new ArrayList<>(), false).toString());
|
||||
assertEquals(baseStr + "[" + System.lineSeparator() + " a=[]" + System.lineSeparator() + "]", new ToStringBuilder(base).append("a", new ArrayList<>(), true).toString());
|
||||
assertEquals(baseStr + "[" + System.lineSeparator() + " a=<size=0>" + System.lineSeparator() + "]", new ToStringBuilder(base).append("a", new HashMap<>(), false).toString());
|
||||
assertEquals(baseStr + "[" + System.lineSeparator() + " a={}" + System.lineSeparator() + "]", new ToStringBuilder(base).append("a", new HashMap<>(), true).toString());
|
||||
assertEquals(baseStr + "[" + System.lineSeparator() + " a=<size=0>" + System.lineSeparator() + "]", new ToStringBuilder(base).append("a", (Object) new String[0], false).toString());
|
||||
assertEquals(baseStr + "[" + System.lineSeparator() + " a={}" + System.lineSeparator() + "]", new ToStringBuilder(base).append("a", (Object) new String[0], true).toString());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCollection() {
|
||||
final Integer i3 = Integer.valueOf(3);
|
||||
final Integer i4 = Integer.valueOf(4);
|
||||
assertEquals(baseStr + "[" + System.lineSeparator() + " a=<size=0>" + System.lineSeparator() + "]", new ToStringBuilder(base).append("a", Collections.emptyList(), false).toString());
|
||||
assertEquals(baseStr + "[" + System.lineSeparator() + " a=[]" + System.lineSeparator() + "]", new ToStringBuilder(base).append("a", Collections.emptyList(), true).toString());
|
||||
assertEquals(baseStr + "[" + System.lineSeparator() + " a=<size=1>" + System.lineSeparator() + "]", new ToStringBuilder(base).append("a", Collections.singletonList(i3), false).toString());
|
||||
assertEquals(baseStr + "[" + System.lineSeparator() + " a=[3]" + System.lineSeparator() + "]", new ToStringBuilder(base).append("a", Collections.singletonList(i3), true).toString());
|
||||
assertEquals(baseStr + "[" + System.lineSeparator() + " a=<size=2>" + System.lineSeparator() + "]", new ToStringBuilder(base).append("a", Arrays.asList(i3, i4), false).toString());
|
||||
assertEquals(baseStr + "[" + System.lineSeparator() + " a=[3, 4]" + System.lineSeparator() + "]", new ToStringBuilder(base).append("a", Arrays.asList(i3, i4), true).toString());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMap() {
|
||||
assertEquals(baseStr + "[" + System.lineSeparator() + " a=<size=0>" + System.lineSeparator() + "]", new ToStringBuilder(base).append("a", Collections.emptyMap(), false).toString());
|
||||
assertEquals(baseStr + "[" + System.lineSeparator() + " a={}" + System.lineSeparator() + "]", new ToStringBuilder(base).append("a", Collections.emptyMap(), true).toString());
|
||||
assertEquals(baseStr + "[" + System.lineSeparator() + " a=<size=1>" + System.lineSeparator() + "]", new ToStringBuilder(base).append("a", Collections.singletonMap("k", "v"), false).toString());
|
||||
assertEquals(baseStr + "[" + System.lineSeparator() + " a={k=v}" + System.lineSeparator() + "]", new ToStringBuilder(base).append("a", Collections.singletonMap("k", "v"), true).toString());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testArray() {
|
||||
final Integer i3 = Integer.valueOf(3);
|
||||
final Integer i4 = Integer.valueOf(4);
|
||||
assertEquals(baseStr + "[" + System.lineSeparator() + " a=<size=0>" + System.lineSeparator() + "]", new ToStringBuilder(base).append("a", (Object) new Integer[0], false).toString());
|
||||
assertEquals(baseStr + "[" + System.lineSeparator() + " a={}" + System.lineSeparator() + "]", new ToStringBuilder(base).append("a", (Object) new Integer[0], true).toString());
|
||||
assertEquals(baseStr + "[" + System.lineSeparator() + " a=<size=1>" + System.lineSeparator() + "]", new ToStringBuilder(base).append("a", (Object) new Integer[] {i3}, false).toString());
|
||||
assertEquals(baseStr + "[" + System.lineSeparator() + " a={3}" + System.lineSeparator() + "]", new ToStringBuilder(base).append("a", (Object) new Integer[] {i3}, true).toString());
|
||||
assertEquals(baseStr + "[" + System.lineSeparator() + " a=<size=2>" + System.lineSeparator() + "]", new ToStringBuilder(base).append("a", (Object) new Integer[] {i3, i4}, false).toString());
|
||||
assertEquals(baseStr + "[" + System.lineSeparator() + " a={3,4}" + System.lineSeparator() + "]", new ToStringBuilder(base).append("a", (Object) new Integer[] {i3, i4}, true).toString());
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
|
@ -18,8 +18,8 @@ package org.apache.commons.lang3.builder;
|
|||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
|
||||
import org.apache.commons.lang3.builder.ToStringStyleTest.Person;
|
||||
import org.junit.jupiter.api.AfterEach;
|
||||
|
@ -70,12 +70,38 @@ public class NoClassNameToStringStyleTest {
|
|||
assertEquals("[a=3]", new ToStringBuilder(base).append("a", i3).toString());
|
||||
assertEquals("[a=3,b=4]", new ToStringBuilder(base).append("a", i3).append("b", i4).toString());
|
||||
assertEquals("[a=<Integer>]", new ToStringBuilder(base).append("a", i3, false).toString());
|
||||
assertEquals("[a=<size=0>]", new ToStringBuilder(base).append("a", new ArrayList<>(), false).toString());
|
||||
assertEquals("[a=[]]", new ToStringBuilder(base).append("a", new ArrayList<>(), true).toString());
|
||||
assertEquals("[a=<size=0>]", new ToStringBuilder(base).append("a", new HashMap<>(), false).toString());
|
||||
assertEquals("[a={}]", new ToStringBuilder(base).append("a", new HashMap<>(), true).toString());
|
||||
assertEquals("[a=<size=0>]", new ToStringBuilder(base).append("a", (Object) new String[0], false).toString());
|
||||
assertEquals("[a={}]", new ToStringBuilder(base).append("a", (Object) new String[0], true).toString());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCollection() {
|
||||
final Integer i3 = Integer.valueOf(3);
|
||||
final Integer i4 = Integer.valueOf(4);
|
||||
assertEquals("[a=<size=0>]", new ToStringBuilder(base).append("a", Collections.emptyList(), false).toString());
|
||||
assertEquals("[a=[]]", new ToStringBuilder(base).append("a", Collections.emptyList(), true).toString());
|
||||
assertEquals("[a=<size=1>]", new ToStringBuilder(base).append("a", Collections.singletonList(i3), false).toString());
|
||||
assertEquals("[a=[3]]", new ToStringBuilder(base).append("a", Collections.singletonList(i3), true).toString());
|
||||
assertEquals("[a=<size=2>]", new ToStringBuilder(base).append("a", Arrays.asList(i3, i4), false).toString());
|
||||
assertEquals("[a=[3, 4]]", new ToStringBuilder(base).append("a", Arrays.asList(i3, i4), true).toString());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMap() {
|
||||
assertEquals("[a=<size=0>]", new ToStringBuilder(base).append("a", Collections.emptyMap(), false).toString());
|
||||
assertEquals("[a={}]", new ToStringBuilder(base).append("a", Collections.emptyMap(), true).toString());
|
||||
assertEquals("[a=<size=1>]", new ToStringBuilder(base).append("a", Collections.singletonMap("k", "v"), false).toString());
|
||||
assertEquals("[a={k=v}]", new ToStringBuilder(base).append("a", Collections.singletonMap("k", "v"), true).toString());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testArray() {
|
||||
final Integer i3 = Integer.valueOf(3);
|
||||
final Integer i4 = Integer.valueOf(4);
|
||||
assertEquals("[a=<size=0>]", new ToStringBuilder(base).append("a", (Object) new Integer[0], false).toString());
|
||||
assertEquals("[a={}]", new ToStringBuilder(base).append("a", (Object) new Integer[0], true).toString());
|
||||
assertEquals("[a=<size=1>]", new ToStringBuilder(base).append("a", (Object) new Integer[] {i3}, false).toString());
|
||||
assertEquals("[a={3}]", new ToStringBuilder(base).append("a", (Object) new Integer[] {i3}, true).toString());
|
||||
assertEquals("[a=<size=2>]", new ToStringBuilder(base).append("a", (Object) new Integer[] {i3, i4}, false).toString());
|
||||
assertEquals("[a={3,4}]", new ToStringBuilder(base).append("a", (Object) new Integer[] {i3, i4}, true).toString());
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
|
@ -18,8 +18,8 @@ package org.apache.commons.lang3.builder;
|
|||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
|
||||
import org.apache.commons.lang3.builder.ToStringStyleTest.Person;
|
||||
import org.junit.jupiter.api.AfterEach;
|
||||
|
@ -71,12 +71,38 @@ public class NoFieldNamesToStringStyleTest {
|
|||
assertEquals(baseStr + "[3]", new ToStringBuilder(base).append("a", i3).toString());
|
||||
assertEquals(baseStr + "[3,4]", new ToStringBuilder(base).append("a", i3).append("b", i4).toString());
|
||||
assertEquals(baseStr + "[<Integer>]", new ToStringBuilder(base).append("a", i3, false).toString());
|
||||
assertEquals(baseStr + "[<size=0>]", new ToStringBuilder(base).append("a", new ArrayList<>(), false).toString());
|
||||
assertEquals(baseStr + "[[]]", new ToStringBuilder(base).append("a", new ArrayList<>(), true).toString());
|
||||
assertEquals(baseStr + "[<size=0>]", new ToStringBuilder(base).append("a", new HashMap<>(), false).toString());
|
||||
assertEquals(baseStr + "[{}]", new ToStringBuilder(base).append("a", new HashMap<>(), true).toString());
|
||||
assertEquals(baseStr + "[<size=0>]", new ToStringBuilder(base).append("a", (Object) new String[0], false).toString());
|
||||
assertEquals(baseStr + "[{}]", new ToStringBuilder(base).append("a", (Object) new String[0], true).toString());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCollection() {
|
||||
final Integer i3 = Integer.valueOf(3);
|
||||
final Integer i4 = Integer.valueOf(4);
|
||||
assertEquals(baseStr + "[<size=0>]", new ToStringBuilder(base).append("a", Collections.emptyList(), false).toString());
|
||||
assertEquals(baseStr + "[[]]", new ToStringBuilder(base).append("a", Collections.emptyList(), true).toString());
|
||||
assertEquals(baseStr + "[<size=1>]", new ToStringBuilder(base).append("a", Collections.singletonList(i3), false).toString());
|
||||
assertEquals(baseStr + "[[3]]", new ToStringBuilder(base).append("a", Collections.singletonList(i3), true).toString());
|
||||
assertEquals(baseStr + "[<size=2>]", new ToStringBuilder(base).append("a", Arrays.asList(i3, i4), false).toString());
|
||||
assertEquals(baseStr + "[[3, 4]]", new ToStringBuilder(base).append("a", Arrays.asList(i3, i4), true).toString());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMap() {
|
||||
assertEquals(baseStr + "[<size=0>]", new ToStringBuilder(base).append("a", Collections.emptyMap(), false).toString());
|
||||
assertEquals(baseStr + "[{}]", new ToStringBuilder(base).append("a", Collections.emptyMap(), true).toString());
|
||||
assertEquals(baseStr + "[<size=1>]", new ToStringBuilder(base).append("a", Collections.singletonMap("k", "v"), false).toString());
|
||||
assertEquals(baseStr + "[{k=v}]", new ToStringBuilder(base).append("a", Collections.singletonMap("k", "v"), true).toString());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testArray() {
|
||||
final Integer i3 = Integer.valueOf(3);
|
||||
final Integer i4 = Integer.valueOf(4);
|
||||
assertEquals(baseStr + "[<size=0>]", new ToStringBuilder(base).append("a", (Object) new Integer[0], false).toString());
|
||||
assertEquals(baseStr + "[{}]", new ToStringBuilder(base).append("a", (Object) new Integer[0], true).toString());
|
||||
assertEquals(baseStr + "[<size=1>]", new ToStringBuilder(base).append("a", (Object) new Integer[] {i3}, false).toString());
|
||||
assertEquals(baseStr + "[{3}]", new ToStringBuilder(base).append("a", (Object) new Integer[] {i3}, true).toString());
|
||||
assertEquals(baseStr + "[<size=2>]", new ToStringBuilder(base).append("a", (Object) new Integer[] {i3, i4}, false).toString());
|
||||
assertEquals(baseStr + "[{3,4}]", new ToStringBuilder(base).append("a", (Object) new Integer[] {i3, i4}, true).toString());
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
|
@ -18,8 +18,8 @@ package org.apache.commons.lang3.builder;
|
|||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
|
||||
import org.apache.commons.lang3.builder.ToStringStyleTest.Person;
|
||||
import org.junit.jupiter.api.AfterEach;
|
||||
|
@ -71,12 +71,38 @@ public class ShortPrefixToStringStyleTest {
|
|||
assertEquals(baseStr + "[a=3]", new ToStringBuilder(base).append("a", i3).toString());
|
||||
assertEquals(baseStr + "[a=3,b=4]", new ToStringBuilder(base).append("a", i3).append("b", i4).toString());
|
||||
assertEquals(baseStr + "[a=<Integer>]", new ToStringBuilder(base).append("a", i3, false).toString());
|
||||
assertEquals(baseStr + "[a=<size=0>]", new ToStringBuilder(base).append("a", new ArrayList<>(), false).toString());
|
||||
assertEquals(baseStr + "[a=[]]", new ToStringBuilder(base).append("a", new ArrayList<>(), true).toString());
|
||||
assertEquals(baseStr + "[a=<size=0>]", new ToStringBuilder(base).append("a", new HashMap<>(), false).toString());
|
||||
assertEquals(baseStr + "[a={}]", new ToStringBuilder(base).append("a", new HashMap<>(), true).toString());
|
||||
assertEquals(baseStr + "[a=<size=0>]", new ToStringBuilder(base).append("a", (Object) new String[0], false).toString());
|
||||
assertEquals(baseStr + "[a={}]", new ToStringBuilder(base).append("a", (Object) new String[0], true).toString());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCollection() {
|
||||
final Integer i3 = Integer.valueOf(3);
|
||||
final Integer i4 = Integer.valueOf(4);
|
||||
assertEquals(baseStr + "[a=<size=0>]", new ToStringBuilder(base).append("a", Collections.emptyList(), false).toString());
|
||||
assertEquals(baseStr + "[a=[]]", new ToStringBuilder(base).append("a", Collections.emptyList(), true).toString());
|
||||
assertEquals(baseStr + "[a=<size=1>]", new ToStringBuilder(base).append("a", Collections.singletonList(i3), false).toString());
|
||||
assertEquals(baseStr + "[a=[3]]", new ToStringBuilder(base).append("a", Collections.singletonList(i3), true).toString());
|
||||
assertEquals(baseStr + "[a=<size=2>]", new ToStringBuilder(base).append("a", Arrays.asList(i3, i4), false).toString());
|
||||
assertEquals(baseStr + "[a=[3, 4]]", new ToStringBuilder(base).append("a", Arrays.asList(i3, i4), true).toString());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMap() {
|
||||
assertEquals(baseStr + "[a=<size=0>]", new ToStringBuilder(base).append("a", Collections.emptyMap(), false).toString());
|
||||
assertEquals(baseStr + "[a={}]", new ToStringBuilder(base).append("a", Collections.emptyMap(), true).toString());
|
||||
assertEquals(baseStr + "[a=<size=1>]", new ToStringBuilder(base).append("a", Collections.singletonMap("k", "v"), false).toString());
|
||||
assertEquals(baseStr + "[a={k=v}]", new ToStringBuilder(base).append("a", Collections.singletonMap("k", "v"), true).toString());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testArray() {
|
||||
final Integer i3 = Integer.valueOf(3);
|
||||
final Integer i4 = Integer.valueOf(4);
|
||||
assertEquals(baseStr + "[a=<size=0>]", new ToStringBuilder(base).append("a", (Object) new Integer[0], false).toString());
|
||||
assertEquals(baseStr + "[a={}]", new ToStringBuilder(base).append("a", (Object) new Integer[0], true).toString());
|
||||
assertEquals(baseStr + "[a=<size=1>]", new ToStringBuilder(base).append("a", (Object) new Integer[] {i3}, false).toString());
|
||||
assertEquals(baseStr + "[a={3}]", new ToStringBuilder(base).append("a", (Object) new Integer[] {i3}, true).toString());
|
||||
assertEquals(baseStr + "[a=<size=2>]", new ToStringBuilder(base).append("a", (Object) new Integer[] {i3, i4}, false).toString());
|
||||
assertEquals(baseStr + "[a={3,4}]", new ToStringBuilder(base).append("a", (Object) new Integer[] {i3, i4}, true).toString());
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
|
@ -18,8 +18,8 @@ package org.apache.commons.lang3.builder;
|
|||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
|
||||
import org.apache.commons.lang3.builder.ToStringStyleTest.Person;
|
||||
import org.junit.jupiter.api.AfterEach;
|
||||
|
@ -70,12 +70,38 @@ public class SimpleToStringStyleTest {
|
|||
assertEquals("3", new ToStringBuilder(base).append("a", i3).toString());
|
||||
assertEquals("3,4", new ToStringBuilder(base).append("a", i3).append("b", i4).toString());
|
||||
assertEquals("<Integer>", new ToStringBuilder(base).append("a", i3, false).toString());
|
||||
assertEquals("<size=0>", new ToStringBuilder(base).append("a", new ArrayList<>(), false).toString());
|
||||
assertEquals("[]", new ToStringBuilder(base).append("a", new ArrayList<>(), true).toString());
|
||||
assertEquals("<size=0>", new ToStringBuilder(base).append("a", new HashMap<>(), false).toString());
|
||||
assertEquals("{}", new ToStringBuilder(base).append("a", new HashMap<>(), true).toString());
|
||||
assertEquals("<size=0>", new ToStringBuilder(base).append("a", (Object) new String[0], false).toString());
|
||||
assertEquals("{}", new ToStringBuilder(base).append("a", (Object) new String[0], true).toString());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCollection() {
|
||||
final Integer i3 = Integer.valueOf(3);
|
||||
final Integer i4 = Integer.valueOf(4);
|
||||
assertEquals("<size=0>", new ToStringBuilder(base).append("a", Collections.emptyList(), false).toString());
|
||||
assertEquals("[]", new ToStringBuilder(base).append("a", Collections.emptyList(), true).toString());
|
||||
assertEquals("<size=1>", new ToStringBuilder(base).append("a", Collections.singletonList(i3), false).toString());
|
||||
assertEquals("[3]", new ToStringBuilder(base).append("a", Collections.singletonList(i3), true).toString());
|
||||
assertEquals("<size=2>", new ToStringBuilder(base).append("a", Arrays.asList(i3, i4), false).toString());
|
||||
assertEquals("[3, 4]", new ToStringBuilder(base).append("a", Arrays.asList(i3, i4), true).toString());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMap() {
|
||||
assertEquals("<size=0>", new ToStringBuilder(base).append("a", Collections.emptyMap(), false).toString());
|
||||
assertEquals("{}", new ToStringBuilder(base).append("a", Collections.emptyMap(), true).toString());
|
||||
assertEquals("<size=1>", new ToStringBuilder(base).append("a", Collections.singletonMap("k", "v"), false).toString());
|
||||
assertEquals("{k=v}", new ToStringBuilder(base).append("a", Collections.singletonMap("k", "v"), true).toString());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testArray() {
|
||||
final Integer i3 = Integer.valueOf(3);
|
||||
final Integer i4 = Integer.valueOf(4);
|
||||
assertEquals("<size=0>", new ToStringBuilder(base).append("a", (Object) new Integer[0], false).toString());
|
||||
assertEquals("{}", new ToStringBuilder(base).append("a", (Object) new Integer[0], true).toString());
|
||||
assertEquals("<size=1>", new ToStringBuilder(base).append("a", (Object) new Integer[]{i3}, false).toString());
|
||||
assertEquals("{3}", new ToStringBuilder(base).append("a", (Object) new Integer[]{i3}, true).toString());
|
||||
assertEquals("<size=2>", new ToStringBuilder(base).append("a", (Object) new Integer[]{i3, i4}, false).toString());
|
||||
assertEquals("{3,4}", new ToStringBuilder(base).append("a", (Object) new Integer[]{i3, i4}, true).toString());
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
|
@ -20,8 +20,8 @@ import static org.junit.jupiter.api.Assertions.assertEquals;
|
|||
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
|
||||
import org.apache.commons.lang3.builder.ToStringStyleTest.Person;
|
||||
import org.junit.jupiter.api.AfterEach;
|
||||
|
@ -88,12 +88,38 @@ public class StandardToStringStyleTest {
|
|||
assertEquals(baseStr + "[a=3]", new ToStringBuilder(base).append("a", i3).toString());
|
||||
assertEquals(baseStr + "[a=3,b=4]", new ToStringBuilder(base).append("a", i3).append("b", i4).toString());
|
||||
assertEquals(baseStr + "[a=%Integer%]", new ToStringBuilder(base).append("a", i3, false).toString());
|
||||
assertEquals(baseStr + "[a=%SIZE=0%]", new ToStringBuilder(base).append("a", new ArrayList<>(), false).toString());
|
||||
assertEquals(baseStr + "[a=[]]", new ToStringBuilder(base).append("a", new ArrayList<>(), true).toString());
|
||||
assertEquals(baseStr + "[a=%SIZE=0%]", new ToStringBuilder(base).append("a", new HashMap<>(), false).toString());
|
||||
assertEquals(baseStr + "[a={}]", new ToStringBuilder(base).append("a", new HashMap<>(), true).toString());
|
||||
assertEquals(baseStr + "[a=%SIZE=0%]", new ToStringBuilder(base).append("a", (Object) new String[0], false).toString());
|
||||
assertEquals(baseStr + "[a=[]]", new ToStringBuilder(base).append("a", (Object) new String[0], true).toString());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCollection() {
|
||||
final Integer i3 = Integer.valueOf(3);
|
||||
final Integer i4 = Integer.valueOf(4);
|
||||
assertEquals(baseStr + "[a=%SIZE=0%]", new ToStringBuilder(base).append("a", Collections.emptyList(), false).toString());
|
||||
assertEquals(baseStr + "[a=[]]", new ToStringBuilder(base).append("a", Collections.emptyList(), true).toString());
|
||||
assertEquals(baseStr + "[a=%SIZE=1%]", new ToStringBuilder(base).append("a", Collections.singletonList(i3), false).toString());
|
||||
assertEquals(baseStr + "[a=[3]]", new ToStringBuilder(base).append("a", Collections.singletonList(i3), true).toString());
|
||||
assertEquals(baseStr + "[a=%SIZE=2%]", new ToStringBuilder(base).append("a", Arrays.asList(i3, i4), false).toString());
|
||||
assertEquals(baseStr + "[a=[3, 4]]", new ToStringBuilder(base).append("a", Arrays.asList(i3, i4), true).toString());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMap() {
|
||||
assertEquals(baseStr + "[a=%SIZE=0%]", new ToStringBuilder(base).append("a", Collections.emptyMap(), false).toString());
|
||||
assertEquals(baseStr + "[a={}]", new ToStringBuilder(base).append("a", Collections.emptyMap(), true).toString());
|
||||
assertEquals(baseStr + "[a=%SIZE=1%]", new ToStringBuilder(base).append("a", Collections.singletonMap("k", "v"), false).toString());
|
||||
assertEquals(baseStr + "[a={k=v}]", new ToStringBuilder(base).append("a", Collections.singletonMap("k", "v"), true).toString());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testArray() {
|
||||
final Integer i3 = Integer.valueOf(3);
|
||||
final Integer i4 = Integer.valueOf(4);
|
||||
assertEquals(baseStr + "[a=%SIZE=0%]", new ToStringBuilder(base).append("a", (Object) new Integer[0], false).toString());
|
||||
assertEquals(baseStr + "[a=[]]", new ToStringBuilder(base).append("a", (Object) new Integer[0], true).toString());
|
||||
assertEquals(baseStr + "[a=%SIZE=1%]", new ToStringBuilder(base).append("a", (Object) new Integer[] {i3}, false).toString());
|
||||
assertEquals(baseStr + "[a=[3]]", new ToStringBuilder(base).append("a", (Object) new Integer[] {i3}, true).toString());
|
||||
assertEquals(baseStr + "[a=%SIZE=2%]", new ToStringBuilder(base).append("a", (Object) new Integer[] {i3, i4}, false).toString());
|
||||
assertEquals(baseStr + "[a=[3, 4]]", new ToStringBuilder(base).append("a", (Object) new Integer[] {i3, i4}, true).toString());
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
Loading…
Reference in New Issue