8062804: IsoFields WEEK_BASED_YEAR and QUARTER_OF_YEAR too lenient

Addded the necessary chck in IsoFields WEEK_BASED_YEAR and QUARTER_OF_YEAR

Reviewed-by: rriggs, scolebourne
This commit is contained in:
Bhanu Prakash Gopularam 2016-05-11 10:28:23 +00:00
parent e7e64ceea3
commit f2dabbdb6a
2 changed files with 40 additions and 2 deletions

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2012, 2015, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2012, 2016, 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
@ -402,6 +402,12 @@ public final class IsoFields {
long moy = temporal.getLong(MONTH_OF_YEAR);
return ((moy + 2) / 3);
}
public ValueRange rangeRefinedBy(TemporalAccessor temporal) {
if (isSupportedBy(temporal) == false) {
throw new UnsupportedTemporalTypeException("Unsupported field: QuarterOfYear");
}
return super.rangeRefinedBy(temporal);
}
@SuppressWarnings("unchecked")
@Override
public <R extends Temporal> R adjustInto(R temporal, long newValue) {
@ -529,6 +535,12 @@ public final class IsoFields {
}
return getWeekBasedYear(LocalDate.from(temporal));
}
public ValueRange rangeRefinedBy(TemporalAccessor temporal) {
if (isSupportedBy(temporal) == false) {
throw new UnsupportedTemporalTypeException("Unsupported field: WeekBasedYear");
}
return super.rangeRefinedBy(temporal);
}
@SuppressWarnings("unchecked")
@Override
public <R extends Temporal> R adjustInto(R temporal, long newValue) {

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2012, 2013, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2012, 2016, 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
@ -71,12 +71,15 @@ import static org.testng.Assert.fail;
import java.time.DayOfWeek;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.chrono.ThaiBuddhistDate;
import java.time.format.DateTimeFormatter;
import java.time.format.DateTimeFormatterBuilder;
import java.time.format.DateTimeParseException;
import java.time.format.ResolverStyle;
import java.time.temporal.IsoFields;
import java.time.temporal.Temporal;
import java.time.temporal.TemporalField;
import java.time.temporal.UnsupportedTemporalTypeException;
import java.time.temporal.ValueRange;
import org.testng.annotations.DataProvider;
@ -438,6 +441,29 @@ public class TCKIsoFields {
assertEquals(parsed, expected);
}
//-----------------------------------------------------------------------
// range refinedby
//-----------------------------------------------------------------------
@DataProvider(name="isofields")
Object[][] data_isofields() {
return new Object[][] {
{IsoFields.DAY_OF_QUARTER},
{IsoFields.QUARTER_OF_YEAR},
{IsoFields.WEEK_OF_WEEK_BASED_YEAR},
{IsoFields.WEEK_BASED_YEAR},
};
}
@Test(dataProvider = "isofields")
public void test_isofields_rangerefinedby(TemporalField field) {
field.rangeRefinedBy(LocalDate.now());
}
@Test(dataProvider = "isofields", expectedExceptions = UnsupportedTemporalTypeException.class)
public void test_nonisofields_rangerefinedby(TemporalField field) {
field.rangeRefinedBy(ThaiBuddhistDate.now());
}
//-----------------------------------------------------------------------
public void test_loop() {
// loop round at least one 400 year cycle, including before 1970