add testChar and testDate Cases into JsonToStringStyleTest

This commit is contained in:
Jack 2015-04-29 11:02:08 +08:00
parent 102b75cd92
commit cf42ae522e
1 changed files with 33 additions and 0 deletions

View File

@ -90,6 +90,39 @@ public void testAppendSuper() {
assertEquals("{\"a\":\"hello\",\"b\":\"world\"}", new ToStringBuilder(base)
.appendSuper("{\"a\":\"hello\"}").append("b", "world").toString());
}
@Test
public void testChar() {
try {
new ToStringBuilder(base).append('A').toString();
fail("Should have generated UnsupportedOperationException");
} catch (UnsupportedOperationException e) {
}
assertEquals("{\"a\":\"A\"}", new ToStringBuilder(base).append("a", 'A')
.toString());
assertEquals("{\"a\":\"A\",\"b\":\"B\"}", new ToStringBuilder(base).append("a", 'A').append("b", 'B')
.toString());
}
@Test
public void testDate() {
final Date now = new Date();
final Date after_now = new Date(System.currentTimeMillis() + 1);
try {
new ToStringBuilder(base).append(now).toString();
fail("Should have generated UnsupportedOperationException");
} catch (UnsupportedOperationException e) {
}
assertEquals("{\"now\":\"" + now.toString() +"\"}", new ToStringBuilder(base).append("now", now)
.toString());
assertEquals("{\"now\":\"" + now.toString() +"\",\"after\":\"" + after_now.toString() + "\"}", new ToStringBuilder(base).append("now", now).append("after", after_now)
.toString());
}
@Test
public void testObject() {