Java Code Examples for java.time.chrono.ChronoLocalDate#with()

The following examples show how to use java.time.chrono.ChronoLocalDate#with() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TCKChronoLocalDate.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
@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");
        }
    }
}
 
Example 2
Source File: TCKChronoLocalDate.java    From jdk8u_jdk with GNU General Public License v2.0 6 votes vote down vote up
@Test(dataProvider="calendars")
public void test_badTemporalFieldChrono(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);
        TemporalField adjuster = new FixedTemporalField(date2);
        if (chrono != chrono2) {
            try {
                date.with(adjuster, 1);
                Assert.fail("TemporalField doSet 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.with(adjuster, 1);
            assertEquals(result, date2, "TemporalField doSet failed to replace date");
        }
    }
}
 
Example 3
Source File: TCKChronoLocalDate.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
@Test(dataProvider="calendars")
public void test_badTemporalFieldChrono(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);
        TemporalField adjuster = new FixedTemporalField(date2);
        if (chrono != chrono2) {
            try {
                date.with(adjuster, 1);
                Assert.fail("TemporalField doSet 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.with(adjuster, 1);
            assertEquals(result, date2, "TemporalField doSet failed to replace date");
        }
    }
}
 
Example 4
Source File: TCKChronoLocalDate.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
@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");
        }
    }
}
 
Example 5
Source File: TCKChronoLocalDate.java    From j2objc with Apache License 2.0 6 votes vote down vote up
@Test
@UseDataProvider("data_of_calendars")
public void test_badWithAdjusterChrono(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);
        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("WithAdjuster failed to replace date", result, date2);
        }
    }
}
 
Example 6
Source File: TCKChronoLocalDate.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 6 votes vote down vote up
@Test(dataProvider="calendars")
public void test_badTemporalFieldChrono(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);
        TemporalField adjuster = new FixedTemporalField(date2);
        if (chrono != chrono2) {
            try {
                date.with(adjuster, 1);
                Assert.fail("TemporalField doSet 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.with(adjuster, 1);
            assertEquals(result, date2, "TemporalField doSet failed to replace date");
        }
    }
}
 
Example 7
Source File: TCKChronoLocalDate.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 6 votes vote down vote up
@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");
        }
    }
}
 
Example 8
Source File: TCKChronoLocalDate.java    From jdk8u-dev-jdk with GNU General Public License v2.0 6 votes vote down vote up
@Test(dataProvider="calendars")
public void test_badTemporalFieldChrono(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);
        TemporalField adjuster = new FixedTemporalField(date2);
        if (chrono != chrono2) {
            try {
                date.with(adjuster, 1);
                Assert.fail("TemporalField doSet 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.with(adjuster, 1);
            assertEquals(result, date2, "TemporalField doSet failed to replace date");
        }
    }
}
 
Example 9
Source File: TCKChronoLocalDate.java    From jdk8u60 with GNU General Public License v2.0 6 votes vote down vote up
@Test(dataProvider="calendars")
public void test_badTemporalFieldChrono(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);
        TemporalField adjuster = new FixedTemporalField(date2);
        if (chrono != chrono2) {
            try {
                date.with(adjuster, 1);
                Assert.fail("TemporalField doSet 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.with(adjuster, 1);
            assertEquals(result, date2, "TemporalField doSet failed to replace date");
        }
    }
}
 
Example 10
Source File: TCKChronoLocalDate.java    From jdk8u60 with GNU General Public License v2.0 6 votes vote down vote up
@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");
        }
    }
}
 
Example 11
Source File: TCKChronoLocalDate.java    From jdk8u-jdk with GNU General Public License v2.0 6 votes vote down vote up
@Test(dataProvider="calendars")
public void test_badTemporalFieldChrono(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);
        TemporalField adjuster = new FixedTemporalField(date2);
        if (chrono != chrono2) {
            try {
                date.with(adjuster, 1);
                Assert.fail("TemporalField doSet 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.with(adjuster, 1);
            assertEquals(result, date2, "TemporalField doSet failed to replace date");
        }
    }
}
 
Example 12
Source File: TCKChronoLocalDate.java    From openjdk-8 with GNU General Public License v2.0 6 votes vote down vote up
@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");
        }
    }
}
 
Example 13
Source File: TCKChronoLocalDate.java    From jdk8u_jdk with GNU General Public License v2.0 6 votes vote down vote up
@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");
        }
    }
}
 
Example 14
Source File: TCKChronoLocalDate.java    From dragonwell8_jdk with GNU General Public License v2.0 6 votes vote down vote up
@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");
        }
    }
}
 
Example 15
Source File: TCKChronology.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Compute the number of days from the Epoch and compute the date from the number of days.
 */
@Test(dataProvider = "calendarNameAndType")
public void test_epoch(String name, String alias) {
    Chronology chrono = Chronology.of(name); // a chronology. In practice this is rarely hardcoded
    ChronoLocalDate date1 = chrono.dateNow();
    long epoch1 = date1.getLong(ChronoField.EPOCH_DAY);
    ChronoLocalDate date2 = date1.with(ChronoField.EPOCH_DAY, epoch1);
    assertEquals(date1, date2, "Date from epoch day is not same date: " + date1 + " != " + date2);
    long epoch2 = date1.getLong(ChronoField.EPOCH_DAY);
    assertEquals(epoch1, epoch2, "Epoch day not the same: " + epoch1 + " != " + epoch2);
}
 
Example 16
Source File: TCKChronology.java    From dragonwell8_jdk with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Compute the number of days from the Epoch and compute the date from the number of days.
 */
@Test(dataProvider = "calendarNameAndType")
public void test_epoch(String name, String alias) {
    Chronology chrono = Chronology.of(name); // a chronology. In practice this is rarely hardcoded
    ChronoLocalDate date1 = chrono.dateNow();
    long epoch1 = date1.getLong(ChronoField.EPOCH_DAY);
    ChronoLocalDate date2 = date1.with(ChronoField.EPOCH_DAY, epoch1);
    assertEquals(date1, date2, "Date from epoch day is not same date: " + date1 + " != " + date2);
    long epoch2 = date1.getLong(ChronoField.EPOCH_DAY);
    assertEquals(epoch1, epoch2, "Epoch day not the same: " + epoch1 + " != " + epoch2);
}
 
Example 17
Source File: TCKChronology.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Compute the number of days from the Epoch and compute the date from the number of days.
 */
@Test(dataProvider = "calendarNameAndType")
public void test_epoch(String name, String alias) {
    Chronology chrono = Chronology.of(name); // a chronology. In practice this is rarely hardcoded
    ChronoLocalDate date1 = chrono.dateNow();
    long epoch1 = date1.getLong(ChronoField.EPOCH_DAY);
    ChronoLocalDate date2 = date1.with(ChronoField.EPOCH_DAY, epoch1);
    assertEquals(date1, date2, "Date from epoch day is not same date: " + date1 + " != " + date2);
    long epoch2 = date1.getLong(ChronoField.EPOCH_DAY);
    assertEquals(epoch1, epoch2, "Epoch day not the same: " + epoch1 + " != " + epoch2);
}
 
Example 18
Source File: TCKChronology.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Compute the number of days from the Epoch and compute the date from the number of days.
 */
@Test(dataProvider = "calendarNameAndType")
public void test_epoch(String name, String alias) {
    Chronology chrono = Chronology.of(name); // a chronology. In practice this is rarely hardcoded
    ChronoLocalDate date1 = chrono.dateNow();
    long epoch1 = date1.getLong(ChronoField.EPOCH_DAY);
    ChronoLocalDate date2 = date1.with(ChronoField.EPOCH_DAY, epoch1);
    assertEquals(date1, date2, "Date from epoch day is not same date: " + date1 + " != " + date2);
    long epoch2 = date1.getLong(ChronoField.EPOCH_DAY);
    assertEquals(epoch1, epoch2, "Epoch day not the same: " + epoch1 + " != " + epoch2);
}
 
Example 19
Source File: TCKChronology.java    From jdk8u-dev-jdk with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Compute the number of days from the Epoch and compute the date from the number of days.
 */
@Test(dataProvider = "calendarNameAndType")
public void test_epoch(String name, String alias) {
    Chronology chrono = Chronology.of(name); // a chronology. In practice this is rarely hardcoded
    ChronoLocalDate date1 = chrono.dateNow();
    long epoch1 = date1.getLong(ChronoField.EPOCH_DAY);
    ChronoLocalDate date2 = date1.with(ChronoField.EPOCH_DAY, epoch1);
    assertEquals(date1, date2, "Date from epoch day is not same date: " + date1 + " != " + date2);
    long epoch2 = date1.getLong(ChronoField.EPOCH_DAY);
    assertEquals(epoch1, epoch2, "Epoch day not the same: " + epoch1 + " != " + epoch2);
}
 
Example 20
Source File: TCKChronology.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Compute the number of days from the Epoch and compute the date from the number of days.
 */
@Test(dataProvider = "calendarNameAndType")
public void test_epoch(String name, String alias) {
    Chronology chrono = Chronology.of(name); // a chronology. In practice this is rarely hardcoded
    ChronoLocalDate date1 = chrono.dateNow();
    long epoch1 = date1.getLong(ChronoField.EPOCH_DAY);
    ChronoLocalDate date2 = date1.with(ChronoField.EPOCH_DAY, epoch1);
    assertEquals(date1, date2, "Date from epoch day is not same date: " + date1 + " != " + date2);
    long epoch2 = date1.getLong(ChronoField.EPOCH_DAY);
    assertEquals(epoch1, epoch2, "Epoch day not the same: " + epoch1 + " != " + epoch2);
}