Port to JUnit 4.

git-svn-id: https://svn.apache.org/repos/asf/commons/proper/lang/trunk@1185699 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Gary D. Gregory 2011-10-18 14:51:31 +00:00
parent f4223f93e4
commit 6e9a3888a6
1 changed files with 18 additions and 13 deletions

View File

@ -16,44 +16,43 @@
*/
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.SimpleToStringStyleTest}.
*
* @version $Id$
*/
public class SimpleToStringStyleTest extends TestCase {
public class SimpleToStringStyleTest {
private final Integer base = Integer.valueOf(5);
public SimpleToStringStyleTest(String name) {
super(name);
}
@Override
protected void setUp() throws Exception {
super.setUp();
@Before
public void setUp() throws Exception {
ToStringBuilder.setDefaultStyle(ToStringStyle.SIMPLE_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("", new ToStringBuilder(base).toString());
}
@Test
public void testAppendSuper() {
assertEquals("", new ToStringBuilder(base).appendSuper("").toString());
assertEquals("<null>", new ToStringBuilder(base).appendSuper("<null>").toString());
@ -63,6 +62,7 @@ public class SimpleToStringStyleTest extends TestCase {
assertEquals("hello", new ToStringBuilder(base).appendSuper(null).append("a", "hello").toString());
}
@Test
public void testObject() {
Integer i3 = Integer.valueOf(3);
Integer i4 = Integer.valueOf(4);
@ -80,6 +80,7 @@ public class SimpleToStringStyleTest extends TestCase {
assertEquals("{}", new ToStringBuilder(base).append("a", (Object) new String[0], true).toString());
}
@Test
public void testPerson() {
Person p = new Person();
p.name = "Jane Q. Public";
@ -88,12 +89,14 @@ public class SimpleToStringStyleTest extends TestCase {
assertEquals("Jane Q. Public,47,false", new ToStringBuilder(p).append("name", p.name).append("age", p.age).append("smoker", p.smoker).toString());
}
@Test
public void testLong() {
assertEquals("3", new ToStringBuilder(base).append(3L).toString());
assertEquals("3", new ToStringBuilder(base).append("a", 3L).toString());
assertEquals("3,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("{<null>,5,{3,6}}", new ToStringBuilder(base).append(array).toString());
@ -103,6 +106,7 @@ public class SimpleToStringStyleTest extends TestCase {
assertEquals("<null>", new ToStringBuilder(base).append((Object) array).toString());
}
@Test
public void testLongArray() {
long[] array = new long[] {1, 2, -3, 4};
assertEquals("{1,2,-3,4}", new ToStringBuilder(base).append(array).toString());
@ -112,6 +116,7 @@ public class SimpleToStringStyleTest extends TestCase {
assertEquals("<null>", new ToStringBuilder(base).append((Object) array).toString());
}
@Test
public void testLongArrayArray() {
long[][] array = new long[][] {{1, 2}, null, {5}};
assertEquals("{{1,2},<null>,{5}}", new ToStringBuilder(base).append(array).toString());