任何人都可以向我解释为什么这个测试通过:
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);
}
}
Run Code Online (Sandbox Code Playgroud)
第二次测试捕获的异常如下所示:
java.time.format.DateTimeParseException: Text '10:11:12' could not be parsed: Unable …Run Code Online (Sandbox Code Playgroud)