爲什麼該測試通過任何人都可以向我解釋:JDK8 java.time.LocalTime與自定義模式
import org.junit.Assert;
import org.junit.Test;
import java.time.LocalTime;
import java.time.format.DateTimeFormatter;
import java.time.format.DateTimeParseException;
import static org.hamcrest.core.Is.is;
public class BasicTest extends Assert{
@Test
public void testLocalTimeWithPredefinedPattern() throws Exception {
DateTimeFormatter dtf = DateTimeFormatter.ISO_TIME;
LocalTime time = LocalTime.parse("10:11:12", dtf);
assertThat(time.toString(), is("10:11:12"));
}
/**
* It's a kind of bug from my side of view
*/
@Test(expected = DateTimeParseException.class)
public void testLocalTimeWithCustomPattern() throws Exception {
DateTimeFormatter dtf = DateTimeFormatter.ofPattern("hh:mm:ss");
LocalTime time = LocalTime.parse("10:11:12", dtf);
}
}
異常的第二次測試是抓是這樣的:
java.time.format.DateTimeParseException: Text '10:11:12' could not be parsed: Unable to obtain LocalTime from TemporalAccessor: {MilliOfSecond=0, MinuteOfHour=11, MicroOfSecond=0, SecondOfMinute=12, NanoOfSecond=0, HourOfAmPm=10},ISO of type java.time.format.Parsed
這是一個有點不合邏輯的,不是嗎?