test/java/time/test/java/time/format/TestCharLiteralParser.java

Print this page

        

*** 57,71 **** * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ package test.java.time.format; import static org.testng.Assert.assertEquals; import static org.testng.Assert.assertTrue; - import java.time.format.DateTimeBuilder; import java.text.ParsePosition; import org.testng.annotations.DataProvider; import org.testng.annotations.Test; /** * Test CharLiteralPrinterParser. --- 57,75 ---- * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ package test.java.time.format; + import static java.time.temporal.ChronoField.YEAR; import static org.testng.Assert.assertEquals; import static org.testng.Assert.assertTrue; + import static org.testng.Assert.fail; import java.text.ParsePosition; + import java.time.temporal.Queries; + import java.time.temporal.TemporalAccessor; + import org.testng.annotations.DataProvider; import org.testng.annotations.Test; /** * Test CharLiteralPrinterParser.
*** 99,115 **** @Test(dataProvider="success") public void test_parse_success(char c, boolean caseSensitive, String text, int pos, int expectedPos) { setCaseSensitive(caseSensitive); ParsePosition ppos = new ParsePosition(pos); ! DateTimeBuilder result = ! getFormatter(c).parseToBuilder(text, ppos); if (ppos.getErrorIndex() != -1) { assertEquals(ppos.getIndex(), expectedPos); } else { assertEquals(ppos.getIndex(), expectedPos); ! assertEquals(result.getCalendricalList().size(), 0); } } //----------------------------------------------------------------------- @DataProvider(name="error") --- 103,120 ---- @Test(dataProvider="success") public void test_parse_success(char c, boolean caseSensitive, String text, int pos, int expectedPos) { setCaseSensitive(caseSensitive); ParsePosition ppos = new ParsePosition(pos); ! TemporalAccessor parsed = getFormatter(c).parseUnresolved(text, ppos); if (ppos.getErrorIndex() != -1) { assertEquals(ppos.getIndex(), expectedPos); } else { assertEquals(ppos.getIndex(), expectedPos); ! assertEquals(parsed.isSupported(YEAR), false); ! assertEquals(parsed.query(Queries.chronology()), null); ! assertEquals(parsed.query(Queries.zoneId()), null); } } //----------------------------------------------------------------------- @DataProvider(name="error")
*** 121,133 **** } @Test(dataProvider="error") public void test_parse_error(char c, String text, int pos, Class<?> expected) { try { ! DateTimeBuilder result = ! getFormatter(c).parseToBuilder(text, new ParsePosition(pos)); ! assertTrue(false); } catch (RuntimeException ex) { assertTrue(expected.isInstance(ex)); } } } --- 126,138 ---- } @Test(dataProvider="error") public void test_parse_error(char c, String text, int pos, Class<?> expected) { try { ! ParsePosition ppos = new ParsePosition(pos); ! getFormatter(c).parseUnresolved(text, ppos); ! fail(); } catch (RuntimeException ex) { assertTrue(expected.isInstance(ex)); } } }