本文整理汇总了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);
}