Search in sources :

Example 26 with ChronoLocalDate

use of java.time.chrono.ChronoLocalDate in project jdk8u_jdk by JetBrains.

the class TCKChronoLocalDate method test_badWithAdjusterChrono.

@Test(dataProvider = "calendars")
public void test_badWithAdjusterChrono(Chronology chrono) {
    LocalDate refDate = LocalDate.of(2013, 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);
                Assert.fail("WithAdjuster should have thrown a ClassCastException");
            } catch (ClassCastException cce) {
            // Expected exception; not an error
            }
        } else {
            // Same chronology,
            ChronoLocalDate result = date.with(adjuster);
            assertEquals(result, date2, "WithAdjuster failed to replace date");
        }
    }
}
Also used : ChronoLocalDate(java.time.chrono.ChronoLocalDate) TemporalAdjuster(java.time.temporal.TemporalAdjuster) HijrahChronology(java.time.chrono.HijrahChronology) ThaiBuddhistChronology(java.time.chrono.ThaiBuddhistChronology) IsoChronology(java.time.chrono.IsoChronology) Chronology(java.time.chrono.Chronology) MinguoChronology(java.time.chrono.MinguoChronology) JapaneseChronology(java.time.chrono.JapaneseChronology) ChronoLocalDate(java.time.chrono.ChronoLocalDate) LocalDate(java.time.LocalDate) Test(org.testng.annotations.Test)

Example 27 with ChronoLocalDate

use of java.time.chrono.ChronoLocalDate in project jdk8u_jdk by JetBrains.

the class TCKChronoLocalDate method test_badPlusAdjusterChrono.

@Test(dataProvider = "calendars")
public void test_badPlusAdjusterChrono(Chronology chrono) {
    LocalDate refDate = LocalDate.of(2013, 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) {
            // Expected exception; not an error
            }
        } else {
            // Same chronology,
            ChronoLocalDate result = date.plus(adjuster);
            assertEquals(result, date2, "WithAdjuster failed to replace date");
        }
    }
}
Also used : ChronoLocalDate(java.time.chrono.ChronoLocalDate) TemporalAmount(java.time.temporal.TemporalAmount) HijrahChronology(java.time.chrono.HijrahChronology) ThaiBuddhistChronology(java.time.chrono.ThaiBuddhistChronology) IsoChronology(java.time.chrono.IsoChronology) Chronology(java.time.chrono.Chronology) MinguoChronology(java.time.chrono.MinguoChronology) JapaneseChronology(java.time.chrono.JapaneseChronology) ChronoLocalDate(java.time.chrono.ChronoLocalDate) LocalDate(java.time.LocalDate) Test(org.testng.annotations.Test)

Example 28 with ChronoLocalDate

use of java.time.chrono.ChronoLocalDate in project jdk8u_jdk by JetBrains.

the class TCKChronoLocalDate method test_badPlusTemporalUnitChrono.

@Test(dataProvider = "calendars")
public void test_badPlusTemporalUnitChrono(Chronology chrono) {
    LocalDate refDate = LocalDate.of(2013, 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);
                Assert.fail("TemporalUnit.doAdd plus should have thrown a ClassCastException" + date.getClass() + ", can not be cast to " + date2.getClass());
            } catch (ClassCastException cce) {
            // Expected exception; not an error
            }
        } else {
            // Same chronology,
            ChronoLocalDate result = date.plus(1, adjuster);
            assertEquals(result, date2, "WithAdjuster failed to replace date");
        }
    }
}
Also used : ChronoLocalDate(java.time.chrono.ChronoLocalDate) TemporalUnit(java.time.temporal.TemporalUnit) HijrahChronology(java.time.chrono.HijrahChronology) ThaiBuddhistChronology(java.time.chrono.ThaiBuddhistChronology) IsoChronology(java.time.chrono.IsoChronology) Chronology(java.time.chrono.Chronology) MinguoChronology(java.time.chrono.MinguoChronology) JapaneseChronology(java.time.chrono.JapaneseChronology) ChronoLocalDate(java.time.chrono.ChronoLocalDate) LocalDate(java.time.LocalDate) Test(org.testng.annotations.Test)

Example 29 with ChronoLocalDate

use of java.time.chrono.ChronoLocalDate in project jdk8u_jdk by JetBrains.

the class TCKChronoLocalDate method test_badMinusTemporalUnitChrono.

@Test(dataProvider = "calendars")
public void test_badMinusTemporalUnitChrono(Chronology chrono) {
    LocalDate refDate = LocalDate.of(2013, 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);
                Assert.fail("TemporalUnit.doAdd minus should have thrown a ClassCastException" + date.getClass() + ", can not be cast to " + date2.getClass());
            } catch (ClassCastException cce) {
            // Expected exception; not an error
            }
        } else {
            // Same chronology,
            ChronoLocalDate result = date.minus(1, adjuster);
            assertEquals(result, date2, "WithAdjuster failed to replace date");
        }
    }
}
Also used : ChronoLocalDate(java.time.chrono.ChronoLocalDate) TemporalUnit(java.time.temporal.TemporalUnit) HijrahChronology(java.time.chrono.HijrahChronology) ThaiBuddhistChronology(java.time.chrono.ThaiBuddhistChronology) IsoChronology(java.time.chrono.IsoChronology) Chronology(java.time.chrono.Chronology) MinguoChronology(java.time.chrono.MinguoChronology) JapaneseChronology(java.time.chrono.JapaneseChronology) ChronoLocalDate(java.time.chrono.ChronoLocalDate) LocalDate(java.time.LocalDate) Test(org.testng.annotations.Test)

Example 30 with ChronoLocalDate

use of java.time.chrono.ChronoLocalDate in project jdk8u_jdk by JetBrains.

the class TCKChronoLocalDate method test_badMinusAdjusterChrono.

@Test(dataProvider = "calendars")
public void test_badMinusAdjusterChrono(Chronology chrono) {
    LocalDate refDate = LocalDate.of(2013, 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) {
            // Expected exception; not an error
            }
        } else {
            // Same chronology,
            ChronoLocalDate result = date.minus(adjuster);
            assertEquals(result, date2, "WithAdjuster failed to replace date");
        }
    }
}
Also used : ChronoLocalDate(java.time.chrono.ChronoLocalDate) TemporalAmount(java.time.temporal.TemporalAmount) HijrahChronology(java.time.chrono.HijrahChronology) ThaiBuddhistChronology(java.time.chrono.ThaiBuddhistChronology) IsoChronology(java.time.chrono.IsoChronology) Chronology(java.time.chrono.Chronology) MinguoChronology(java.time.chrono.MinguoChronology) JapaneseChronology(java.time.chrono.JapaneseChronology) ChronoLocalDate(java.time.chrono.ChronoLocalDate) LocalDate(java.time.LocalDate) Test(org.testng.annotations.Test)

Aggregations

ChronoLocalDate (java.time.chrono.ChronoLocalDate)43 Test (org.testng.annotations.Test)34 Chronology (java.time.chrono.Chronology)28 IsoChronology (java.time.chrono.IsoChronology)19 ThaiBuddhistChronology (java.time.chrono.ThaiBuddhistChronology)18 HijrahChronology (java.time.chrono.HijrahChronology)17 MinguoChronology (java.time.chrono.MinguoChronology)17 JapaneseChronology (java.time.chrono.JapaneseChronology)15 LocalDate (java.time.LocalDate)10 DateTimeException (java.time.DateTimeException)5 ChronoPeriod (java.time.chrono.ChronoPeriod)4 Era (java.time.chrono.Era)4 DateTimeFormatter (java.time.format.DateTimeFormatter)3 TemporalAccessor (java.time.temporal.TemporalAccessor)3 TemporalField (java.time.temporal.TemporalField)3 ChronoZonedDateTime (java.time.chrono.ChronoZonedDateTime)2 ThaiBuddhistDate (java.time.chrono.ThaiBuddhistDate)2 DateTimeFormatterBuilder (java.time.format.DateTimeFormatterBuilder)2 Temporal (java.time.temporal.Temporal)2 TemporalAmount (java.time.temporal.TemporalAmount)2