Search in sources :

Example 36 with TemporalUnit

use of java.time.temporal.TemporalUnit in project jdk8u_jdk by JetBrains.

the class TCKPeriod method test_minus_TemporalAmount_DaysHours.

@Test(expectedExceptions = DateTimeException.class)
public void test_minus_TemporalAmount_DaysHours() {
    TemporalAmount amount = new TemporalAmount() {

        @Override
        public long get(TemporalUnit unit) {
            if (unit == DAYS) {
                return 1;
            } else {
                return 2;
            }
        }

        @Override
        public List<TemporalUnit> getUnits() {
            List<TemporalUnit> list = new ArrayList<>();
            list.add(DAYS);
            list.add(HOURS);
            return list;
        }

        @Override
        public Temporal addTo(Temporal temporal) {
            throw new UnsupportedOperationException();
        }

        @Override
        public Temporal subtractFrom(Temporal temporal) {
            throw new UnsupportedOperationException();
        }
    };
    pymd(4, 5, 6).minus(amount);
}
Also used : Temporal(java.time.temporal.Temporal) TemporalUnit(java.time.temporal.TemporalUnit) TemporalAmount(java.time.temporal.TemporalAmount) ArrayList(java.util.ArrayList) Test(org.testng.annotations.Test)

Example 37 with TemporalUnit

use of java.time.temporal.TemporalUnit in project jdk8u_jdk by JetBrains.

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.testng.annotations.Test)

Example 38 with TemporalUnit

use of java.time.temporal.TemporalUnit in project jdk8u_jdk by JetBrains.

the class TCKPeriod method factory_from_TemporalAmount_Years_tooBig.

@Test(expectedExceptions = ArithmeticException.class)
public void factory_from_TemporalAmount_Years_tooBig() {
    TemporalAmount amount = new TemporalAmount() {

        @Override
        public long get(TemporalUnit unit) {
            return ((long) (Integer.MAX_VALUE)) + 1;
        }

        @Override
        public List<TemporalUnit> getUnits() {
            return Collections.<TemporalUnit>singletonList(YEARS);
        }

        @Override
        public Temporal addTo(Temporal temporal) {
            throw new UnsupportedOperationException();
        }

        @Override
        public Temporal subtractFrom(Temporal temporal) {
            throw new UnsupportedOperationException();
        }
    };
    Period.from(amount);
}
Also used : Temporal(java.time.temporal.Temporal) TemporalUnit(java.time.temporal.TemporalUnit) TemporalAmount(java.time.temporal.TemporalAmount) Test(org.testng.annotations.Test)

Example 39 with TemporalUnit

use of java.time.temporal.TemporalUnit in project jdk8u_jdk by JetBrains.

the class TCKPeriod method factory_from_TemporalAmount_YearsDays.

@Test
public void factory_from_TemporalAmount_YearsDays() {
    TemporalAmount amount = new TemporalAmount() {

        @Override
        public long get(TemporalUnit unit) {
            if (unit == YEARS) {
                return 23;
            } else {
                return 45;
            }
        }

        @Override
        public List<TemporalUnit> getUnits() {
            List<TemporalUnit> list = new ArrayList<>();
            list.add(YEARS);
            list.add(DAYS);
            return list;
        }

        @Override
        public Temporal addTo(Temporal temporal) {
            throw new UnsupportedOperationException();
        }

        @Override
        public Temporal subtractFrom(Temporal temporal) {
            throw new UnsupportedOperationException();
        }
    };
    assertPeriod(Period.from(amount), 23, 0, 45);
}
Also used : Temporal(java.time.temporal.Temporal) TemporalUnit(java.time.temporal.TemporalUnit) TemporalAmount(java.time.temporal.TemporalAmount) ArrayList(java.util.ArrayList) Test(org.testng.annotations.Test)

Example 40 with TemporalUnit

use of java.time.temporal.TemporalUnit in project jdk8u_jdk by JetBrains.

the class TCKPeriod method test_plus_TemporalAmount_DaysHours.

@Test(expectedExceptions = DateTimeException.class)
public void test_plus_TemporalAmount_DaysHours() {
    TemporalAmount amount = new TemporalAmount() {

        @Override
        public long get(TemporalUnit unit) {
            if (unit == DAYS) {
                return 1;
            } else {
                return 2;
            }
        }

        @Override
        public List<TemporalUnit> getUnits() {
            List<TemporalUnit> list = new ArrayList<>();
            list.add(DAYS);
            list.add(HOURS);
            return list;
        }

        @Override
        public Temporal addTo(Temporal temporal) {
            throw new UnsupportedOperationException();
        }

        @Override
        public Temporal subtractFrom(Temporal temporal) {
            throw new UnsupportedOperationException();
        }
    };
    pymd(4, 5, 6).plus(amount);
}
Also used : Temporal(java.time.temporal.Temporal) TemporalUnit(java.time.temporal.TemporalUnit) TemporalAmount(java.time.temporal.TemporalAmount) ArrayList(java.util.ArrayList) Test(org.testng.annotations.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