Java Code Examples for java.time.YearMonth#parse()
The following examples show how to use
java.time.YearMonth#parse() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TCKYearMonth.java From dragonwell8_jdk with GNU General Public License v2.0 | 5 votes |
@Test(dataProvider="badParseData", expectedExceptions=DateTimeParseException.class) public void factory_parse_fail(String text, int pos) { try { YearMonth.parse(text); fail(String.format("Parse should have failed for %s at position %d", text, pos)); } catch (DateTimeParseException ex) { assertEquals(ex.getParsedString(), text); assertEquals(ex.getErrorIndex(), pos); throw ex; } }
Example 2
Source File: YearMonthConverterTestCase.java From commons-beanutils with Apache License 2.0 | 5 votes |
public void testSimpleConversion() throws Exception { final String[] message= { "from String", "from String", "from String", "from String", "from String", "from String", "from String", "from String", }; final Object[] input = { "2007-12", "1974-05", "2112-01" }; final YearMonth[] expected = { YearMonth.parse("2007-12"), YearMonth.parse("1974-05"), YearMonth.parse("2112-01") }; for(int i=0;i<expected.length;i++) { assertEquals(message[i] + " to URI",expected[i],converter.convert(YearMonth.class,input[i])); assertEquals(message[i] + " to null type",expected[i],converter.convert(null,input[i])); } for(int i=0;i<expected.length;i++) { assertEquals(input[i] + " to String", input[i], converter.convert(String.class, expected[i])); } }
Example 3
Source File: TCKYearMonth.java From hottub with GNU General Public License v2.0 | 4 votes |
@Test(expectedExceptions=NullPointerException.class) public void factory_parse_formatter_nullText() { DateTimeFormatter f = DateTimeFormatter.ofPattern("y M"); YearMonth.parse((String) null, f); }
Example 4
Source File: TCKYearMonth.java From jdk8u60 with GNU General Public License v2.0 | 4 votes |
@Test(expectedExceptions=DateTimeParseException.class) public void factory_parse_illegalValue_Month() { YearMonth.parse("2008-13"); }
Example 5
Source File: TCKYearMonth.java From openjdk-jdk9 with GNU General Public License v2.0 | 4 votes |
@Test(expectedExceptions=NullPointerException.class) public void factory_parse_formatter_nullText() { DateTimeFormatter f = DateTimeFormatter.ofPattern("y M"); YearMonth.parse((String) null, f); }
Example 6
Source File: TCKYearMonth.java From jdk8u60 with GNU General Public License v2.0 | 4 votes |
@Test(dataProvider="goodParseData") public void factory_parse_success(String text, YearMonth expected) { YearMonth yearMonth = YearMonth.parse(text); assertEquals(yearMonth, expected); }
Example 7
Source File: YearMonthDeserializer.java From jackson-modules-java8 with Apache License 2.0 | 4 votes |
@Override public YearMonth deserialize(JsonParser parser, DeserializationContext context) throws IOException { if (parser.hasToken(JsonToken.VALUE_STRING)) { String string = parser.getText().trim(); if (string.length() == 0) { if (!isLenient()) { return _failForNotLenient(parser, context, JsonToken.VALUE_STRING); } return null; } try { return YearMonth.parse(string, _formatter); } catch (DateTimeException e) { return _handleDateTimeFormatException(context, e, _formatter, string); } } if (parser.isExpectedStartArrayToken()) { JsonToken t = parser.nextToken(); if (t == JsonToken.END_ARRAY) { return null; } if ((t == JsonToken.VALUE_STRING || t == JsonToken.VALUE_EMBEDDED_OBJECT) && context.isEnabled(DeserializationFeature.UNWRAP_SINGLE_VALUE_ARRAYS)) { final YearMonth parsed = deserialize(parser, context); if (parser.nextToken() != JsonToken.END_ARRAY) { handleMissingEndArrayForSingle(parser, context); } return parsed; } if (t != JsonToken.VALUE_NUMBER_INT) { _reportWrongToken(context, JsonToken.VALUE_NUMBER_INT, "years"); } int year = parser.getIntValue(); int month = parser.nextIntValue(-1); if (month == -1) { if (!parser.hasToken(JsonToken.VALUE_NUMBER_INT)) { _reportWrongToken(context, JsonToken.VALUE_NUMBER_INT, "months"); } month = parser.getIntValue(); } if (parser.nextToken() != JsonToken.END_ARRAY) { throw context.wrongTokenException(parser, handledType(), JsonToken.END_ARRAY, "Expected array to end"); } return YearMonth.of(year, month); } if (parser.hasToken(JsonToken.VALUE_EMBEDDED_OBJECT)) { return (YearMonth) parser.getEmbeddedObject(); } return _handleUnexpectedToken(context, parser, JsonToken.VALUE_STRING, JsonToken.START_ARRAY); }
Example 8
Source File: YearMonthFormatter.java From java-technology-stack with MIT License | 4 votes |
@Override public YearMonth parse(String text, Locale locale) throws ParseException { return YearMonth.parse(text); }
Example 9
Source File: TCKYearMonth.java From jdk8u-jdk with GNU General Public License v2.0 | 4 votes |
@Test(expectedExceptions=NullPointerException.class) public void factory_parse_formatter_nullFormatter() { YearMonth.parse("ANY", null); }
Example 10
Source File: TCKYearMonth.java From openjdk-jdk9 with GNU General Public License v2.0 | 4 votes |
@Test(expectedExceptions=DateTimeParseException.class) public void factory_parse_illegalValue_Month() { YearMonth.parse("2008-13"); }
Example 11
Source File: TCKYearMonth.java From jdk8u-dev-jdk with GNU General Public License v2.0 | 4 votes |
@Test(expectedExceptions=NullPointerException.class) public void factory_parse_nullText() { YearMonth.parse(null); }
Example 12
Source File: TCKYearMonth.java From openjdk-jdk9 with GNU General Public License v2.0 | 4 votes |
@Test(expectedExceptions=NullPointerException.class) public void factory_parse_nullText() { YearMonth.parse(null); }
Example 13
Source File: TCKYearMonth.java From openjdk-8-source with GNU General Public License v2.0 | 4 votes |
@Test(expectedExceptions=DateTimeParseException.class) public void factory_parse_illegalValue_Month() { YearMonth.parse("2008-13"); }
Example 14
Source File: YearMonthParam.java From dropwizard-java8 with Apache License 2.0 | 4 votes |
@Override protected YearMonth parse(final String input) throws Exception { return YearMonth.parse(input); }
Example 15
Source File: TCKYearMonth.java From openjdk-jdk9 with GNU General Public License v2.0 | 4 votes |
@Test(dataProvider="goodParseData") public void factory_parse_success(String text, YearMonth expected) { YearMonth yearMonth = YearMonth.parse(text); assertEquals(yearMonth, expected); }
Example 16
Source File: TCKYearMonth.java From jdk8u-dev-jdk with GNU General Public License v2.0 | 4 votes |
@Test public void factory_parse_formatter() { DateTimeFormatter f = DateTimeFormatter.ofPattern("y M"); YearMonth test = YearMonth.parse("2010 12", f); assertEquals(test, YearMonth.of(2010, 12)); }
Example 17
Source File: YearMonthXmlAdapter.java From threeten-jaxb with Apache License 2.0 | 4 votes |
@Override public YearMonth unmarshal(String stringValue) { return stringValue != null ? YearMonth.parse(stringValue) : null; }
Example 18
Source File: TCKYearMonth.java From dragonwell8_jdk with GNU General Public License v2.0 | 4 votes |
@Test(expectedExceptions=NullPointerException.class) public void factory_parse_nullText() { YearMonth.parse(null); }
Example 19
Source File: TCKYearMonth.java From jdk8u-jdk with GNU General Public License v2.0 | 4 votes |
@Test(expectedExceptions=NullPointerException.class) public void factory_parse_nullText() { YearMonth.parse(null); }
Example 20
Source File: TCKYearMonth.java From openjdk-jdk8u-backup with GNU General Public License v2.0 | 4 votes |
@Test(dataProvider="goodParseData") public void factory_parse_success(String text, YearMonth expected) { YearMonth yearMonth = YearMonth.parse(text); assertEquals(yearMonth, expected); }