Search in sources :

Example 21 with TemporalUnit

use of java.time.temporal.TemporalUnit in project j2objc by google.

the class TCKChronoZonedDateTime method test_badMinusTemporalUnitChrono.

@Test()
@UseDataProvider("data_of_calendars")
public void test_badMinusTemporalUnitChrono(Chronology chrono) {
    LocalDate refDate = LocalDate.of(2013, 1, 1);
    ChronoZonedDateTime<?> czdt = chrono.date(refDate).atTime(LocalTime.NOON).atZone(ZoneOffset.UTC);
    for (Chronology[] clist : (Chronology[][]) data_of_calendars()) {
        Chronology chrono2 = clist[0];
        ChronoZonedDateTime<?> czdt2 = chrono2.date(refDate).atTime(LocalTime.NOON).atZone(ZoneOffset.UTC);
        TemporalUnit adjuster = new FixedTemporalUnit(czdt2);
        if (chrono != chrono2) {
            try {
                czdt.minus(1, adjuster);
                Assert.fail("TemporalUnit.doPlus minus should have thrown a ClassCastException, " + czdt.getClass() + " can not be cast to " + czdt2.getClass());
            } catch (ClassCastException cce) {
            // Expected exception; not an error
            }
        } else {
            // Same chronology,
            ChronoZonedDateTime<?> result = czdt.minus(1, adjuster);
            assertEquals("WithAdjuster failed to replace date", result, czdt2);
        }
    }
}
Also used : TemporalUnit(java.time.temporal.TemporalUnit) IsoChronology(java.time.chrono.IsoChronology) Chronology(java.time.chrono.Chronology) LocalDate(java.time.LocalDate) Test(org.junit.Test) UseDataProvider(com.tngtech.java.junit.dataprovider.UseDataProvider)

Example 22 with TemporalUnit

use of java.time.temporal.TemporalUnit in project j2objc by google.

the class TCKChronoLocalDateTime method test_badMinusTemporalUnitChrono.

@Test
@UseDataProvider("data_of_calendars")
public void test_badMinusTemporalUnitChrono(Chronology chrono) {
    LocalDate refDate = LocalDate.of(2013, 1, 1);
    ChronoLocalDateTime<?> cdt = chrono.date(refDate).atTime(LocalTime.NOON);
    for (Chronology[] clist : (Chronology[][]) data_of_calendars()) {
        Chronology chrono2 = clist[0];
        ChronoLocalDateTime<?> cdt2 = chrono2.date(refDate).atTime(LocalTime.NOON);
        TemporalUnit adjuster = new FixedTemporalUnit(cdt2);
        if (chrono != chrono2) {
            try {
                cdt.minus(1, adjuster);
                Assert.fail("TemporalUnit.doPlus minus should have thrown a ClassCastException" + cdt.getClass() + ", can not be cast to " + cdt2.getClass());
            } catch (ClassCastException cce) {
            // Expected exception; not an error
            }
        } else {
            // Same chronology,
            ChronoLocalDateTime<?> result = cdt.minus(1, adjuster);
            assertEquals("WithAdjuster failed to replace date", result, cdt2);
        }
    }
}
Also used : TemporalUnit(java.time.temporal.TemporalUnit) IsoChronology(java.time.chrono.IsoChronology) Chronology(java.time.chrono.Chronology) LocalDate(java.time.LocalDate) Test(org.junit.Test) UseDataProvider(com.tngtech.java.junit.dataprovider.UseDataProvider)

Example 23 with TemporalUnit

use of java.time.temporal.TemporalUnit in project j2objc by google.

the class TCKChronoLocalDateTime method test_badPlusTemporalUnitChrono.

@Test
@UseDataProvider("data_of_calendars")
public void test_badPlusTemporalUnitChrono(Chronology chrono) {
    LocalDate refDate = LocalDate.of(2013, 1, 1);
    ChronoLocalDateTime<?> cdt = chrono.date(refDate).atTime(LocalTime.NOON);
    for (Chronology[] clist : (Chronology[][]) data_of_calendars()) {
        Chronology chrono2 = clist[0];
        ChronoLocalDateTime<?> cdt2 = chrono2.date(refDate).atTime(LocalTime.NOON);
        TemporalUnit adjuster = new FixedTemporalUnit(cdt2);
        if (chrono != chrono2) {
            try {
                cdt.plus(1, adjuster);
                Assert.fail("TemporalUnit.doPlus plus should have thrown a ClassCastException" + cdt + ", can not be cast to " + cdt2);
            } catch (ClassCastException cce) {
            // Expected exception; not an error
            }
        } else {
            // Same chronology,
            ChronoLocalDateTime<?> result = cdt.plus(1, adjuster);
            assertEquals("WithAdjuster failed to replace date", result, cdt2);
        }
    }
}
Also used : TemporalUnit(java.time.temporal.TemporalUnit) IsoChronology(java.time.chrono.IsoChronology) Chronology(java.time.chrono.Chronology) LocalDate(java.time.LocalDate) Test(org.junit.Test) UseDataProvider(com.tngtech.java.junit.dataprovider.UseDataProvider)

Example 24 with TemporalUnit

use of java.time.temporal.TemporalUnit in project j2objc by google.

the class TCKChronoLocalDate method test_badMinusTemporalUnitChrono.

@Test
@UseDataProvider("data_of_calendars")
public void test_badMinusTemporalUnitChrono(Chronology chrono) {
    LocalDate refDate = LocalDate.of(2013, 1, 1);
    ChronoLocalDate date = chrono.date(refDate);
    for (Chronology[] clist : (Chronology[][]) 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("WithAdjuster failed to replace date", result, date2);
        }
    }
}
Also used : ChronoLocalDate(java.time.chrono.ChronoLocalDate) TemporalUnit(java.time.temporal.TemporalUnit) IsoChronology(java.time.chrono.IsoChronology) Chronology(java.time.chrono.Chronology) ChronoLocalDate(java.time.chrono.ChronoLocalDate) LocalDate(java.time.LocalDate) Test(org.junit.Test) UseDataProvider(com.tngtech.java.junit.dataprovider.UseDataProvider)

Example 25 with TemporalUnit

use of java.time.temporal.TemporalUnit in project j2objc by google.

the class TCKLocalTime method test_minus_longTemporalUnit_invalidUnit.

@Test
public void test_minus_longTemporalUnit_invalidUnit() {
    for (TemporalUnit unit : INVALID_UNITS) {
        try {
            TEST_12_30_40_987654321.minus(1, unit);
            fail("Unit should not be allowed " + unit);
        } catch (DateTimeException ex) {
        // expected
        }
    }
}
Also used : DateTimeException(java.time.DateTimeException) TemporalUnit(java.time.temporal.TemporalUnit) Test(org.junit.Test)

Aggregations

TemporalUnit (java.time.temporal.TemporalUnit)60 LocalDate (java.time.LocalDate)18 Test (org.junit.Test)18 Test (org.testng.annotations.Test)17 Temporal (java.time.temporal.Temporal)16 TemporalAmount (java.time.temporal.TemporalAmount)15 Chronology (java.time.chrono.Chronology)12 IsoChronology (java.time.chrono.IsoChronology)12 ArrayList (java.util.ArrayList)12 UseDataProvider (com.tngtech.java.junit.dataprovider.UseDataProvider)6 InternalErrorException (cz.metacentrum.perun.core.api.exceptions.InternalErrorException)6 DateTimeException (java.time.DateTimeException)6 HijrahChronology (java.time.chrono.HijrahChronology)6 JapaneseChronology (java.time.chrono.JapaneseChronology)6 MinguoChronology (java.time.chrono.MinguoChronology)6 ThaiBuddhistChronology (java.time.chrono.ThaiBuddhistChronology)6 Matcher (java.util.regex.Matcher)6 Pattern (java.util.regex.Pattern)6 Duration (java.time.Duration)5 ChronoLocalDate (java.time.chrono.ChronoLocalDate)4