test/java/time/tck/java/time/temporal/TCKJulianFields.java

Print this page

        

*** 58,99 **** * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ package tck.java.time.temporal; import static org.testng.Assert.assertEquals; - import static org.testng.Assert.assertSame; - import java.io.ByteArrayInputStream; - import java.io.ByteArrayOutputStream; import java.io.IOException; - import java.io.ObjectInputStream; - import java.io.ObjectOutputStream; - import java.time.LocalDate; - import java.time.temporal.*; - - - import org.testng.annotations.BeforeMethod; import org.testng.annotations.DataProvider; import org.testng.annotations.Test; /** * Test. */ @Test ! public class TCKJulianFields { private static final LocalDate JAN01_1970 = LocalDate.of(1970, 1, 1); private static final LocalDate DEC31_1969 = LocalDate.of(1969, 12, 31); private static final LocalDate NOV12_1945 = LocalDate.of(1945, 11, 12); private static final LocalDate JAN01_0001 = LocalDate.of(1, 1, 1); - @BeforeMethod - public void setUp() { - } - //----------------------------------------------------------------------- @DataProvider(name="julian_fields") Object[][] julian_samples() { return new Object[][] { {JulianFields.JULIAN_DAY}, --- 58,91 ---- * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ package tck.java.time.temporal; import static org.testng.Assert.assertEquals; import java.io.IOException; import java.time.LocalDate; + import java.time.format.DateTimeFormatter; + import java.time.format.DateTimeFormatterBuilder; + import java.time.temporal.ChronoField; + import java.time.temporal.JulianFields; + import java.time.temporal.TemporalField; import org.testng.annotations.DataProvider; import org.testng.annotations.Test; + import tck.java.time.AbstractTCKTest; /** * Test. */ @Test ! public class TCKJulianFields extends AbstractTCKTest { private static final LocalDate JAN01_1970 = LocalDate.of(1970, 1, 1); private static final LocalDate DEC31_1969 = LocalDate.of(1969, 12, 31); private static final LocalDate NOV12_1945 = LocalDate.of(1945, 11, 12); private static final LocalDate JAN01_0001 = LocalDate.of(1, 1, 1); //----------------------------------------------------------------------- @DataProvider(name="julian_fields") Object[][] julian_samples() { return new Object[][] { {JulianFields.JULIAN_DAY},
*** 125,168 **** {JulianFields.MODIFIED_JULIAN_DAY, JAN01_0001, 31771L - 710346L}, {JulianFields.RATA_DIE, JAN01_0001, 1}, }; } ! @Test(dataProvider="samples", groups={"tck"}) public void test_samples_get(TemporalField field, LocalDate date, long expected) { assertEquals(date.getLong(field), expected); } ! @Test(dataProvider="samples", groups={"tck"}) public void test_samples_set(TemporalField field, LocalDate date, long value) { ! assertEquals(field.doWith(LocalDate.MAX, value), date); ! assertEquals(field.doWith(LocalDate.MIN, value), date); ! assertEquals(field.doWith(JAN01_1970, value), date); ! assertEquals(field.doWith(DEC31_1969, value), date); ! assertEquals(field.doWith(NOV12_1945, value), date); } //----------------------------------------------------------------------- ! // toString() ! //----------------------------------------------------------------------- ! @Test(groups={"tck"}) ! public void test_toString() { ! assertEquals(JulianFields.JULIAN_DAY.toString(), "JulianDay"); ! assertEquals(JulianFields.MODIFIED_JULIAN_DAY.toString(), "ModifiedJulianDay"); ! assertEquals(JulianFields.RATA_DIE.toString(), "RataDie"); ! } ! ! @Test(groups = {"tck"},dataProvider="julian_fields") ! public void test_JulianFieldsSingleton(TemporalField field) throws IOException, ClassNotFoundException { ! try (ByteArrayOutputStream baos = new ByteArrayOutputStream(); ! ObjectOutputStream oos = new ObjectOutputStream(baos)) { ! oos.writeObject(field); ! ! ObjectInputStream ois = new ObjectInputStream(new ByteArrayInputStream( ! baos.toByteArray())); ! TemporalField result = (TemporalField)ois.readObject(); ! assertSame(result, field, "Deserialized object same as serialized."); ! } ! // Exceptions will be handled as failures by TestNG } } --- 117,151 ---- {JulianFields.MODIFIED_JULIAN_DAY, JAN01_0001, 31771L - 710346L}, {JulianFields.RATA_DIE, JAN01_0001, 1}, }; } ! //----------------------------------------------------------------------- ! @Test(dataProvider="julian_fields") ! public void test_serializable(TemporalField field) throws IOException, ClassNotFoundException { ! assertSerializable(field); ! } ! ! //----------------------------------------------------------------------- ! @Test(dataProvider="samples") public void test_samples_get(TemporalField field, LocalDate date, long expected) { assertEquals(date.getLong(field), expected); } ! @Test(dataProvider="samples") public void test_samples_set(TemporalField field, LocalDate date, long value) { ! assertEquals(field.adjustInto(LocalDate.MAX, value), date); ! assertEquals(field.adjustInto(LocalDate.MIN, value), date); ! assertEquals(field.adjustInto(JAN01_1970, value), date); ! assertEquals(field.adjustInto(DEC31_1969, value), date); ! assertEquals(field.adjustInto(NOV12_1945, value), date); } //----------------------------------------------------------------------- ! @Test(dataProvider="samples") ! public void test_samples_parse(TemporalField field, LocalDate date, long value) { ! DateTimeFormatter f = new DateTimeFormatterBuilder().appendValue(field).toFormatter(); ! LocalDate parsed = LocalDate.parse(Long.toString(value), f); ! assertEquals(parsed, date); } }