Port to JUnit 4.
git-svn-id: https://svn.apache.org/repos/asf/commons/proper/lang/trunk@1185700 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
6e9a3888a6
commit
d9ad78065d
|
@ -16,41 +16,44 @@
|
|||
*/
|
||||
package org.apache.commons.lang3.builder;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
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.ToStringStyle#SHORT_PREFIX_STYLE}.
|
||||
*
|
||||
* @version $Id$
|
||||
*/
|
||||
public class ShortPrefixToStringStyleTest extends TestCase {
|
||||
public class ShortPrefixToStringStyleTest {
|
||||
|
||||
private final Integer base = Integer.valueOf(5);
|
||||
private final String baseStr = "Integer";
|
||||
|
||||
@Override
|
||||
protected void setUp() throws Exception {
|
||||
super.setUp();
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
ToStringBuilder.setDefaultStyle(ToStringStyle.SHORT_PREFIX_STYLE);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void tearDown() throws Exception {
|
||||
super.tearDown();
|
||||
@After
|
||||
public void tearDown() throws Exception {
|
||||
ToStringBuilder.setDefaultStyle(ToStringStyle.DEFAULT_STYLE);
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------
|
||||
|
||||
@Test
|
||||
public void testBlank() {
|
||||
assertEquals(baseStr + "[]", new ToStringBuilder(base).toString());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAppendSuper() {
|
||||
assertEquals(baseStr + "[]", new ToStringBuilder(base).appendSuper("Integer@8888[]").toString());
|
||||
assertEquals(baseStr + "[<null>]", new ToStringBuilder(base).appendSuper("Integer@8888[<null>]").toString());
|
||||
|
@ -60,6 +63,7 @@ public class ShortPrefixToStringStyleTest extends TestCase {
|
|||
assertEquals(baseStr + "[a=hello]", new ToStringBuilder(base).appendSuper(null).append("a", "hello").toString());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testObject() {
|
||||
Integer i3 = Integer.valueOf(3);
|
||||
Integer i4 = Integer.valueOf(4);
|
||||
|
@ -77,6 +81,7 @@ public class ShortPrefixToStringStyleTest extends TestCase {
|
|||
assertEquals(baseStr + "[a={}]", new ToStringBuilder(base).append("a", (Object) new String[0], true).toString());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPerson() {
|
||||
Person p = new Person();
|
||||
p.name = "John Q. Public";
|
||||
|
@ -86,12 +91,14 @@ public class ShortPrefixToStringStyleTest extends TestCase {
|
|||
assertEquals(pBaseStr + "[name=John Q. Public,age=45,smoker=true]", new ToStringBuilder(p).append("name", p.name).append("age", p.age).append("smoker", p.smoker).toString());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testLong() {
|
||||
assertEquals(baseStr + "[3]", new ToStringBuilder(base).append(3L).toString());
|
||||
assertEquals(baseStr + "[a=3]", new ToStringBuilder(base).append("a", 3L).toString());
|
||||
assertEquals(baseStr + "[a=3,b=4]", new ToStringBuilder(base).append("a", 3L).append("b", 4L).toString());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testObjectArray() {
|
||||
Object[] array = new Object[] {null, base, new int[] {3, 6}};
|
||||
assertEquals(baseStr + "[{<null>,5,{3,6}}]", new ToStringBuilder(base).append(array).toString());
|
||||
|
@ -101,6 +108,7 @@ public class ShortPrefixToStringStyleTest extends TestCase {
|
|||
assertEquals(baseStr + "[<null>]", new ToStringBuilder(base).append((Object) array).toString());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testLongArray() {
|
||||
long[] array = new long[] {1, 2, -3, 4};
|
||||
assertEquals(baseStr + "[{1,2,-3,4}]", new ToStringBuilder(base).append(array).toString());
|
||||
|
@ -110,6 +118,7 @@ public class ShortPrefixToStringStyleTest extends TestCase {
|
|||
assertEquals(baseStr + "[<null>]", new ToStringBuilder(base).append((Object) array).toString());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testLongArrayArray() {
|
||||
long[][] array = new long[][] {{1, 2}, null, {5}};
|
||||
assertEquals(baseStr + "[{{1,2},<null>,{5}}]", new ToStringBuilder(base).append(array).toString());
|
||||
|
|
Loading…
Reference in New Issue