add testcase

This commit is contained in:
高铁
2016-04-28 12:37:28 +08:00
parent ebc89103de
commit 64d2ce8daf
@@ -20,23 +20,27 @@ public class BeanToArrayTest_date extends TestCase {
public void test_date() throws Exception {
long time = System.currentTimeMillis();
Model model = JSON.parseObject("[" + time + "]", Model.class, Feature.SupportArrayToBean);
Model model = JSON.parseObject("[" + time + "," + time + "]", Model.class, Feature.SupportArrayToBean);
Assert.assertEquals(time, model.v1.getTime());
Assert.assertEquals(time, model.v2.getTime());
}
public void test_date_null() throws Exception {
Model model = JSON.parseObject("[null]", Model.class, Feature.SupportArrayToBean);
Model model = JSON.parseObject("[null,null]", Model.class, Feature.SupportArrayToBean);
Assert.assertNull(model.v1);
Assert.assertNull(model.v2);
}
public void test_date2() throws Exception {
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd", JSON.defaultLocale);
dateFormat.setTimeZone(JSON.defaultTimeZone);
Model model = JSON.parseObject("[\"2016-01-01\"]", Model.class, Feature.SupportArrayToBean);
Model model = JSON.parseObject("[\"2016-01-01\",\"2016-01-02\"]", Model.class, Feature.SupportArrayToBean);
Assert.assertEquals(dateFormat.parse("2016-01-01").getTime(), model.v1.getTime());
Assert.assertEquals(dateFormat.parse("2016-01-02").getTime(), model.v2.getTime());
}
public static class Model {
public Date v1;
public Date v2;
}
}