Port to JUnit 4.
git-svn-id: https://svn.apache.org/repos/asf/commons/proper/lang/trunk@1185704 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
c800d51a69
commit
1b2fa6a727
|
@ -16,46 +16,45 @@
|
||||||
*/
|
*/
|
||||||
package org.apache.commons.lang3.builder;
|
package org.apache.commons.lang3.builder;
|
||||||
|
|
||||||
|
import static org.junit.Assert.assertEquals;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
|
|
||||||
import junit.framework.TestCase;
|
|
||||||
|
|
||||||
import org.apache.commons.lang3.SystemUtils;
|
import org.apache.commons.lang3.SystemUtils;
|
||||||
import org.apache.commons.lang3.builder.ToStringStyleTest.Person;
|
import org.apache.commons.lang3.builder.ToStringStyleTest.Person;
|
||||||
|
import org.junit.After;
|
||||||
|
import org.junit.Before;
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Unit tests {@link org.apache.commons.lang3.builder.MultiLineToStringStyleTest}.
|
* Unit tests {@link org.apache.commons.lang3.builder.MultiLineToStringStyleTest}.
|
||||||
*
|
*
|
||||||
* @version $Id$
|
* @version $Id$
|
||||||
*/
|
*/
|
||||||
public class MultiLineToStringStyleTest extends TestCase {
|
public class MultiLineToStringStyleTest {
|
||||||
|
|
||||||
private final Integer base = Integer.valueOf(5);
|
private final Integer base = Integer.valueOf(5);
|
||||||
private final String baseStr = base.getClass().getName() + "@" + Integer.toHexString(System.identityHashCode(base));
|
private final String baseStr = base.getClass().getName() + "@" + Integer.toHexString(System.identityHashCode(base));
|
||||||
|
|
||||||
public MultiLineToStringStyleTest(String name) {
|
@Before
|
||||||
super(name);
|
public void setUp() throws Exception {
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void setUp() throws Exception {
|
|
||||||
super.setUp();
|
|
||||||
ToStringBuilder.setDefaultStyle(ToStringStyle.MULTI_LINE_STYLE);
|
ToStringBuilder.setDefaultStyle(ToStringStyle.MULTI_LINE_STYLE);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@After
|
||||||
protected void tearDown() throws Exception {
|
public void tearDown() throws Exception {
|
||||||
super.tearDown();
|
|
||||||
ToStringBuilder.setDefaultStyle(ToStringStyle.DEFAULT_STYLE);
|
ToStringBuilder.setDefaultStyle(ToStringStyle.DEFAULT_STYLE);
|
||||||
}
|
}
|
||||||
|
|
||||||
//----------------------------------------------------------------
|
//----------------------------------------------------------------
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testBlank() {
|
public void testBlank() {
|
||||||
assertEquals(baseStr + "[" + SystemUtils.LINE_SEPARATOR + "]", new ToStringBuilder(base).toString());
|
assertEquals(baseStr + "[" + SystemUtils.LINE_SEPARATOR + "]", new ToStringBuilder(base).toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testAppendSuper() {
|
public void testAppendSuper() {
|
||||||
assertEquals(baseStr + "[" + SystemUtils.LINE_SEPARATOR + "]", new ToStringBuilder(base).appendSuper("Integer@8888[" + SystemUtils.LINE_SEPARATOR + "]").toString());
|
assertEquals(baseStr + "[" + SystemUtils.LINE_SEPARATOR + "]", new ToStringBuilder(base).appendSuper("Integer@8888[" + SystemUtils.LINE_SEPARATOR + "]").toString());
|
||||||
assertEquals(baseStr + "[" + SystemUtils.LINE_SEPARATOR + " <null>" + SystemUtils.LINE_SEPARATOR + "]", new ToStringBuilder(base).appendSuper("Integer@8888[" + SystemUtils.LINE_SEPARATOR + " <null>" + SystemUtils.LINE_SEPARATOR + "]").toString());
|
assertEquals(baseStr + "[" + SystemUtils.LINE_SEPARATOR + " <null>" + SystemUtils.LINE_SEPARATOR + "]", new ToStringBuilder(base).appendSuper("Integer@8888[" + SystemUtils.LINE_SEPARATOR + " <null>" + SystemUtils.LINE_SEPARATOR + "]").toString());
|
||||||
|
@ -65,6 +64,7 @@ public class MultiLineToStringStyleTest extends TestCase {
|
||||||
assertEquals(baseStr + "[" + SystemUtils.LINE_SEPARATOR + " a=hello" + SystemUtils.LINE_SEPARATOR + "]", new ToStringBuilder(base).appendSuper(null).append("a", "hello").toString());
|
assertEquals(baseStr + "[" + SystemUtils.LINE_SEPARATOR + " a=hello" + SystemUtils.LINE_SEPARATOR + "]", new ToStringBuilder(base).appendSuper(null).append("a", "hello").toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testObject() {
|
public void testObject() {
|
||||||
Integer i3 = Integer.valueOf(3);
|
Integer i3 = Integer.valueOf(3);
|
||||||
Integer i4 = Integer.valueOf(4);
|
Integer i4 = Integer.valueOf(4);
|
||||||
|
@ -82,6 +82,7 @@ public class MultiLineToStringStyleTest extends TestCase {
|
||||||
assertEquals(baseStr + "[" + SystemUtils.LINE_SEPARATOR + " a={}" + SystemUtils.LINE_SEPARATOR + "]", new ToStringBuilder(base).append("a", (Object) new String[0], true).toString());
|
assertEquals(baseStr + "[" + SystemUtils.LINE_SEPARATOR + " a={}" + SystemUtils.LINE_SEPARATOR + "]", new ToStringBuilder(base).append("a", (Object) new String[0], true).toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testPerson() {
|
public void testPerson() {
|
||||||
Person p = new Person();
|
Person p = new Person();
|
||||||
p.name = "Jane Doe";
|
p.name = "Jane Doe";
|
||||||
|
@ -91,12 +92,14 @@ public class MultiLineToStringStyleTest extends TestCase {
|
||||||
assertEquals(pBaseStr + "[" + SystemUtils.LINE_SEPARATOR + " name=Jane Doe" + SystemUtils.LINE_SEPARATOR + " age=25" + SystemUtils.LINE_SEPARATOR + " smoker=true" + SystemUtils.LINE_SEPARATOR + "]", new ToStringBuilder(p).append("name", p.name).append("age", p.age).append("smoker", p.smoker).toString());
|
assertEquals(pBaseStr + "[" + SystemUtils.LINE_SEPARATOR + " name=Jane Doe" + SystemUtils.LINE_SEPARATOR + " age=25" + SystemUtils.LINE_SEPARATOR + " smoker=true" + SystemUtils.LINE_SEPARATOR + "]", new ToStringBuilder(p).append("name", p.name).append("age", p.age).append("smoker", p.smoker).toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testLong() {
|
public void testLong() {
|
||||||
assertEquals(baseStr + "[" + SystemUtils.LINE_SEPARATOR + " 3" + SystemUtils.LINE_SEPARATOR + "]", new ToStringBuilder(base).append(3L).toString());
|
assertEquals(baseStr + "[" + SystemUtils.LINE_SEPARATOR + " 3" + SystemUtils.LINE_SEPARATOR + "]", new ToStringBuilder(base).append(3L).toString());
|
||||||
assertEquals(baseStr + "[" + SystemUtils.LINE_SEPARATOR + " a=3" + SystemUtils.LINE_SEPARATOR + "]", new ToStringBuilder(base).append("a", 3L).toString());
|
assertEquals(baseStr + "[" + SystemUtils.LINE_SEPARATOR + " a=3" + SystemUtils.LINE_SEPARATOR + "]", new ToStringBuilder(base).append("a", 3L).toString());
|
||||||
assertEquals(baseStr + "[" + SystemUtils.LINE_SEPARATOR + " a=3" + SystemUtils.LINE_SEPARATOR + " b=4" + SystemUtils.LINE_SEPARATOR + "]", new ToStringBuilder(base).append("a", 3L).append("b", 4L).toString());
|
assertEquals(baseStr + "[" + SystemUtils.LINE_SEPARATOR + " a=3" + SystemUtils.LINE_SEPARATOR + " b=4" + SystemUtils.LINE_SEPARATOR + "]", new ToStringBuilder(base).append("a", 3L).append("b", 4L).toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testObjectArray() {
|
public void testObjectArray() {
|
||||||
Object[] array = new Object[] {null, base, new int[] {3, 6}};
|
Object[] array = new Object[] {null, base, new int[] {3, 6}};
|
||||||
assertEquals(baseStr + "[" + SystemUtils.LINE_SEPARATOR + " {<null>,5,{3,6}}" + SystemUtils.LINE_SEPARATOR + "]", new ToStringBuilder(base).append(array).toString());
|
assertEquals(baseStr + "[" + SystemUtils.LINE_SEPARATOR + " {<null>,5,{3,6}}" + SystemUtils.LINE_SEPARATOR + "]", new ToStringBuilder(base).append(array).toString());
|
||||||
|
@ -106,6 +109,7 @@ public class MultiLineToStringStyleTest extends TestCase {
|
||||||
assertEquals(baseStr + "[" + SystemUtils.LINE_SEPARATOR + " <null>" + SystemUtils.LINE_SEPARATOR + "]", new ToStringBuilder(base).append((Object) array).toString());
|
assertEquals(baseStr + "[" + SystemUtils.LINE_SEPARATOR + " <null>" + SystemUtils.LINE_SEPARATOR + "]", new ToStringBuilder(base).append((Object) array).toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testLongArray() {
|
public void testLongArray() {
|
||||||
long[] array = new long[] {1, 2, -3, 4};
|
long[] array = new long[] {1, 2, -3, 4};
|
||||||
assertEquals(baseStr + "[" + SystemUtils.LINE_SEPARATOR + " {1,2,-3,4}" + SystemUtils.LINE_SEPARATOR + "]", new ToStringBuilder(base).append(array).toString());
|
assertEquals(baseStr + "[" + SystemUtils.LINE_SEPARATOR + " {1,2,-3,4}" + SystemUtils.LINE_SEPARATOR + "]", new ToStringBuilder(base).append(array).toString());
|
||||||
|
@ -115,6 +119,7 @@ public class MultiLineToStringStyleTest extends TestCase {
|
||||||
assertEquals(baseStr + "[" + SystemUtils.LINE_SEPARATOR + " <null>" + SystemUtils.LINE_SEPARATOR + "]", new ToStringBuilder(base).append((Object) array).toString());
|
assertEquals(baseStr + "[" + SystemUtils.LINE_SEPARATOR + " <null>" + SystemUtils.LINE_SEPARATOR + "]", new ToStringBuilder(base).append((Object) array).toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testLongArrayArray() {
|
public void testLongArrayArray() {
|
||||||
long[][] array = new long[][] {{1, 2}, null, {5}};
|
long[][] array = new long[][] {{1, 2}, null, {5}};
|
||||||
assertEquals(baseStr + "[" + SystemUtils.LINE_SEPARATOR + " {{1,2},<null>,{5}}" + SystemUtils.LINE_SEPARATOR + "]", new ToStringBuilder(base).append(array).toString());
|
assertEquals(baseStr + "[" + SystemUtils.LINE_SEPARATOR + " {{1,2},<null>,{5}}" + SystemUtils.LINE_SEPARATOR + "]", new ToStringBuilder(base).append(array).toString());
|
||||||
|
|
Loading…
Reference in New Issue