Skip to content

Commit

Permalink
Addresses review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
naotoj committed Nov 13, 2023
1 parent 6a9a1bf commit b258983
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions test/jdk/java/time/test/java/time/format/TestDateTimeParsing.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2014, 2021, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2014, 2023, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
Expand Down Expand Up @@ -72,6 +72,7 @@
import static java.time.temporal.ChronoField.SECOND_OF_DAY;
import static java.util.Locale.US;
import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertNull;

import java.text.ParsePosition;
import java.time.DateTimeException;
Expand Down Expand Up @@ -245,7 +246,7 @@ public void test_validateHourOfAmPm() {

// Checks ::toFormat().parseObject(text, pos) do not throw DateTimeException
@Test
public void test_toFormat_2arg_null_on_error() {
public void test_toFormat_2arg_null_return_on_DateTimeException() {
var f = new DateTimeFormatterBuilder()
.appendValue(HOUR_OF_DAY, 2, 2, SignStyle.NOT_NEGATIVE)
.optionalStart()
Expand All @@ -257,6 +258,15 @@ public void test_toFormat_2arg_null_on_error() {
.optionalEnd()
.toFormatter(Locale.ROOT)
.toFormat();
assertEquals(f.parseObject("17-30", new ParsePosition(0)), null);
assertNull(f.parseObject("17-30", new ParsePosition(0)));
}

// Checks ::toFormat().parseObject(text, pos) do not throw DateTimeException
@Test
public void test_toFormat_2arg_null_return_on_IOOBE() {
var date = "2023-11-13";
assertNull(DateTimeFormatter.ISO_LOCAL_DATE
.toFormat()
.parseObject(date, new ParsePosition(date.length() + 1)));
}
}

0 comments on commit b258983

Please sign in to comment.