package com.fanruan.api.util; import java.util.Date; import java.text.DateFormat; import java.text.SimpleDateFormat; import org.junit.Assert; import org.junit.Test; public class DateKitTest { @Test public void string2Date() throws Exception{ DateFormat dateFormat2 = new SimpleDateFormat("yyyy-MM-dd"); Date myDate = dateFormat2.parse("2019-02-20"); Assert.assertEquals(DateKit.string2Date("2019-02-20", false), myDate); Assert.assertEquals(DateKit.string2Date("abcd", false), new Date()); Assert.assertEquals(DateKit.string2Date("abcd", true), null); } }