test/java/time/tck/java/time/chrono/TestChronoLocalDate.java

Print this page

        

*** 52,93 **** * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ ! package tck.java.time.calendar; import static org.testng.Assert.assertEquals; import static org.testng.Assert.assertTrue; import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import java.io.ObjectInputStream; import java.io.ObjectOutputStream; - import java.util.ArrayList; - import java.util.List; - import java.time.Duration; import java.time.LocalDate; ! import java.time.calendar.HijrahChrono; ! import java.time.calendar.JapaneseChrono; ! import java.time.calendar.MinguoChrono; ! import java.time.calendar.ThaiBuddhistChrono; ! import java.time.temporal.Chrono; ! import java.time.temporal.ChronoLocalDate; import java.time.temporal.ChronoUnit; - import java.time.temporal.SimplePeriod; import java.time.temporal.Temporal; import java.time.temporal.TemporalAccessor; - import java.time.format.DateTimeBuilder; - import java.time.temporal.TemporalAdder; import java.time.temporal.TemporalAdjuster; import java.time.temporal.TemporalField; - import java.time.temporal.TemporalSubtractor; - import java.time.temporal.ValueRange; import java.time.temporal.TemporalUnit; ! import java.time.temporal.ISOChrono; import org.testng.Assert; import org.testng.annotations.DataProvider; import org.testng.annotations.Test; --- 52,89 ---- * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ ! package tck.java.time.chrono; import static org.testng.Assert.assertEquals; import static org.testng.Assert.assertTrue; import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import java.io.ObjectInputStream; import java.io.ObjectOutputStream; import java.time.Duration; import java.time.LocalDate; ! import java.time.chrono.HijrahChronology; ! import java.time.chrono.JapaneseChronology; ! import java.time.chrono.MinguoChronology; ! import java.time.chrono.ThaiBuddhistChronology; ! import java.time.chrono.Chronology; ! import java.time.chrono.ChronoLocalDate; ! import java.time.chrono.IsoChronology; import java.time.temporal.ChronoUnit; import java.time.temporal.Temporal; import java.time.temporal.TemporalAccessor; import java.time.temporal.TemporalAdjuster; + import java.time.temporal.TemporalAmount; import java.time.temporal.TemporalField; import java.time.temporal.TemporalUnit; ! import java.time.temporal.ValueRange; ! import java.util.ArrayList; ! import java.util.List; import org.testng.Assert; import org.testng.annotations.DataProvider; import org.testng.annotations.Test;
*** 99,123 **** //----------------------------------------------------------------------- // regular data factory for names and descriptions of available calendars //----------------------------------------------------------------------- @DataProvider(name = "calendars") ! Chrono<?>[][] data_of_calendars() { ! return new Chrono<?>[][]{ ! {HijrahChrono.INSTANCE}, ! {ISOChrono.INSTANCE}, ! {JapaneseChrono.INSTANCE}, ! {MinguoChrono.INSTANCE}, ! {ThaiBuddhistChrono.INSTANCE}}; } @Test(groups={"tck"}, dataProvider="calendars") ! public void test_badWithAdjusterChrono(Chrono<?> chrono) { LocalDate refDate = LocalDate.of(1900, 1, 1); ChronoLocalDate<?> date = chrono.date(refDate); ! for (Chrono<?>[] clist : data_of_calendars()) { ! Chrono<?> chrono2 = clist[0]; ChronoLocalDate<?> date2 = chrono2.date(refDate); TemporalAdjuster adjuster = new FixedAdjuster(date2); if (chrono != chrono2) { try { date.with(adjuster); --- 95,119 ---- //----------------------------------------------------------------------- // regular data factory for names and descriptions of available calendars //----------------------------------------------------------------------- @DataProvider(name = "calendars") ! Chronology[][] data_of_calendars() { ! return new Chronology[][]{ ! {HijrahChronology.INSTANCE}, ! {IsoChronology.INSTANCE}, ! {JapaneseChronology.INSTANCE}, ! {MinguoChronology.INSTANCE}, ! {ThaiBuddhistChronology.INSTANCE}}; } @Test(groups={"tck"}, dataProvider="calendars") ! public void test_badWithAdjusterChrono(Chronology chrono) { LocalDate refDate = LocalDate.of(1900, 1, 1); ChronoLocalDate<?> date = chrono.date(refDate); ! for (Chronology[] clist : data_of_calendars()) { ! Chronology chrono2 = clist[0]; ChronoLocalDate<?> date2 = chrono2.date(refDate); TemporalAdjuster adjuster = new FixedAdjuster(date2); if (chrono != chrono2) { try { date.with(adjuster);
*** 132,148 **** } } } @Test(groups={"tck"}, dataProvider="calendars") ! public void test_badPlusAdjusterChrono(Chrono<?> chrono) { LocalDate refDate = LocalDate.of(1900, 1, 1); ChronoLocalDate<?> date = chrono.date(refDate); ! for (Chrono<?>[] clist : data_of_calendars()) { ! Chrono<?> chrono2 = clist[0]; ChronoLocalDate<?> date2 = chrono2.date(refDate); ! TemporalAdder adjuster = new FixedAdjuster(date2); if (chrono != chrono2) { try { date.plus(adjuster); Assert.fail("WithAdjuster should have thrown a ClassCastException"); } catch (ClassCastException cce) { --- 128,144 ---- } } } @Test(groups={"tck"}, dataProvider="calendars") ! public void test_badPlusAdjusterChrono(Chronology chrono) { LocalDate refDate = LocalDate.of(1900, 1, 1); ChronoLocalDate<?> date = chrono.date(refDate); ! for (Chronology[] clist : data_of_calendars()) { ! Chronology chrono2 = clist[0]; ChronoLocalDate<?> date2 = chrono2.date(refDate); ! TemporalAmount adjuster = new FixedAdjuster(date2); if (chrono != chrono2) { try { date.plus(adjuster); Assert.fail("WithAdjuster should have thrown a ClassCastException"); } catch (ClassCastException cce) {
*** 155,171 **** } } } @Test(groups={"tck"}, dataProvider="calendars") ! public void test_badMinusAdjusterChrono(Chrono<?> chrono) { LocalDate refDate = LocalDate.of(1900, 1, 1); ChronoLocalDate<?> date = chrono.date(refDate); ! for (Chrono<?>[] clist : data_of_calendars()) { ! Chrono<?> chrono2 = clist[0]; ChronoLocalDate<?> date2 = chrono2.date(refDate); ! TemporalSubtractor adjuster = new FixedAdjuster(date2); if (chrono != chrono2) { try { date.minus(adjuster); Assert.fail("WithAdjuster should have thrown a ClassCastException"); } catch (ClassCastException cce) { --- 151,167 ---- } } } @Test(groups={"tck"}, dataProvider="calendars") ! public void test_badMinusAdjusterChrono(Chronology chrono) { LocalDate refDate = LocalDate.of(1900, 1, 1); ChronoLocalDate<?> date = chrono.date(refDate); ! for (Chronology[] clist : data_of_calendars()) { ! Chronology chrono2 = clist[0]; ChronoLocalDate<?> date2 = chrono2.date(refDate); ! TemporalAmount adjuster = new FixedAdjuster(date2); if (chrono != chrono2) { try { date.minus(adjuster); Assert.fail("WithAdjuster should have thrown a ClassCastException"); } catch (ClassCastException cce) {
*** 178,192 **** } } } @Test(groups={"tck"}, dataProvider="calendars") ! public void test_badPlusTemporalUnitChrono(Chrono<?> chrono) { LocalDate refDate = LocalDate.of(1900, 1, 1); ChronoLocalDate<?> date = chrono.date(refDate); ! for (Chrono<?>[] clist : data_of_calendars()) { ! Chrono<?> chrono2 = clist[0]; ChronoLocalDate<?> date2 = chrono2.date(refDate); TemporalUnit adjuster = new FixedTemporalUnit(date2); if (chrono != chrono2) { try { date.plus(1, adjuster); --- 174,188 ---- } } } @Test(groups={"tck"}, dataProvider="calendars") ! public void test_badPlusTemporalUnitChrono(Chronology chrono) { LocalDate refDate = LocalDate.of(1900, 1, 1); ChronoLocalDate<?> date = chrono.date(refDate); ! for (Chronology[] clist : data_of_calendars()) { ! Chronology chrono2 = clist[0]; ChronoLocalDate<?> date2 = chrono2.date(refDate); TemporalUnit adjuster = new FixedTemporalUnit(date2); if (chrono != chrono2) { try { date.plus(1, adjuster);
*** 202,216 **** } } } @Test(groups={"tck"}, dataProvider="calendars") ! public void test_badMinusTemporalUnitChrono(Chrono<?> chrono) { LocalDate refDate = LocalDate.of(1900, 1, 1); ChronoLocalDate<?> date = chrono.date(refDate); ! for (Chrono<?>[] clist : data_of_calendars()) { ! Chrono<?> chrono2 = clist[0]; ChronoLocalDate<?> date2 = chrono2.date(refDate); TemporalUnit adjuster = new FixedTemporalUnit(date2); if (chrono != chrono2) { try { date.minus(1, adjuster); --- 198,212 ---- } } } @Test(groups={"tck"}, dataProvider="calendars") ! public void test_badMinusTemporalUnitChrono(Chronology chrono) { LocalDate refDate = LocalDate.of(1900, 1, 1); ChronoLocalDate<?> date = chrono.date(refDate); ! for (Chronology[] clist : data_of_calendars()) { ! Chronology chrono2 = clist[0]; ChronoLocalDate<?> date2 = chrono2.date(refDate); TemporalUnit adjuster = new FixedTemporalUnit(date2); if (chrono != chrono2) { try { date.minus(1, adjuster);
*** 226,240 **** } } } @Test(groups={"tck"}, dataProvider="calendars") ! public void test_badTemporalFieldChrono(Chrono<?> chrono) { LocalDate refDate = LocalDate.of(1900, 1, 1); ChronoLocalDate<?> date = chrono.date(refDate); ! for (Chrono<?>[] clist : data_of_calendars()) { ! Chrono<?> chrono2 = clist[0]; ChronoLocalDate<?> date2 = chrono2.date(refDate); TemporalField adjuster = new FixedTemporalField(date2); if (chrono != chrono2) { try { date.with(adjuster, 1); --- 222,236 ---- } } } @Test(groups={"tck"}, dataProvider="calendars") ! public void test_badTemporalFieldChrono(Chronology chrono) { LocalDate refDate = LocalDate.of(1900, 1, 1); ChronoLocalDate<?> date = chrono.date(refDate); ! for (Chronology[] clist : data_of_calendars()) { ! Chronology chrono2 = clist[0]; ChronoLocalDate<?> date2 = chrono2.date(refDate); TemporalField adjuster = new FixedTemporalField(date2); if (chrono != chrono2) { try { date.with(adjuster, 1);
*** 253,264 **** //----------------------------------------------------------------------- // isBefore, isAfter, isEqual, DATE_COMPARATOR //----------------------------------------------------------------------- @Test(groups={"tck"}, dataProvider="calendars") ! public void test_date_comparisons(Chrono<?> chrono) { ! List<ChronoLocalDate<?>> dates = new ArrayList<>(); ChronoLocalDate<?> date = chrono.date(LocalDate.of(1900, 1, 1)); // Insert dates in order, no duplicates dates.add(date.minus(1000, ChronoUnit.YEARS)); --- 249,260 ---- //----------------------------------------------------------------------- // isBefore, isAfter, isEqual, DATE_COMPARATOR //----------------------------------------------------------------------- @Test(groups={"tck"}, dataProvider="calendars") ! public void test_date_comparisons(Chronology chrono) { ! List<ChronoLocalDate> dates = new ArrayList<>(); ChronoLocalDate<?> date = chrono.date(LocalDate.of(1900, 1, 1)); // Insert dates in order, no duplicates dates.add(date.minus(1000, ChronoUnit.YEARS));
*** 276,288 **** dates.add(date.plus(10, ChronoUnit.YEARS)); dates.add(date.plus(100, ChronoUnit.YEARS)); dates.add(date.plus(1000, ChronoUnit.YEARS)); // Check these dates against the corresponding dates for every calendar ! for (Chrono<?>[] clist : data_of_calendars()) { List<ChronoLocalDate<?>> otherDates = new ArrayList<>(); ! Chrono<?> chrono2 = clist[0]; for (ChronoLocalDate<?> d : dates) { otherDates.add(chrono2.date(d)); } // Now compare the sequence of original dates with the sequence of converted dates --- 272,284 ---- dates.add(date.plus(10, ChronoUnit.YEARS)); dates.add(date.plus(100, ChronoUnit.YEARS)); dates.add(date.plus(1000, ChronoUnit.YEARS)); // Check these dates against the corresponding dates for every calendar ! for (Chronology[] clist : data_of_calendars()) { List<ChronoLocalDate<?>> otherDates = new ArrayList<>(); ! Chronology chrono2 = clist[0]; for (ChronoLocalDate<?> d : dates) { otherDates.add(chrono2.date(d)); } // Now compare the sequence of original dates with the sequence of converted dates
*** 314,342 **** //----------------------------------------------------------------------- // Test Serialization of Calendars //----------------------------------------------------------------------- @Test( groups={"tck"}, dataProvider="calendars") ! public <C extends Chrono<C>> void test_ChronoSerialization(C chrono) throws Exception { LocalDate ref = LocalDate.of(1900, 1, 5); ! ChronoLocalDate<C> orginal = chrono.date(ref); ByteArrayOutputStream baos = new ByteArrayOutputStream(); ObjectOutputStream out = new ObjectOutputStream(baos); out.writeObject(orginal); out.close(); ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray()); ObjectInputStream in = new ObjectInputStream(bais); @SuppressWarnings("unchecked") ! ChronoLocalDate<C> ser = (ChronoLocalDate<C>) in.readObject(); assertEquals(ser, orginal, "deserialized date is wrong"); } /** * FixedAdjusted returns a fixed Temporal in all adjustments. * Construct an adjuster with the Temporal that should be returned from adjust. */ ! static class FixedAdjuster implements TemporalAdjuster, TemporalAdder, TemporalSubtractor { private Temporal datetime; FixedAdjuster(Temporal datetime) { this.datetime = datetime; } --- 310,338 ---- //----------------------------------------------------------------------- // Test Serialization of Calendars //----------------------------------------------------------------------- @Test( groups={"tck"}, dataProvider="calendars") ! public void test_ChronoSerialization(Chronology chrono) throws Exception { LocalDate ref = LocalDate.of(1900, 1, 5); ! ChronoLocalDate<?> orginal = chrono.date(ref); ByteArrayOutputStream baos = new ByteArrayOutputStream(); ObjectOutputStream out = new ObjectOutputStream(baos); out.writeObject(orginal); out.close(); ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray()); ObjectInputStream in = new ObjectInputStream(bais); @SuppressWarnings("unchecked") ! ChronoLocalDate<?> ser = (ChronoLocalDate<?>) in.readObject(); assertEquals(ser, orginal, "deserialized date is wrong"); } /** * FixedAdjusted returns a fixed Temporal in all adjustments. * Construct an adjuster with the Temporal that should be returned from adjust. */ ! static class FixedAdjuster implements TemporalAdjuster, TemporalAmount { private Temporal datetime; FixedAdjuster(Temporal datetime) { this.datetime = datetime; }
*** 354,363 **** --- 350,368 ---- @Override public Temporal subtractFrom(Temporal ignore) { return datetime; } + @Override + public long get(TemporalUnit unit) { + throw new UnsupportedOperationException("Not supported yet."); + } + + @Override + public List<TemporalUnit> getUnits() { + throw new UnsupportedOperationException("Not supported yet."); + } } /** * FixedTemporalUnit returns a fixed Temporal in all adjustments. * Construct an FixedTemporalUnit with the Temporal that should be returned from doAdd.
*** 383,404 **** public boolean isDurationEstimated() { throw new UnsupportedOperationException("Not supported yet."); } @Override ! public boolean isSupported(Temporal temporal) { throw new UnsupportedOperationException("Not supported yet."); } @SuppressWarnings("unchecked") @Override ! public <R extends Temporal> R doPlus(R dateTime, long periodToAdd) { return (R) this.temporal; } @Override ! public <R extends Temporal> SimplePeriod between(R dateTime1, R dateTime2) { throw new UnsupportedOperationException("Not supported yet."); } } /** --- 388,409 ---- public boolean isDurationEstimated() { throw new UnsupportedOperationException("Not supported yet."); } @Override ! public boolean isSupportedBy(Temporal temporal) { throw new UnsupportedOperationException("Not supported yet."); } @SuppressWarnings("unchecked") @Override ! public <R extends Temporal> R addTo(R temporal, long amount) { return (R) this.temporal; } @Override ! public long between(Temporal temporal1, Temporal temporal2) { throw new UnsupportedOperationException("Not supported yet."); } } /**
*** 430,461 **** public ValueRange range() { throw new UnsupportedOperationException("Not supported yet."); } @Override ! public boolean doIsSupported(TemporalAccessor temporal) { throw new UnsupportedOperationException("Not supported yet."); } @Override ! public ValueRange doRange(TemporalAccessor temporal) { throw new UnsupportedOperationException("Not supported yet."); } @Override ! public long doGet(TemporalAccessor temporal) { throw new UnsupportedOperationException("Not supported yet."); } @SuppressWarnings("unchecked") @Override ! public <R extends Temporal> R doWith(R temporal, long newValue) { return (R) this.temporal; } - - @Override - public boolean resolve(DateTimeBuilder builder, long value) { - throw new UnsupportedOperationException("Not supported yet."); - } - } } --- 435,460 ---- public ValueRange range() { throw new UnsupportedOperationException("Not supported yet."); } @Override ! public boolean isSupportedBy(TemporalAccessor temporal) { throw new UnsupportedOperationException("Not supported yet."); } @Override ! public ValueRange rangeRefinedBy(TemporalAccessor temporal) { throw new UnsupportedOperationException("Not supported yet."); } @Override ! public long getFrom(TemporalAccessor temporal) { throw new UnsupportedOperationException("Not supported yet."); } @SuppressWarnings("unchecked") @Override ! public <R extends Temporal> R adjustInto(R temporal, long newValue) { return (R) this.temporal; } } }