本文整理匯總了Java中java.time.Year.parse方法的典型用法代碼示例。如果您正苦於以下問題:Java Year.parse方法的具體用法?Java Year.parse怎麽用?Java Year.parse使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類java.time.Year
的用法示例。
在下文中一共展示了Year.parse方法的7個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: factory_parse_fail
import java.time.Year; //導入方法依賴的package包/類
@Test(dataProvider="badParseData", expectedExceptions=DateTimeParseException.class)
public void factory_parse_fail(String text, int pos) {
try {
Year.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;
}
}
示例2: matchesYear
import java.time.Year; //導入方法依賴的package包/類
private boolean matchesYear(String yearString, Year year) {
try {
final Year parsedYear = Year.parse(yearString);
return year.equals(parsedYear);
} catch (DateTimeParseException dateTimeParseException) {
return false;
}
}
示例3: factory_parse_success
import java.time.Year; //導入方法依賴的package包/類
@Test(dataProvider="goodParseData")
public void factory_parse_success(String text, Year expected) {
Year year = Year.parse(text);
assertEquals(year, expected);
}
示例4: factory_parse_nullText
import java.time.Year; //導入方法依賴的package包/類
@Test(expectedExceptions=NullPointerException.class)
public void factory_parse_nullText() {
Year.parse(null);
}
示例5: factory_parse_formatter
import java.time.Year; //導入方法依賴的package包/類
@Test
public void factory_parse_formatter() {
DateTimeFormatter f = DateTimeFormatter.ofPattern("y");
Year test = Year.parse("2010", f);
assertEquals(test, Year.of(2010));
}
示例6: factory_parse_formatter_nullText
import java.time.Year; //導入方法依賴的package包/類
@Test(expectedExceptions=NullPointerException.class)
public void factory_parse_formatter_nullText() {
DateTimeFormatter f = DateTimeFormatter.ofPattern("y");
Year.parse((String) null, f);
}
示例7: factory_parse_formatter_nullFormatter
import java.time.Year; //導入方法依賴的package包/類
@Test(expectedExceptions=NullPointerException.class)
public void factory_parse_formatter_nullFormatter() {
Year.parse("ANY", null);
}