mirror of
https://github.com/openjdk/jdk.git
synced 2026-01-28 12:09:14 +00:00
8373830: Refactor test/jdk/java/time/test tests to use JUnit over TestNG
8373829: Refactor test/jdk/java/time/tck tests to use JUnit over TestNG Reviewed-by: naoto
This commit is contained in:
parent
f1e0e0c25e
commit
53300b4ac1
@ -1,5 +1,5 @@
|
||||
# java.time tests use TestNG
|
||||
TestNG.dirs = ..
|
||||
# java.time tests use JUnit
|
||||
JUnit.dirs = ..
|
||||
othervm.dirs = java/time/chrono
|
||||
lib.dirs = /test/lib /test/jdk/tools/lib
|
||||
lib.build = jdk.test.lib.RandomFactory
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2012, 2013, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2012, 2025, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
@ -59,8 +59,8 @@
|
||||
*/
|
||||
package tck.java.time;
|
||||
|
||||
import static org.testng.Assert.assertEquals;
|
||||
import static org.testng.Assert.fail;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.fail;
|
||||
|
||||
import java.time.DateTimeException;
|
||||
import java.time.temporal.TemporalAccessor;
|
||||
@ -68,7 +68,9 @@ import java.time.temporal.TemporalField;
|
||||
import java.time.temporal.TemporalQuery;
|
||||
import java.util.List;
|
||||
|
||||
import org.testng.annotations.Test;
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import test.java.time.temporal.MockFieldNoValue;
|
||||
|
||||
/**
|
||||
@ -101,7 +103,7 @@ public abstract class AbstractDateTimeTest extends AbstractTCKTest {
|
||||
public void basicTest_isSupported_TemporalField_supported() {
|
||||
for (TemporalAccessor sample : samples()) {
|
||||
for (TemporalField field : validFields()) {
|
||||
assertEquals(sample.isSupported(field), true, "Failed on " + sample + " " + field);
|
||||
assertEquals(true, sample.isSupported(field), "Failed on " + sample + " " + field);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -110,7 +112,7 @@ public abstract class AbstractDateTimeTest extends AbstractTCKTest {
|
||||
public void basicTest_isSupported_TemporalField_unsupported() {
|
||||
for (TemporalAccessor sample : samples()) {
|
||||
for (TemporalField field : invalidFields()) {
|
||||
assertEquals(sample.isSupported(field), false, "Failed on " + sample + " " + field);
|
||||
assertEquals(false, sample.isSupported(field), "Failed on " + sample + " " + field);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -118,7 +120,7 @@ public abstract class AbstractDateTimeTest extends AbstractTCKTest {
|
||||
@Test()
|
||||
public void basicTest_isSupported_TemporalField_null() {
|
||||
for (TemporalAccessor sample : samples()) {
|
||||
assertEquals(sample.isSupported(null), false, "Failed on " + sample);
|
||||
assertEquals(false, sample.isSupported(null), "Failed on " + sample);
|
||||
}
|
||||
}
|
||||
|
||||
@ -195,11 +197,13 @@ public abstract class AbstractDateTimeTest extends AbstractTCKTest {
|
||||
}
|
||||
}
|
||||
|
||||
@Test(expectedExceptions=DateTimeException.class)
|
||||
@Test
|
||||
public void test_get_TemporalField_invalidField() {
|
||||
for (TemporalAccessor sample : samples()) {
|
||||
sample.get(MockFieldNoValue.INSTANCE);
|
||||
}
|
||||
Assertions.assertThrows(DateTimeException.class, () -> {
|
||||
for (TemporalAccessor sample : samples()) {
|
||||
sample.get(MockFieldNoValue.INSTANCE);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Test()
|
||||
@ -240,11 +244,13 @@ public abstract class AbstractDateTimeTest extends AbstractTCKTest {
|
||||
}
|
||||
}
|
||||
|
||||
@Test(expectedExceptions=DateTimeException.class)
|
||||
@Test
|
||||
public void test_getLong_TemporalField_invalidField() {
|
||||
for (TemporalAccessor sample : samples()) {
|
||||
sample.getLong(MockFieldNoValue.INSTANCE);
|
||||
}
|
||||
Assertions.assertThrows(DateTimeException.class, () -> {
|
||||
for (TemporalAccessor sample : samples()) {
|
||||
sample.getLong(MockFieldNoValue.INSTANCE);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Test()
|
||||
@ -263,12 +269,12 @@ public abstract class AbstractDateTimeTest extends AbstractTCKTest {
|
||||
@Test
|
||||
public void basicTest_query() {
|
||||
for (TemporalAccessor sample : samples()) {
|
||||
assertEquals(sample.query(new TemporalQuery<String>() {
|
||||
assertEquals("foo", sample.query(new TemporalQuery<String>() {
|
||||
@Override
|
||||
public String queryFrom(TemporalAccessor temporal) {
|
||||
return "foo";
|
||||
}
|
||||
}), "foo");
|
||||
}));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2012, 2017, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2012, 2025, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
@ -54,9 +54,9 @@
|
||||
*/
|
||||
package tck.java.time;
|
||||
|
||||
import static org.testng.Assert.assertEquals;
|
||||
import static org.testng.Assert.assertSame;
|
||||
import static org.testng.Assert.fail;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertSame;
|
||||
import static org.junit.jupiter.api.Assertions.fail;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
@ -70,6 +70,8 @@ import java.io.Serializable;
|
||||
import java.util.Formatter;
|
||||
import java.util.Map;
|
||||
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
|
||||
/**
|
||||
* Base test class.
|
||||
*/
|
||||
@ -107,13 +109,13 @@ public abstract class AbstractTCKTest {
|
||||
}
|
||||
|
||||
protected static void assertSerializable(Object object) throws IOException, ClassNotFoundException {
|
||||
assertEquals(object instanceof Serializable, true);
|
||||
assertEquals(true, object instanceof Serializable);
|
||||
Object deserializedObject = writeThenRead(object);
|
||||
assertEquals(deserializedObject, object);
|
||||
assertEquals(object, deserializedObject);
|
||||
}
|
||||
|
||||
protected static void assertSerializableSame(Object object) throws IOException, ClassNotFoundException {
|
||||
assertEquals(object instanceof Serializable, true);
|
||||
assertEquals(true, object instanceof Serializable);
|
||||
Object deserializedObject = writeThenRead(object);
|
||||
assertSame(deserializedObject, object);
|
||||
}
|
||||
@ -139,26 +141,26 @@ public abstract class AbstractTCKTest {
|
||||
byte[] bytes = baos.toByteArray();
|
||||
ByteArrayInputStream bais = new ByteArrayInputStream(bytes);
|
||||
try (DataInputStream dis = new DataInputStream(bais)) {
|
||||
assertEquals(dis.readShort(), ObjectStreamConstants.STREAM_MAGIC);
|
||||
assertEquals(dis.readShort(), ObjectStreamConstants.STREAM_VERSION);
|
||||
assertEquals(dis.readByte(), ObjectStreamConstants.TC_OBJECT);
|
||||
assertEquals(dis.readByte(), ObjectStreamConstants.TC_CLASSDESC);
|
||||
assertEquals(dis.readUTF(), serClass);
|
||||
assertEquals(dis.readLong(), serVer);
|
||||
assertEquals(dis.readByte(), ObjectStreamConstants.SC_EXTERNALIZABLE | ObjectStreamConstants.SC_BLOCK_DATA);
|
||||
assertEquals(dis.readShort(), 0); // number of fields
|
||||
assertEquals(dis.readByte(), ObjectStreamConstants.TC_ENDBLOCKDATA); // end of classdesc
|
||||
assertEquals(dis.readByte(), ObjectStreamConstants.TC_NULL); // no superclasses
|
||||
assertEquals(ObjectStreamConstants.STREAM_MAGIC, dis.readShort());
|
||||
assertEquals(ObjectStreamConstants.STREAM_VERSION, dis.readShort());
|
||||
assertEquals(ObjectStreamConstants.TC_OBJECT, dis.readByte());
|
||||
assertEquals(ObjectStreamConstants.TC_CLASSDESC, dis.readByte());
|
||||
assertEquals(serClass, dis.readUTF());
|
||||
assertEquals(serVer, dis.readLong());
|
||||
assertEquals(ObjectStreamConstants.SC_EXTERNALIZABLE | ObjectStreamConstants.SC_BLOCK_DATA, dis.readByte());
|
||||
assertEquals(0, dis.readShort()); // number of fields
|
||||
assertEquals(ObjectStreamConstants.TC_ENDBLOCKDATA, dis.readByte()); // end of classdesc
|
||||
assertEquals(ObjectStreamConstants.TC_NULL, dis.readByte()); // no superclasses
|
||||
if (expectedBytes.length < 256) {
|
||||
assertEquals(dis.readByte(), ObjectStreamConstants.TC_BLOCKDATA);
|
||||
assertEquals(dis.readUnsignedByte(), expectedBytes.length, "blockdata length incorrect");
|
||||
assertEquals(ObjectStreamConstants.TC_BLOCKDATA, dis.readByte());
|
||||
assertEquals(expectedBytes.length, dis.readUnsignedByte(), "blockdata length incorrect");
|
||||
} else {
|
||||
assertEquals(dis.readByte(), ObjectStreamConstants.TC_BLOCKDATALONG);
|
||||
assertEquals(dis.readInt(), expectedBytes.length, "blockdatalong length incorrect");
|
||||
assertEquals(ObjectStreamConstants.TC_BLOCKDATALONG, dis.readByte());
|
||||
assertEquals(expectedBytes.length, dis.readInt(), "blockdatalong length incorrect");
|
||||
}
|
||||
byte[] input = new byte[expectedBytes.length];
|
||||
dis.readFully(input);
|
||||
assertEquals(input, expectedBytes);
|
||||
Assertions.assertArrayEquals(expectedBytes, input);
|
||||
if (matches.length > 0) {
|
||||
for (byte[] match : matches) {
|
||||
boolean matched = false;
|
||||
@ -167,7 +169,7 @@ public abstract class AbstractTCKTest {
|
||||
dis.mark(1000);
|
||||
byte[] possible = new byte[match.length];
|
||||
dis.readFully(possible);
|
||||
assertEquals(possible, match);
|
||||
Assertions.assertArrayEquals(match, possible);
|
||||
matched = true;
|
||||
} catch (AssertionError ex) {
|
||||
dis.reset();
|
||||
@ -176,8 +178,8 @@ public abstract class AbstractTCKTest {
|
||||
}
|
||||
}
|
||||
} else {
|
||||
assertEquals(dis.readByte(), ObjectStreamConstants.TC_ENDBLOCKDATA); // end of blockdata
|
||||
assertEquals(dis.read(), -1);
|
||||
assertEquals(ObjectStreamConstants.TC_ENDBLOCKDATA, dis.readByte()); // end of blockdata
|
||||
assertEquals(-1, dis.read());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2012, 2013, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2012, 2025, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
@ -59,18 +59,17 @@
|
||||
*/
|
||||
package tck.java.time;
|
||||
|
||||
import static org.testng.Assert.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
|
||||
import java.time.Clock;
|
||||
import java.time.Instant;
|
||||
import java.time.ZoneId;
|
||||
|
||||
import org.testng.annotations.Test;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
/**
|
||||
* Test Clock.
|
||||
*/
|
||||
@Test
|
||||
public class TCKClock {
|
||||
|
||||
static class MockInstantClock extends Clock {
|
||||
@ -117,18 +116,18 @@ public class TCKClock {
|
||||
//-----------------------------------------------------------------------
|
||||
@Test
|
||||
public void test_mockInstantClock_get() {
|
||||
assertEquals(MOCK_INSTANT.instant(), INSTANT);
|
||||
assertEquals(MOCK_INSTANT.millis(), INSTANT.toEpochMilli());
|
||||
assertEquals(MOCK_INSTANT.getZone(), ZONE);
|
||||
assertEquals(INSTANT, MOCK_INSTANT.instant());
|
||||
assertEquals(INSTANT.toEpochMilli(), MOCK_INSTANT.millis());
|
||||
assertEquals(ZONE, MOCK_INSTANT.getZone());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test_mockInstantClock_withZone() {
|
||||
ZoneId london = ZoneId.of("Europe/London");
|
||||
Clock changed = MOCK_INSTANT.withZone(london);
|
||||
assertEquals(MOCK_INSTANT.instant(), INSTANT);
|
||||
assertEquals(MOCK_INSTANT.millis(), INSTANT.toEpochMilli());
|
||||
assertEquals(changed.getZone(), london);
|
||||
assertEquals(INSTANT, MOCK_INSTANT.instant());
|
||||
assertEquals(INSTANT.toEpochMilli(), MOCK_INSTANT.millis());
|
||||
assertEquals(london, changed.getZone());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2012, 2013, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2012, 2025, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
@ -59,7 +59,7 @@
|
||||
*/
|
||||
package tck.java.time;
|
||||
|
||||
import static org.testng.Assert.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.time.Clock;
|
||||
@ -68,12 +68,12 @@ import java.time.LocalDateTime;
|
||||
import java.time.ZoneId;
|
||||
import java.time.ZoneOffset;
|
||||
|
||||
import org.testng.annotations.Test;
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
/**
|
||||
* Test fixed clock.
|
||||
*/
|
||||
@Test
|
||||
public class TCKClock_Fixed extends AbstractTCKTest {
|
||||
|
||||
private static final ZoneId MOSCOW = ZoneId.of("Europe/Moscow");
|
||||
@ -81,72 +81,77 @@ public class TCKClock_Fixed extends AbstractTCKTest {
|
||||
private static final Instant INSTANT = LocalDateTime.of(2008, 6, 30, 11, 30, 10, 500).atZone(ZoneOffset.ofHours(2)).toInstant();
|
||||
|
||||
//-------------------------------------------------------------------------
|
||||
@Test
|
||||
public void test_fixed_InstantZoneId() {
|
||||
Clock test = Clock.fixed(INSTANT, PARIS);
|
||||
assertEquals(test.instant(), INSTANT);
|
||||
assertEquals(test.getZone(), PARIS);
|
||||
assertEquals(test.instant().getEpochSecond()*1000, test.millis());
|
||||
assertEquals(INSTANT, test.instant());
|
||||
assertEquals(PARIS, test.getZone());
|
||||
assertEquals(test.millis(), test.instant().getEpochSecond()*1000);
|
||||
}
|
||||
|
||||
@Test(expectedExceptions = NullPointerException.class)
|
||||
@Test
|
||||
public void test_fixed_InstantZoneId_nullInstant() {
|
||||
Clock.fixed(null, PARIS);
|
||||
Assertions.assertThrows(NullPointerException.class, () -> Clock.fixed(null, PARIS));
|
||||
}
|
||||
|
||||
@Test(expectedExceptions = NullPointerException.class)
|
||||
@Test
|
||||
public void test_fixed_InstantZoneId_nullZoneId() {
|
||||
Clock.fixed(INSTANT, null);
|
||||
Assertions.assertThrows(NullPointerException.class, () -> Clock.fixed(INSTANT, null));
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------------
|
||||
@Test
|
||||
public void test_withZone() {
|
||||
Clock test = Clock.fixed(INSTANT, PARIS);
|
||||
Clock changed = test.withZone(MOSCOW);
|
||||
assertEquals(test.getZone(), PARIS);
|
||||
assertEquals(changed.getZone(), MOSCOW);
|
||||
assertEquals(PARIS, test.getZone());
|
||||
assertEquals(MOSCOW, changed.getZone());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test_withZone_equal() {
|
||||
Clock test = Clock.fixed(INSTANT, PARIS);
|
||||
Clock changed = test.withZone(PARIS);
|
||||
assertEquals(changed.getZone(), PARIS);
|
||||
assertEquals(PARIS, changed.getZone());
|
||||
}
|
||||
|
||||
@Test(expectedExceptions = NullPointerException.class)
|
||||
@Test
|
||||
public void test_withZone_null() {
|
||||
Clock.fixed(INSTANT, PARIS).withZone(null);
|
||||
Assertions.assertThrows(NullPointerException.class, () -> Clock.fixed(INSTANT, PARIS).withZone(null));
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
@Test
|
||||
public void test_equals() {
|
||||
Clock a = Clock.fixed(INSTANT, ZoneOffset.UTC);
|
||||
Clock b = Clock.fixed(INSTANT, ZoneOffset.UTC);
|
||||
assertEquals(a.equals(a), true);
|
||||
assertEquals(a.equals(b), true);
|
||||
assertEquals(b.equals(a), true);
|
||||
assertEquals(b.equals(b), true);
|
||||
assertEquals(true, a.equals(a));
|
||||
assertEquals(true, a.equals(b));
|
||||
assertEquals(true, b.equals(a));
|
||||
assertEquals(true, b.equals(b));
|
||||
|
||||
Clock c = Clock.fixed(INSTANT, PARIS);
|
||||
assertEquals(a.equals(c), false);
|
||||
assertEquals(false, a.equals(c));
|
||||
|
||||
Clock d = Clock.fixed(INSTANT.minusNanos(1), ZoneOffset.UTC);
|
||||
assertEquals(a.equals(d), false);
|
||||
assertEquals(false, a.equals(d));
|
||||
|
||||
assertEquals(a.equals(null), false);
|
||||
assertEquals(a.equals("other type"), false);
|
||||
assertEquals(a.equals(Clock.systemUTC()), false);
|
||||
assertEquals(false, a.equals(null));
|
||||
assertEquals(false, a.equals("other type"));
|
||||
assertEquals(false, a.equals(Clock.systemUTC()));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test_hashCode() {
|
||||
Clock a = Clock.fixed(INSTANT, ZoneOffset.UTC);
|
||||
Clock b = Clock.fixed(INSTANT, ZoneOffset.UTC);
|
||||
assertEquals(a.hashCode(), a.hashCode());
|
||||
assertEquals(a.hashCode(), b.hashCode());
|
||||
assertEquals(b.hashCode(), a.hashCode());
|
||||
|
||||
Clock c = Clock.fixed(INSTANT, PARIS);
|
||||
assertEquals(a.hashCode() == c.hashCode(), false);
|
||||
assertEquals(false, a.hashCode() == c.hashCode());
|
||||
|
||||
Clock d = Clock.fixed(INSTANT.minusNanos(1), ZoneOffset.UTC);
|
||||
assertEquals(a.hashCode() == d.hashCode(), false);
|
||||
assertEquals(false, a.hashCode() == d.hashCode());
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2012, 2013, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2012, 2025, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
@ -59,8 +59,8 @@
|
||||
*/
|
||||
package tck.java.time;
|
||||
|
||||
import static org.testng.Assert.assertEquals;
|
||||
import static org.testng.Assert.assertSame;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertSame;
|
||||
|
||||
import java.time.Clock;
|
||||
import java.time.Duration;
|
||||
@ -69,12 +69,12 @@ import java.time.LocalDateTime;
|
||||
import java.time.ZoneId;
|
||||
import java.time.ZoneOffset;
|
||||
|
||||
import org.testng.annotations.Test;
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
/**
|
||||
* Test offset clock.
|
||||
*/
|
||||
@Test
|
||||
public class TCKClock_Offset extends AbstractTCKTest {
|
||||
|
||||
private static final ZoneId MOSCOW = ZoneId.of("Europe/Moscow");
|
||||
@ -83,80 +83,86 @@ public class TCKClock_Offset extends AbstractTCKTest {
|
||||
private static final Duration OFFSET = Duration.ofSeconds(2);
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
@Test
|
||||
public void test_offset_ClockDuration() {
|
||||
Clock test = Clock.offset(Clock.fixed(INSTANT, PARIS), OFFSET);
|
||||
//System.out.println(test.instant());
|
||||
//System.out.println(INSTANT.plus(OFFSET));
|
||||
assertEquals(test.instant(), INSTANT.plus(OFFSET));
|
||||
assertEquals(test.getZone(), PARIS);
|
||||
assertEquals(INSTANT.plus(OFFSET), test.instant());
|
||||
assertEquals(PARIS, test.getZone());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test_offset_ClockDuration_zeroDuration() {
|
||||
Clock underlying = Clock.system(PARIS);
|
||||
Clock test = Clock.offset(underlying, Duration.ZERO);
|
||||
assertSame(test, underlying); // spec says same
|
||||
}
|
||||
|
||||
@Test(expectedExceptions = NullPointerException.class)
|
||||
@Test
|
||||
public void test_offset_ClockDuration_nullClock() {
|
||||
Clock.offset(null, Duration.ZERO);
|
||||
Assertions.assertThrows(NullPointerException.class, () -> Clock.offset(null, Duration.ZERO));
|
||||
}
|
||||
|
||||
@Test(expectedExceptions = NullPointerException.class)
|
||||
@Test
|
||||
public void test_offset_ClockDuration_nullDuration() {
|
||||
Clock.offset(Clock.systemUTC(), null);
|
||||
Assertions.assertThrows(NullPointerException.class, () -> Clock.offset(Clock.systemUTC(), null));
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------------
|
||||
@Test
|
||||
public void test_withZone() {
|
||||
Clock test = Clock.offset(Clock.system(PARIS), OFFSET);
|
||||
Clock changed = test.withZone(MOSCOW);
|
||||
assertEquals(test.getZone(), PARIS);
|
||||
assertEquals(changed.getZone(), MOSCOW);
|
||||
assertEquals(PARIS, test.getZone());
|
||||
assertEquals(MOSCOW, changed.getZone());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test_withZone_equal() {
|
||||
Clock test = Clock.offset(Clock.system(PARIS), OFFSET);
|
||||
Clock changed = test.withZone(PARIS);
|
||||
assertEquals(test, changed);
|
||||
assertEquals(changed, test);
|
||||
}
|
||||
|
||||
@Test(expectedExceptions = NullPointerException.class)
|
||||
@Test
|
||||
public void test_withZone_null() {
|
||||
Clock.offset(Clock.system(PARIS), OFFSET).withZone(null);
|
||||
Assertions.assertThrows(NullPointerException.class, () -> Clock.offset(Clock.system(PARIS), OFFSET).withZone(null));
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
@Test
|
||||
public void test_equals() {
|
||||
Clock a = Clock.offset(Clock.system(PARIS), OFFSET);
|
||||
Clock b = Clock.offset(Clock.system(PARIS), OFFSET);
|
||||
assertEquals(a.equals(a), true);
|
||||
assertEquals(a.equals(b), true);
|
||||
assertEquals(b.equals(a), true);
|
||||
assertEquals(b.equals(b), true);
|
||||
assertEquals(true, a.equals(a));
|
||||
assertEquals(true, a.equals(b));
|
||||
assertEquals(true, b.equals(a));
|
||||
assertEquals(true, b.equals(b));
|
||||
|
||||
Clock c = Clock.offset(Clock.system(MOSCOW), OFFSET);
|
||||
assertEquals(a.equals(c), false);
|
||||
assertEquals(false, a.equals(c));
|
||||
|
||||
Clock d = Clock.offset(Clock.system(PARIS), OFFSET.minusNanos(1));
|
||||
assertEquals(a.equals(d), false);
|
||||
assertEquals(false, a.equals(d));
|
||||
|
||||
assertEquals(a.equals(null), false);
|
||||
assertEquals(a.equals("other type"), false);
|
||||
assertEquals(a.equals(Clock.systemUTC()), false);
|
||||
assertEquals(false, a.equals(null));
|
||||
assertEquals(false, a.equals("other type"));
|
||||
assertEquals(false, a.equals(Clock.systemUTC()));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test_hashCode() {
|
||||
Clock a = Clock.offset(Clock.system(PARIS), OFFSET);
|
||||
Clock b = Clock.offset(Clock.system(PARIS), OFFSET);
|
||||
assertEquals(a.hashCode(), a.hashCode());
|
||||
assertEquals(a.hashCode(), b.hashCode());
|
||||
assertEquals(b.hashCode(), a.hashCode());
|
||||
|
||||
Clock c = Clock.offset(Clock.system(MOSCOW), OFFSET);
|
||||
assertEquals(a.hashCode() == c.hashCode(), false);
|
||||
assertEquals(false, a.hashCode() == c.hashCode());
|
||||
|
||||
Clock d = Clock.offset(Clock.system(PARIS), OFFSET.minusNanos(1));
|
||||
assertEquals(a.hashCode() == d.hashCode(), false);
|
||||
assertEquals(false, a.hashCode() == d.hashCode());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2012, 2013, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2012, 2025, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
@ -59,29 +59,30 @@
|
||||
*/
|
||||
package tck.java.time;
|
||||
|
||||
import static org.testng.Assert.assertEquals;
|
||||
import static org.testng.Assert.fail;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.fail;
|
||||
|
||||
import java.time.Clock;
|
||||
import java.time.Instant;
|
||||
import java.time.ZoneId;
|
||||
import java.time.ZoneOffset;
|
||||
|
||||
import org.testng.annotations.Test;
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
/**
|
||||
* Test system clock.
|
||||
*/
|
||||
@Test
|
||||
public class TCKClock_System extends AbstractTCKTest {
|
||||
|
||||
private static final ZoneId MOSCOW = ZoneId.of("Europe/Moscow");
|
||||
private static final ZoneId PARIS = ZoneId.of("Europe/Paris");
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
@Test
|
||||
public void test_instant() {
|
||||
Clock system = Clock.systemUTC();
|
||||
assertEquals(system.getZone(), ZoneOffset.UTC);
|
||||
assertEquals(ZoneOffset.UTC, system.getZone());
|
||||
for (int i = 0; i < 10000; i++) {
|
||||
// assume can eventually get these within 10 milliseconds
|
||||
Instant instant = system.instant();
|
||||
@ -93,9 +94,10 @@ public class TCKClock_System extends AbstractTCKTest {
|
||||
fail();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test_millis() {
|
||||
Clock system = Clock.systemUTC();
|
||||
assertEquals(system.getZone(), ZoneOffset.UTC);
|
||||
assertEquals(ZoneOffset.UTC, system.getZone());
|
||||
for (int i = 0; i < 10000; i++) {
|
||||
// assume can eventually get these within 10 milliseconds
|
||||
long instant = system.millis();
|
||||
@ -108,85 +110,93 @@ public class TCKClock_System extends AbstractTCKTest {
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------------
|
||||
@Test
|
||||
public void test_systemUTC() {
|
||||
Clock test = Clock.systemUTC();
|
||||
assertEquals(test.getZone(), ZoneOffset.UTC);
|
||||
assertEquals(test, Clock.system(ZoneOffset.UTC));
|
||||
assertEquals(ZoneOffset.UTC, test.getZone());
|
||||
assertEquals(Clock.system(ZoneOffset.UTC), test);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test_systemDefaultZone() {
|
||||
Clock test = Clock.systemDefaultZone();
|
||||
assertEquals(test.getZone(), ZoneId.systemDefault());
|
||||
assertEquals(test, Clock.system(ZoneId.systemDefault()));
|
||||
assertEquals(ZoneId.systemDefault(), test.getZone());
|
||||
assertEquals(Clock.system(ZoneId.systemDefault()), test);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test_system_ZoneId() {
|
||||
Clock test = Clock.system(PARIS);
|
||||
assertEquals(test.getZone(), PARIS);
|
||||
assertEquals(PARIS, test.getZone());
|
||||
}
|
||||
|
||||
@Test(expectedExceptions = NullPointerException.class)
|
||||
@Test
|
||||
public void test_zoneId_nullZoneId() {
|
||||
Clock.system(null);
|
||||
Assertions.assertThrows(NullPointerException.class, () -> Clock.system(null));
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------------
|
||||
@Test
|
||||
public void test_withZone() {
|
||||
Clock test = Clock.system(PARIS);
|
||||
Clock changed = test.withZone(MOSCOW);
|
||||
assertEquals(test.getZone(), PARIS);
|
||||
assertEquals(changed.getZone(), MOSCOW);
|
||||
assertEquals(PARIS, test.getZone());
|
||||
assertEquals(MOSCOW, changed.getZone());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test_withZone_equal() {
|
||||
Clock test = Clock.system(PARIS);
|
||||
Clock changed = test.withZone(PARIS);
|
||||
assertEquals(changed.getZone(), PARIS);
|
||||
assertEquals(PARIS, changed.getZone());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test_withZone_fromUTC() {
|
||||
Clock test = Clock.systemUTC();
|
||||
Clock changed = test.withZone(PARIS);
|
||||
assertEquals(changed.getZone(), PARIS);
|
||||
assertEquals(PARIS, changed.getZone());
|
||||
}
|
||||
|
||||
@Test(expectedExceptions = NullPointerException.class)
|
||||
@Test
|
||||
public void test_withZone_null() {
|
||||
Clock.systemUTC().withZone(null);
|
||||
Assertions.assertThrows(NullPointerException.class, () -> Clock.systemUTC().withZone(null));
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
@Test
|
||||
public void test_equals() {
|
||||
Clock a = Clock.systemUTC();
|
||||
Clock b = Clock.systemUTC();
|
||||
assertEquals(a.equals(a), true);
|
||||
assertEquals(a.equals(b), true);
|
||||
assertEquals(b.equals(a), true);
|
||||
assertEquals(b.equals(b), true);
|
||||
assertEquals(true, a.equals(a));
|
||||
assertEquals(true, a.equals(b));
|
||||
assertEquals(true, b.equals(a));
|
||||
assertEquals(true, b.equals(b));
|
||||
|
||||
Clock c = Clock.system(PARIS);
|
||||
Clock d = Clock.system(PARIS);
|
||||
assertEquals(c.equals(c), true);
|
||||
assertEquals(c.equals(d), true);
|
||||
assertEquals(d.equals(c), true);
|
||||
assertEquals(d.equals(d), true);
|
||||
assertEquals(true, c.equals(c));
|
||||
assertEquals(true, c.equals(d));
|
||||
assertEquals(true, d.equals(c));
|
||||
assertEquals(true, d.equals(d));
|
||||
|
||||
assertEquals(a.equals(c), false);
|
||||
assertEquals(c.equals(a), false);
|
||||
assertEquals(false, a.equals(c));
|
||||
assertEquals(false, c.equals(a));
|
||||
|
||||
assertEquals(a.equals(null), false);
|
||||
assertEquals(a.equals("other type"), false);
|
||||
assertEquals(a.equals(Clock.fixed(Instant.now(), ZoneOffset.UTC)), false);
|
||||
assertEquals(false, a.equals(null));
|
||||
assertEquals(false, a.equals("other type"));
|
||||
assertEquals(false, a.equals(Clock.fixed(Instant.now(), ZoneOffset.UTC)));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test_hashCode() {
|
||||
Clock a = Clock.system(ZoneOffset.UTC);
|
||||
Clock b = Clock.system(ZoneOffset.UTC);
|
||||
assertEquals(a.hashCode(), a.hashCode());
|
||||
assertEquals(a.hashCode(), b.hashCode());
|
||||
assertEquals(b.hashCode(), a.hashCode());
|
||||
|
||||
Clock c = Clock.system(PARIS);
|
||||
assertEquals(a.hashCode() == c.hashCode(), false);
|
||||
assertEquals(false, a.hashCode() == c.hashCode());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2012, 2015, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2012, 2025, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
@ -59,8 +59,8 @@
|
||||
*/
|
||||
package tck.java.time;
|
||||
|
||||
import static org.testng.Assert.assertEquals;
|
||||
import static org.testng.Assert.assertSame;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertSame;
|
||||
|
||||
import java.time.Clock;
|
||||
import java.time.Duration;
|
||||
@ -70,12 +70,12 @@ import java.time.ZoneId;
|
||||
import java.time.ZoneOffset;
|
||||
import java.time.ZonedDateTime;
|
||||
|
||||
import org.testng.annotations.Test;
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
/**
|
||||
* Test tick clock.
|
||||
*/
|
||||
@Test
|
||||
public class TCKClock_Tick extends AbstractTCKTest {
|
||||
|
||||
private static final ZoneId MOSCOW = ZoneId.of("Europe/Moscow");
|
||||
@ -83,170 +83,182 @@ public class TCKClock_Tick extends AbstractTCKTest {
|
||||
private static final ZonedDateTime ZDT = LocalDateTime.of(2008, 6, 30, 11, 30, 10, 500).atZone(ZoneOffset.ofHours(2));
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
@Test
|
||||
public void test_tick_ClockDuration_250millis() {
|
||||
for (int i = 0; i < 1000; i++) {
|
||||
Clock test = Clock.tick(Clock.fixed(ZDT.withNano(i * 1000_000).toInstant(), PARIS), Duration.ofMillis(250));
|
||||
assertEquals(test.instant(), ZDT.withNano((i / 250) * 250_000_000).toInstant());
|
||||
assertEquals(test.getZone(), PARIS);
|
||||
assertEquals(ZDT.withNano((i / 250) * 250_000_000).toInstant(), test.instant());
|
||||
assertEquals(PARIS, test.getZone());
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test_tick_ClockDuration_250micros() {
|
||||
for (int i = 0; i < 1000; i++) {
|
||||
Clock test = Clock.tick(Clock.fixed(ZDT.withNano(i * 1000).toInstant(), PARIS), Duration.ofNanos(250_000));
|
||||
assertEquals(test.instant(), ZDT.withNano((i / 250) * 250_000).toInstant());
|
||||
assertEquals(test.getZone(), PARIS);
|
||||
assertEquals(ZDT.withNano((i / 250) * 250_000).toInstant(), test.instant());
|
||||
assertEquals(PARIS, test.getZone());
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test_tick_ClockDuration_20nanos() {
|
||||
for (int i = 0; i < 1000; i++) {
|
||||
Clock test = Clock.tick(Clock.fixed(ZDT.withNano(i).toInstant(), PARIS), Duration.ofNanos(20));
|
||||
assertEquals(test.instant(), ZDT.withNano((i / 20) * 20).toInstant());
|
||||
assertEquals(test.getZone(), PARIS);
|
||||
assertEquals(ZDT.withNano((i / 20) * 20).toInstant(), test.instant());
|
||||
assertEquals(PARIS, test.getZone());
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test_tick_ClockDuration_zeroDuration() {
|
||||
Clock underlying = Clock.system(PARIS);
|
||||
Clock test = Clock.tick(underlying, Duration.ZERO);
|
||||
assertSame(test, underlying); // spec says same
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test_tick_ClockDuration_1nsDuration() {
|
||||
Clock underlying = Clock.system(PARIS);
|
||||
Clock test = Clock.tick(underlying, Duration.ofNanos(1));
|
||||
assertSame(test, underlying); // spec says same
|
||||
}
|
||||
|
||||
@Test(expectedExceptions = ArithmeticException.class)
|
||||
@Test
|
||||
public void test_tick_ClockDuration_maxDuration() {
|
||||
Clock.tick(Clock.systemUTC(), Duration.ofSeconds(Long.MAX_VALUE));
|
||||
Assertions.assertThrows(ArithmeticException.class, () -> Clock.tick(Clock.systemUTC(), Duration.ofSeconds(Long.MAX_VALUE)));
|
||||
}
|
||||
|
||||
@Test(expectedExceptions = IllegalArgumentException.class)
|
||||
@Test
|
||||
public void test_tick_ClockDuration_subMilliNotDivisible_123ns() {
|
||||
Clock.tick(Clock.systemUTC(), Duration.ofSeconds(0, 123));
|
||||
Assertions.assertThrows(IllegalArgumentException.class, () -> Clock.tick(Clock.systemUTC(), Duration.ofSeconds(0, 123)));
|
||||
}
|
||||
|
||||
@Test(expectedExceptions = IllegalArgumentException.class)
|
||||
@Test
|
||||
public void test_tick_ClockDuration_subMilliNotDivisible_999ns() {
|
||||
Clock.tick(Clock.systemUTC(), Duration.ofSeconds(0, 999));
|
||||
Assertions.assertThrows(IllegalArgumentException.class, () -> Clock.tick(Clock.systemUTC(), Duration.ofSeconds(0, 999)));
|
||||
}
|
||||
|
||||
@Test(expectedExceptions = IllegalArgumentException.class)
|
||||
@Test
|
||||
public void test_tick_ClockDuration_subMilliNotDivisible_999_999_999ns() {
|
||||
Clock.tick(Clock.systemUTC(), Duration.ofSeconds(0, 999_999_999));
|
||||
Assertions.assertThrows(IllegalArgumentException.class, () -> Clock.tick(Clock.systemUTC(), Duration.ofSeconds(0, 999_999_999)));
|
||||
}
|
||||
|
||||
@Test(expectedExceptions = IllegalArgumentException.class)
|
||||
@Test
|
||||
public void test_tick_ClockDuration_negative1ns() {
|
||||
Clock.tick(Clock.systemUTC(), Duration.ofSeconds(0, -1));
|
||||
Assertions.assertThrows(IllegalArgumentException.class, () -> Clock.tick(Clock.systemUTC(), Duration.ofSeconds(0, -1)));
|
||||
}
|
||||
|
||||
@Test(expectedExceptions = IllegalArgumentException.class)
|
||||
@Test
|
||||
public void test_tick_ClockDuration_negative1s() {
|
||||
Clock.tick(Clock.systemUTC(), Duration.ofSeconds(-1));
|
||||
Assertions.assertThrows(IllegalArgumentException.class, () -> Clock.tick(Clock.systemUTC(), Duration.ofSeconds(-1)));
|
||||
}
|
||||
|
||||
@Test(expectedExceptions = NullPointerException.class)
|
||||
@Test
|
||||
public void test_tick_ClockDuration_nullClock() {
|
||||
Clock.tick(null, Duration.ZERO);
|
||||
Assertions.assertThrows(NullPointerException.class, () -> Clock.tick(null, Duration.ZERO));
|
||||
}
|
||||
|
||||
@Test(expectedExceptions = NullPointerException.class)
|
||||
@Test
|
||||
public void test_tick_ClockDuration_nullDuration() {
|
||||
Clock.tick(Clock.systemUTC(), null);
|
||||
Assertions.assertThrows(NullPointerException.class, () -> Clock.tick(Clock.systemUTC(), null));
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
@Test
|
||||
public void test_tickMillis_ZoneId() throws Exception {
|
||||
Clock test = Clock.tickMillis(PARIS);
|
||||
assertEquals(test.getZone(), PARIS);
|
||||
assertEquals(test.instant().getNano() % 1000_000, 0);
|
||||
assertEquals(PARIS, test.getZone());
|
||||
assertEquals(0, test.instant().getNano() % 1000_000);
|
||||
}
|
||||
|
||||
@Test(expectedExceptions = NullPointerException.class)
|
||||
@Test
|
||||
public void test_tickMillis_ZoneId_nullZoneId() {
|
||||
Clock.tickMillis(null);
|
||||
Assertions.assertThrows(NullPointerException.class, () -> Clock.tickMillis(null));
|
||||
}
|
||||
//-----------------------------------------------------------------------
|
||||
@Test
|
||||
public void test_tickSeconds_ZoneId() throws Exception {
|
||||
Clock test = Clock.tickSeconds(PARIS);
|
||||
assertEquals(test.getZone(), PARIS);
|
||||
assertEquals(test.instant().getNano(), 0);
|
||||
assertEquals(PARIS, test.getZone());
|
||||
assertEquals(0, test.instant().getNano());
|
||||
Thread.sleep(100);
|
||||
assertEquals(test.instant().getNano(), 0);
|
||||
assertEquals(0, test.instant().getNano());
|
||||
}
|
||||
|
||||
@Test(expectedExceptions = NullPointerException.class)
|
||||
@Test
|
||||
public void test_tickSeconds_ZoneId_nullZoneId() {
|
||||
Clock.tickSeconds(null);
|
||||
Assertions.assertThrows(NullPointerException.class, () -> Clock.tickSeconds(null));
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
@Test
|
||||
public void test_tickMinutes_ZoneId() {
|
||||
Clock test = Clock.tickMinutes(PARIS);
|
||||
assertEquals(test.getZone(), PARIS);
|
||||
assertEquals(PARIS, test.getZone());
|
||||
Instant instant = test.instant();
|
||||
assertEquals(instant.getEpochSecond() % 60, 0);
|
||||
assertEquals(instant.getNano(), 0);
|
||||
assertEquals(0, instant.getEpochSecond() % 60);
|
||||
assertEquals(0, instant.getNano());
|
||||
}
|
||||
|
||||
@Test(expectedExceptions = NullPointerException.class)
|
||||
@Test
|
||||
public void test_tickMinutes_ZoneId_nullZoneId() {
|
||||
Clock.tickMinutes(null);
|
||||
Assertions.assertThrows(NullPointerException.class, () -> Clock.tickMinutes(null));
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------------
|
||||
@Test
|
||||
public void test_withZone() {
|
||||
Clock test = Clock.tick(Clock.system(PARIS), Duration.ofMillis(500));
|
||||
Clock changed = test.withZone(MOSCOW);
|
||||
assertEquals(test.getZone(), PARIS);
|
||||
assertEquals(changed.getZone(), MOSCOW);
|
||||
assertEquals(PARIS, test.getZone());
|
||||
assertEquals(MOSCOW, changed.getZone());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test_withZone_equal() {
|
||||
Clock test = Clock.tick(Clock.system(PARIS), Duration.ofMillis(500));
|
||||
Clock changed = test.withZone(PARIS);
|
||||
assertEquals(test, changed);
|
||||
assertEquals(changed, test);
|
||||
}
|
||||
|
||||
@Test(expectedExceptions = NullPointerException.class)
|
||||
@Test
|
||||
public void test_withZone_null() {
|
||||
Clock.tick(Clock.system(PARIS), Duration.ofMillis(500)).withZone(null);
|
||||
Assertions.assertThrows(NullPointerException.class, () -> Clock.tick(Clock.system(PARIS), Duration.ofMillis(500)).withZone(null));
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
@Test
|
||||
public void test__equals() {
|
||||
Clock a = Clock.tick(Clock.system(PARIS), Duration.ofMillis(500));
|
||||
Clock b = Clock.tick(Clock.system(PARIS), Duration.ofMillis(500));
|
||||
assertEquals(a.equals(a), true);
|
||||
assertEquals(a.equals(b), true);
|
||||
assertEquals(b.equals(a), true);
|
||||
assertEquals(b.equals(b), true);
|
||||
assertEquals(true, a.equals(a));
|
||||
assertEquals(true, a.equals(b));
|
||||
assertEquals(true, b.equals(a));
|
||||
assertEquals(true, b.equals(b));
|
||||
|
||||
Clock c = Clock.tick(Clock.system(MOSCOW), Duration.ofMillis(500));
|
||||
assertEquals(a.equals(c), false);
|
||||
assertEquals(false, a.equals(c));
|
||||
|
||||
Clock d = Clock.tick(Clock.system(PARIS), Duration.ofMillis(499));
|
||||
assertEquals(a.equals(d), false);
|
||||
assertEquals(false, a.equals(d));
|
||||
|
||||
assertEquals(a.equals(null), false);
|
||||
assertEquals(a.equals("other type"), false);
|
||||
assertEquals(a.equals(Clock.systemUTC()), false);
|
||||
assertEquals(false, a.equals(null));
|
||||
assertEquals(false, a.equals("other type"));
|
||||
assertEquals(false, a.equals(Clock.systemUTC()));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test_hashCode() {
|
||||
Clock a = Clock.tick(Clock.system(PARIS), Duration.ofMillis(500));
|
||||
Clock b = Clock.tick(Clock.system(PARIS), Duration.ofMillis(500));
|
||||
assertEquals(a.hashCode(), a.hashCode());
|
||||
assertEquals(a.hashCode(), b.hashCode());
|
||||
assertEquals(b.hashCode(), a.hashCode());
|
||||
|
||||
Clock c = Clock.tick(Clock.system(MOSCOW), Duration.ofMillis(500));
|
||||
assertEquals(a.hashCode() == c.hashCode(), false);
|
||||
assertEquals(false, a.hashCode() == c.hashCode());
|
||||
|
||||
Clock d = Clock.tick(Clock.system(PARIS), Duration.ofMillis(499));
|
||||
assertEquals(a.hashCode() == d.hashCode(), false);
|
||||
assertEquals(false, a.hashCode() == d.hashCode());
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2012, 2013, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2012, 2025, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
@ -63,8 +63,9 @@ import static java.time.DayOfWeek.MONDAY;
|
||||
import static java.time.DayOfWeek.SUNDAY;
|
||||
import static java.time.DayOfWeek.WEDNESDAY;
|
||||
import static java.time.temporal.ChronoField.DAY_OF_WEEK;
|
||||
import static org.testng.Assert.assertEquals;
|
||||
import static org.testng.Assert.assertSame;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertSame;
|
||||
|
||||
import java.time.DateTimeException;
|
||||
import java.time.DayOfWeek;
|
||||
@ -84,17 +85,20 @@ import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
|
||||
import org.testng.annotations.BeforeMethod;
|
||||
import org.testng.annotations.DataProvider;
|
||||
import org.testng.annotations.Test;
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.TestInstance;
|
||||
import org.junit.jupiter.params.ParameterizedTest;
|
||||
import org.junit.jupiter.params.provider.MethodSource;
|
||||
|
||||
/**
|
||||
* Test DayOfWeek.
|
||||
*/
|
||||
@Test
|
||||
@TestInstance(TestInstance.Lifecycle.PER_CLASS)
|
||||
public class TCKDayOfWeek extends AbstractDateTimeTest {
|
||||
|
||||
@BeforeMethod
|
||||
@BeforeEach
|
||||
public void setUp() {
|
||||
}
|
||||
|
||||
@ -128,35 +132,35 @@ public class TCKDayOfWeek extends AbstractDateTimeTest {
|
||||
public void test_factory_int_singleton() {
|
||||
for (int i = 1; i <= 7; i++) {
|
||||
DayOfWeek test = DayOfWeek.of(i);
|
||||
assertEquals(test.getValue(), i);
|
||||
assertEquals(i, test.getValue());
|
||||
assertSame(DayOfWeek.of(i), test);
|
||||
}
|
||||
}
|
||||
|
||||
@Test(expectedExceptions=DateTimeException.class)
|
||||
@Test
|
||||
public void test_factory_int_valueTooLow() {
|
||||
DayOfWeek.of(0);
|
||||
Assertions.assertThrows(DateTimeException.class, () -> DayOfWeek.of(0));
|
||||
}
|
||||
|
||||
@Test(expectedExceptions=DateTimeException.class)
|
||||
@Test
|
||||
public void test_factory_int_valueTooHigh() {
|
||||
DayOfWeek.of(8);
|
||||
Assertions.assertThrows(DateTimeException.class, () -> DayOfWeek.of(8));
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
@Test
|
||||
public void test_factory_CalendricalObject() {
|
||||
assertEquals(DayOfWeek.from(LocalDate.of(2011, 6, 6)), DayOfWeek.MONDAY);
|
||||
assertEquals(DayOfWeek.MONDAY, DayOfWeek.from(LocalDate.of(2011, 6, 6)));
|
||||
}
|
||||
|
||||
@Test(expectedExceptions=DateTimeException.class)
|
||||
@Test
|
||||
public void test_factory_CalendricalObject_invalid_noDerive() {
|
||||
DayOfWeek.from(LocalTime.of(12, 30));
|
||||
Assertions.assertThrows(DateTimeException.class, () -> DayOfWeek.from(LocalTime.of(12, 30)));
|
||||
}
|
||||
|
||||
@Test(expectedExceptions=NullPointerException.class)
|
||||
@Test
|
||||
public void test_factory_CalendricalObject_null() {
|
||||
DayOfWeek.from((TemporalAccessor) null);
|
||||
Assertions.assertThrows(NullPointerException.class, () -> DayOfWeek.from((TemporalAccessor) null));
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
@ -164,37 +168,37 @@ public class TCKDayOfWeek extends AbstractDateTimeTest {
|
||||
//-----------------------------------------------------------------------
|
||||
@Test
|
||||
public void test_isSupported_TemporalField() {
|
||||
assertEquals(DayOfWeek.THURSDAY.isSupported((TemporalField) null), false);
|
||||
assertEquals(DayOfWeek.THURSDAY.isSupported(ChronoField.NANO_OF_SECOND), false);
|
||||
assertEquals(DayOfWeek.THURSDAY.isSupported(ChronoField.NANO_OF_DAY), false);
|
||||
assertEquals(DayOfWeek.THURSDAY.isSupported(ChronoField.MICRO_OF_SECOND), false);
|
||||
assertEquals(DayOfWeek.THURSDAY.isSupported(ChronoField.MICRO_OF_DAY), false);
|
||||
assertEquals(DayOfWeek.THURSDAY.isSupported(ChronoField.MILLI_OF_SECOND), false);
|
||||
assertEquals(DayOfWeek.THURSDAY.isSupported(ChronoField.MILLI_OF_DAY), false);
|
||||
assertEquals(DayOfWeek.THURSDAY.isSupported(ChronoField.SECOND_OF_MINUTE), false);
|
||||
assertEquals(DayOfWeek.THURSDAY.isSupported(ChronoField.SECOND_OF_DAY), false);
|
||||
assertEquals(DayOfWeek.THURSDAY.isSupported(ChronoField.MINUTE_OF_HOUR), false);
|
||||
assertEquals(DayOfWeek.THURSDAY.isSupported(ChronoField.MINUTE_OF_DAY), false);
|
||||
assertEquals(DayOfWeek.THURSDAY.isSupported(ChronoField.HOUR_OF_AMPM), false);
|
||||
assertEquals(DayOfWeek.THURSDAY.isSupported(ChronoField.CLOCK_HOUR_OF_AMPM), false);
|
||||
assertEquals(DayOfWeek.THURSDAY.isSupported(ChronoField.HOUR_OF_DAY), false);
|
||||
assertEquals(DayOfWeek.THURSDAY.isSupported(ChronoField.CLOCK_HOUR_OF_DAY), false);
|
||||
assertEquals(DayOfWeek.THURSDAY.isSupported(ChronoField.AMPM_OF_DAY), false);
|
||||
assertEquals(DayOfWeek.THURSDAY.isSupported(ChronoField.DAY_OF_WEEK), true);
|
||||
assertEquals(DayOfWeek.THURSDAY.isSupported(ChronoField.ALIGNED_DAY_OF_WEEK_IN_MONTH), false);
|
||||
assertEquals(DayOfWeek.THURSDAY.isSupported(ChronoField.ALIGNED_DAY_OF_WEEK_IN_YEAR), false);
|
||||
assertEquals(DayOfWeek.THURSDAY.isSupported(ChronoField.DAY_OF_MONTH), false);
|
||||
assertEquals(DayOfWeek.THURSDAY.isSupported(ChronoField.DAY_OF_YEAR), false);
|
||||
assertEquals(DayOfWeek.THURSDAY.isSupported(ChronoField.EPOCH_DAY), false);
|
||||
assertEquals(DayOfWeek.THURSDAY.isSupported(ChronoField.ALIGNED_WEEK_OF_MONTH), false);
|
||||
assertEquals(DayOfWeek.THURSDAY.isSupported(ChronoField.ALIGNED_WEEK_OF_YEAR), false);
|
||||
assertEquals(DayOfWeek.THURSDAY.isSupported(ChronoField.MONTH_OF_YEAR), false);
|
||||
assertEquals(DayOfWeek.THURSDAY.isSupported(ChronoField.PROLEPTIC_MONTH), false);
|
||||
assertEquals(DayOfWeek.THURSDAY.isSupported(ChronoField.YEAR), false);
|
||||
assertEquals(DayOfWeek.THURSDAY.isSupported(ChronoField.YEAR_OF_ERA), false);
|
||||
assertEquals(DayOfWeek.THURSDAY.isSupported(ChronoField.ERA), false);
|
||||
assertEquals(DayOfWeek.THURSDAY.isSupported(ChronoField.INSTANT_SECONDS), false);
|
||||
assertEquals(DayOfWeek.THURSDAY.isSupported(ChronoField.OFFSET_SECONDS), false);
|
||||
assertEquals(false, DayOfWeek.THURSDAY.isSupported((TemporalField) null));
|
||||
assertEquals(false, DayOfWeek.THURSDAY.isSupported(ChronoField.NANO_OF_SECOND));
|
||||
assertEquals(false, DayOfWeek.THURSDAY.isSupported(ChronoField.NANO_OF_DAY));
|
||||
assertEquals(false, DayOfWeek.THURSDAY.isSupported(ChronoField.MICRO_OF_SECOND));
|
||||
assertEquals(false, DayOfWeek.THURSDAY.isSupported(ChronoField.MICRO_OF_DAY));
|
||||
assertEquals(false, DayOfWeek.THURSDAY.isSupported(ChronoField.MILLI_OF_SECOND));
|
||||
assertEquals(false, DayOfWeek.THURSDAY.isSupported(ChronoField.MILLI_OF_DAY));
|
||||
assertEquals(false, DayOfWeek.THURSDAY.isSupported(ChronoField.SECOND_OF_MINUTE));
|
||||
assertEquals(false, DayOfWeek.THURSDAY.isSupported(ChronoField.SECOND_OF_DAY));
|
||||
assertEquals(false, DayOfWeek.THURSDAY.isSupported(ChronoField.MINUTE_OF_HOUR));
|
||||
assertEquals(false, DayOfWeek.THURSDAY.isSupported(ChronoField.MINUTE_OF_DAY));
|
||||
assertEquals(false, DayOfWeek.THURSDAY.isSupported(ChronoField.HOUR_OF_AMPM));
|
||||
assertEquals(false, DayOfWeek.THURSDAY.isSupported(ChronoField.CLOCK_HOUR_OF_AMPM));
|
||||
assertEquals(false, DayOfWeek.THURSDAY.isSupported(ChronoField.HOUR_OF_DAY));
|
||||
assertEquals(false, DayOfWeek.THURSDAY.isSupported(ChronoField.CLOCK_HOUR_OF_DAY));
|
||||
assertEquals(false, DayOfWeek.THURSDAY.isSupported(ChronoField.AMPM_OF_DAY));
|
||||
assertEquals(true, DayOfWeek.THURSDAY.isSupported(ChronoField.DAY_OF_WEEK));
|
||||
assertEquals(false, DayOfWeek.THURSDAY.isSupported(ChronoField.ALIGNED_DAY_OF_WEEK_IN_MONTH));
|
||||
assertEquals(false, DayOfWeek.THURSDAY.isSupported(ChronoField.ALIGNED_DAY_OF_WEEK_IN_YEAR));
|
||||
assertEquals(false, DayOfWeek.THURSDAY.isSupported(ChronoField.DAY_OF_MONTH));
|
||||
assertEquals(false, DayOfWeek.THURSDAY.isSupported(ChronoField.DAY_OF_YEAR));
|
||||
assertEquals(false, DayOfWeek.THURSDAY.isSupported(ChronoField.EPOCH_DAY));
|
||||
assertEquals(false, DayOfWeek.THURSDAY.isSupported(ChronoField.ALIGNED_WEEK_OF_MONTH));
|
||||
assertEquals(false, DayOfWeek.THURSDAY.isSupported(ChronoField.ALIGNED_WEEK_OF_YEAR));
|
||||
assertEquals(false, DayOfWeek.THURSDAY.isSupported(ChronoField.MONTH_OF_YEAR));
|
||||
assertEquals(false, DayOfWeek.THURSDAY.isSupported(ChronoField.PROLEPTIC_MONTH));
|
||||
assertEquals(false, DayOfWeek.THURSDAY.isSupported(ChronoField.YEAR));
|
||||
assertEquals(false, DayOfWeek.THURSDAY.isSupported(ChronoField.YEAR_OF_ERA));
|
||||
assertEquals(false, DayOfWeek.THURSDAY.isSupported(ChronoField.ERA));
|
||||
assertEquals(false, DayOfWeek.THURSDAY.isSupported(ChronoField.INSTANT_SECONDS));
|
||||
assertEquals(false, DayOfWeek.THURSDAY.isSupported(ChronoField.OFFSET_SECONDS));
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
@ -202,18 +206,17 @@ public class TCKDayOfWeek extends AbstractDateTimeTest {
|
||||
//-----------------------------------------------------------------------
|
||||
@Test
|
||||
public void test_get_TemporalField() {
|
||||
assertEquals(DayOfWeek.WEDNESDAY.getLong(ChronoField.DAY_OF_WEEK), 3);
|
||||
assertEquals(3, DayOfWeek.WEDNESDAY.getLong(ChronoField.DAY_OF_WEEK));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test_getLong_TemporalField() {
|
||||
assertEquals(DayOfWeek.WEDNESDAY.getLong(ChronoField.DAY_OF_WEEK), 3);
|
||||
assertEquals(3, DayOfWeek.WEDNESDAY.getLong(ChronoField.DAY_OF_WEEK));
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
// query(TemporalQuery)
|
||||
//-----------------------------------------------------------------------
|
||||
@DataProvider(name="query")
|
||||
Object[][] data_query() {
|
||||
return new Object[][] {
|
||||
{DayOfWeek.FRIDAY, TemporalQueries.chronology(), null},
|
||||
@ -226,19 +229,21 @@ public class TCKDayOfWeek extends AbstractDateTimeTest {
|
||||
};
|
||||
}
|
||||
|
||||
@Test(dataProvider="query")
|
||||
@ParameterizedTest
|
||||
@MethodSource("data_query")
|
||||
public <T> void test_query(TemporalAccessor temporal, TemporalQuery<T> query, T expected) {
|
||||
assertEquals(temporal.query(query), expected);
|
||||
assertEquals(expected, temporal.query(query));
|
||||
}
|
||||
|
||||
@Test(dataProvider="query")
|
||||
@ParameterizedTest
|
||||
@MethodSource("data_query")
|
||||
public <T> void test_queryFrom(TemporalAccessor temporal, TemporalQuery<T> query, T expected) {
|
||||
assertEquals(query.queryFrom(temporal), expected);
|
||||
assertEquals(expected, query.queryFrom(temporal));
|
||||
}
|
||||
|
||||
@Test(expectedExceptions=NullPointerException.class)
|
||||
@Test
|
||||
public void test_query_null() {
|
||||
DayOfWeek.FRIDAY.query(null);
|
||||
Assertions.assertThrows(NullPointerException.class, () -> DayOfWeek.FRIDAY.query(null));
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
@ -246,23 +251,22 @@ public class TCKDayOfWeek extends AbstractDateTimeTest {
|
||||
//-----------------------------------------------------------------------
|
||||
@Test
|
||||
public void test_getText() {
|
||||
assertEquals(DayOfWeek.MONDAY.getDisplayName(TextStyle.SHORT, Locale.US), "Mon");
|
||||
assertEquals("Mon", DayOfWeek.MONDAY.getDisplayName(TextStyle.SHORT, Locale.US));
|
||||
}
|
||||
|
||||
@Test(expectedExceptions = NullPointerException.class)
|
||||
@Test
|
||||
public void test_getText_nullStyle() {
|
||||
DayOfWeek.MONDAY.getDisplayName(null, Locale.US);
|
||||
Assertions.assertThrows(NullPointerException.class, () -> DayOfWeek.MONDAY.getDisplayName(null, Locale.US));
|
||||
}
|
||||
|
||||
@Test(expectedExceptions = NullPointerException.class)
|
||||
@Test
|
||||
public void test_getText_nullLocale() {
|
||||
DayOfWeek.MONDAY.getDisplayName(TextStyle.FULL, null);
|
||||
Assertions.assertThrows(NullPointerException.class, () -> DayOfWeek.MONDAY.getDisplayName(TextStyle.FULL, null));
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
// plus(long), plus(long,unit)
|
||||
//-----------------------------------------------------------------------
|
||||
@DataProvider(name="plus")
|
||||
Object[][] data_plus() {
|
||||
return new Object[][] {
|
||||
{1, -8, 7},
|
||||
@ -301,15 +305,15 @@ public class TCKDayOfWeek extends AbstractDateTimeTest {
|
||||
};
|
||||
}
|
||||
|
||||
@Test(dataProvider="plus")
|
||||
@ParameterizedTest
|
||||
@MethodSource("data_plus")
|
||||
public void test_plus_long(int base, long amount, int expected) {
|
||||
assertEquals(DayOfWeek.of(base).plus(amount), DayOfWeek.of(expected));
|
||||
assertEquals(DayOfWeek.of(expected), DayOfWeek.of(base).plus(amount));
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
// minus(long), minus(long,unit)
|
||||
//-----------------------------------------------------------------------
|
||||
@DataProvider(name="minus")
|
||||
Object[][] data_minus() {
|
||||
return new Object[][] {
|
||||
{1, -8, 2},
|
||||
@ -332,9 +336,10 @@ public class TCKDayOfWeek extends AbstractDateTimeTest {
|
||||
};
|
||||
}
|
||||
|
||||
@Test(dataProvider="minus")
|
||||
@ParameterizedTest
|
||||
@MethodSource("data_minus")
|
||||
public void test_minus_long(int base, long amount, int expected) {
|
||||
assertEquals(DayOfWeek.of(base).minus(amount), DayOfWeek.of(expected));
|
||||
assertEquals(DayOfWeek.of(expected), DayOfWeek.of(base).minus(amount));
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
@ -342,16 +347,16 @@ public class TCKDayOfWeek extends AbstractDateTimeTest {
|
||||
//-----------------------------------------------------------------------
|
||||
@Test
|
||||
public void test_adjustInto() {
|
||||
assertEquals(DayOfWeek.MONDAY.adjustInto(LocalDate.of(2012, 9, 2)), LocalDate.of(2012, 8, 27));
|
||||
assertEquals(DayOfWeek.MONDAY.adjustInto(LocalDate.of(2012, 9, 3)), LocalDate.of(2012, 9, 3));
|
||||
assertEquals(DayOfWeek.MONDAY.adjustInto(LocalDate.of(2012, 9, 4)), LocalDate.of(2012, 9, 3));
|
||||
assertEquals(DayOfWeek.MONDAY.adjustInto(LocalDate.of(2012, 9, 10)), LocalDate.of(2012, 9, 10));
|
||||
assertEquals(DayOfWeek.MONDAY.adjustInto(LocalDate.of(2012, 9, 11)), LocalDate.of(2012, 9, 10));
|
||||
assertEquals(LocalDate.of(2012, 8, 27), DayOfWeek.MONDAY.adjustInto(LocalDate.of(2012, 9, 2)));
|
||||
assertEquals(LocalDate.of(2012, 9, 3), DayOfWeek.MONDAY.adjustInto(LocalDate.of(2012, 9, 3)));
|
||||
assertEquals(LocalDate.of(2012, 9, 3), DayOfWeek.MONDAY.adjustInto(LocalDate.of(2012, 9, 4)));
|
||||
assertEquals(LocalDate.of(2012, 9, 10), DayOfWeek.MONDAY.adjustInto(LocalDate.of(2012, 9, 10)));
|
||||
assertEquals(LocalDate.of(2012, 9, 10), DayOfWeek.MONDAY.adjustInto(LocalDate.of(2012, 9, 11)));
|
||||
}
|
||||
|
||||
@Test(expectedExceptions=NullPointerException.class)
|
||||
@Test
|
||||
public void test_adjustInto_null() {
|
||||
DayOfWeek.MONDAY.adjustInto((Temporal) null);
|
||||
Assertions.assertThrows(NullPointerException.class, () -> DayOfWeek.MONDAY.adjustInto((Temporal) null));
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
@ -359,13 +364,13 @@ public class TCKDayOfWeek extends AbstractDateTimeTest {
|
||||
//-----------------------------------------------------------------------
|
||||
@Test
|
||||
public void test_toString() {
|
||||
assertEquals(DayOfWeek.MONDAY.toString(), "MONDAY");
|
||||
assertEquals(DayOfWeek.TUESDAY.toString(), "TUESDAY");
|
||||
assertEquals(DayOfWeek.WEDNESDAY.toString(), "WEDNESDAY");
|
||||
assertEquals(DayOfWeek.THURSDAY.toString(), "THURSDAY");
|
||||
assertEquals(DayOfWeek.FRIDAY.toString(), "FRIDAY");
|
||||
assertEquals(DayOfWeek.SATURDAY.toString(), "SATURDAY");
|
||||
assertEquals(DayOfWeek.SUNDAY.toString(), "SUNDAY");
|
||||
assertEquals("MONDAY", DayOfWeek.MONDAY.toString());
|
||||
assertEquals("TUESDAY", DayOfWeek.TUESDAY.toString());
|
||||
assertEquals("WEDNESDAY", DayOfWeek.WEDNESDAY.toString());
|
||||
assertEquals("THURSDAY", DayOfWeek.THURSDAY.toString());
|
||||
assertEquals("FRIDAY", DayOfWeek.FRIDAY.toString());
|
||||
assertEquals("SATURDAY", DayOfWeek.SATURDAY.toString());
|
||||
assertEquals("SUNDAY", DayOfWeek.SUNDAY.toString());
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
@ -373,8 +378,8 @@ public class TCKDayOfWeek extends AbstractDateTimeTest {
|
||||
//-----------------------------------------------------------------------
|
||||
@Test
|
||||
public void test_enum() {
|
||||
assertEquals(DayOfWeek.valueOf("MONDAY"), DayOfWeek.MONDAY);
|
||||
assertEquals(DayOfWeek.values()[0], DayOfWeek.MONDAY);
|
||||
assertEquals(DayOfWeek.MONDAY, DayOfWeek.valueOf("MONDAY"));
|
||||
assertEquals(DayOfWeek.MONDAY, DayOfWeek.values()[0]);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2012, 2013, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2012, 2025, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
@ -60,7 +60,8 @@
|
||||
package tck.java.time;
|
||||
|
||||
import static java.time.temporal.ChronoField.MONTH_OF_YEAR;
|
||||
import static org.testng.Assert.assertEquals;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
|
||||
import java.time.DateTimeException;
|
||||
import java.time.LocalDate;
|
||||
@ -80,13 +81,16 @@ import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
|
||||
import org.testng.annotations.DataProvider;
|
||||
import org.testng.annotations.Test;
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.TestInstance;
|
||||
import org.junit.jupiter.params.ParameterizedTest;
|
||||
import org.junit.jupiter.params.provider.MethodSource;
|
||||
|
||||
/**
|
||||
* Test Month.
|
||||
*/
|
||||
@Test
|
||||
@TestInstance(TestInstance.Lifecycle.PER_CLASS)
|
||||
public class TCKMonth extends AbstractDateTimeTest {
|
||||
|
||||
private static final int MAX_LENGTH = 12;
|
||||
@ -121,34 +125,34 @@ public class TCKMonth extends AbstractDateTimeTest {
|
||||
public void test_factory_int_singleton() {
|
||||
for (int i = 1; i <= MAX_LENGTH; i++) {
|
||||
Month test = Month.of(i);
|
||||
assertEquals(test.getValue(), i);
|
||||
assertEquals(i, test.getValue());
|
||||
}
|
||||
}
|
||||
|
||||
@Test(expectedExceptions=DateTimeException.class)
|
||||
@Test
|
||||
public void test_factory_int_tooLow() {
|
||||
Month.of(0);
|
||||
Assertions.assertThrows(DateTimeException.class, () -> Month.of(0));
|
||||
}
|
||||
|
||||
@Test(expectedExceptions=DateTimeException.class)
|
||||
@Test
|
||||
public void test_factory_int_tooHigh() {
|
||||
Month.of(13);
|
||||
Assertions.assertThrows(DateTimeException.class, () -> Month.of(13));
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
@Test
|
||||
public void test_factory_CalendricalObject() {
|
||||
assertEquals(Month.from(LocalDate.of(2011, 6, 6)), Month.JUNE);
|
||||
assertEquals(Month.JUNE, Month.from(LocalDate.of(2011, 6, 6)));
|
||||
}
|
||||
|
||||
@Test(expectedExceptions=DateTimeException.class)
|
||||
@Test
|
||||
public void test_factory_CalendricalObject_invalid_noDerive() {
|
||||
Month.from(LocalTime.of(12, 30));
|
||||
Assertions.assertThrows(DateTimeException.class, () -> Month.from(LocalTime.of(12, 30)));
|
||||
}
|
||||
|
||||
@Test(expectedExceptions=NullPointerException.class)
|
||||
@Test
|
||||
public void test_factory_CalendricalObject_null() {
|
||||
Month.from((TemporalAccessor) null);
|
||||
Assertions.assertThrows(NullPointerException.class, () -> Month.from((TemporalAccessor) null));
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
@ -156,37 +160,37 @@ public class TCKMonth extends AbstractDateTimeTest {
|
||||
//-----------------------------------------------------------------------
|
||||
@Test
|
||||
public void test_isSupported_TemporalField() {
|
||||
assertEquals(Month.AUGUST.isSupported((TemporalField) null), false);
|
||||
assertEquals(Month.AUGUST.isSupported(ChronoField.NANO_OF_SECOND), false);
|
||||
assertEquals(Month.AUGUST.isSupported(ChronoField.NANO_OF_DAY), false);
|
||||
assertEquals(Month.AUGUST.isSupported(ChronoField.MICRO_OF_SECOND), false);
|
||||
assertEquals(Month.AUGUST.isSupported(ChronoField.MICRO_OF_DAY), false);
|
||||
assertEquals(Month.AUGUST.isSupported(ChronoField.MILLI_OF_SECOND), false);
|
||||
assertEquals(Month.AUGUST.isSupported(ChronoField.MILLI_OF_DAY), false);
|
||||
assertEquals(Month.AUGUST.isSupported(ChronoField.SECOND_OF_MINUTE), false);
|
||||
assertEquals(Month.AUGUST.isSupported(ChronoField.SECOND_OF_DAY), false);
|
||||
assertEquals(Month.AUGUST.isSupported(ChronoField.MINUTE_OF_HOUR), false);
|
||||
assertEquals(Month.AUGUST.isSupported(ChronoField.MINUTE_OF_DAY), false);
|
||||
assertEquals(Month.AUGUST.isSupported(ChronoField.HOUR_OF_AMPM), false);
|
||||
assertEquals(Month.AUGUST.isSupported(ChronoField.CLOCK_HOUR_OF_AMPM), false);
|
||||
assertEquals(Month.AUGUST.isSupported(ChronoField.HOUR_OF_DAY), false);
|
||||
assertEquals(Month.AUGUST.isSupported(ChronoField.CLOCK_HOUR_OF_DAY), false);
|
||||
assertEquals(Month.AUGUST.isSupported(ChronoField.AMPM_OF_DAY), false);
|
||||
assertEquals(Month.AUGUST.isSupported(ChronoField.DAY_OF_WEEK), false);
|
||||
assertEquals(Month.AUGUST.isSupported(ChronoField.ALIGNED_DAY_OF_WEEK_IN_MONTH), false);
|
||||
assertEquals(Month.AUGUST.isSupported(ChronoField.ALIGNED_DAY_OF_WEEK_IN_YEAR), false);
|
||||
assertEquals(Month.AUGUST.isSupported(ChronoField.DAY_OF_MONTH), false);
|
||||
assertEquals(Month.AUGUST.isSupported(ChronoField.DAY_OF_YEAR), false);
|
||||
assertEquals(Month.AUGUST.isSupported(ChronoField.EPOCH_DAY), false);
|
||||
assertEquals(Month.AUGUST.isSupported(ChronoField.ALIGNED_WEEK_OF_MONTH), false);
|
||||
assertEquals(Month.AUGUST.isSupported(ChronoField.ALIGNED_WEEK_OF_YEAR), false);
|
||||
assertEquals(Month.AUGUST.isSupported(ChronoField.MONTH_OF_YEAR), true);
|
||||
assertEquals(Month.AUGUST.isSupported(ChronoField.PROLEPTIC_MONTH), false);
|
||||
assertEquals(Month.AUGUST.isSupported(ChronoField.YEAR), false);
|
||||
assertEquals(Month.AUGUST.isSupported(ChronoField.YEAR_OF_ERA), false);
|
||||
assertEquals(Month.AUGUST.isSupported(ChronoField.ERA), false);
|
||||
assertEquals(Month.AUGUST.isSupported(ChronoField.INSTANT_SECONDS), false);
|
||||
assertEquals(Month.AUGUST.isSupported(ChronoField.OFFSET_SECONDS), false);
|
||||
assertEquals(false, Month.AUGUST.isSupported((TemporalField) null));
|
||||
assertEquals(false, Month.AUGUST.isSupported(ChronoField.NANO_OF_SECOND));
|
||||
assertEquals(false, Month.AUGUST.isSupported(ChronoField.NANO_OF_DAY));
|
||||
assertEquals(false, Month.AUGUST.isSupported(ChronoField.MICRO_OF_SECOND));
|
||||
assertEquals(false, Month.AUGUST.isSupported(ChronoField.MICRO_OF_DAY));
|
||||
assertEquals(false, Month.AUGUST.isSupported(ChronoField.MILLI_OF_SECOND));
|
||||
assertEquals(false, Month.AUGUST.isSupported(ChronoField.MILLI_OF_DAY));
|
||||
assertEquals(false, Month.AUGUST.isSupported(ChronoField.SECOND_OF_MINUTE));
|
||||
assertEquals(false, Month.AUGUST.isSupported(ChronoField.SECOND_OF_DAY));
|
||||
assertEquals(false, Month.AUGUST.isSupported(ChronoField.MINUTE_OF_HOUR));
|
||||
assertEquals(false, Month.AUGUST.isSupported(ChronoField.MINUTE_OF_DAY));
|
||||
assertEquals(false, Month.AUGUST.isSupported(ChronoField.HOUR_OF_AMPM));
|
||||
assertEquals(false, Month.AUGUST.isSupported(ChronoField.CLOCK_HOUR_OF_AMPM));
|
||||
assertEquals(false, Month.AUGUST.isSupported(ChronoField.HOUR_OF_DAY));
|
||||
assertEquals(false, Month.AUGUST.isSupported(ChronoField.CLOCK_HOUR_OF_DAY));
|
||||
assertEquals(false, Month.AUGUST.isSupported(ChronoField.AMPM_OF_DAY));
|
||||
assertEquals(false, Month.AUGUST.isSupported(ChronoField.DAY_OF_WEEK));
|
||||
assertEquals(false, Month.AUGUST.isSupported(ChronoField.ALIGNED_DAY_OF_WEEK_IN_MONTH));
|
||||
assertEquals(false, Month.AUGUST.isSupported(ChronoField.ALIGNED_DAY_OF_WEEK_IN_YEAR));
|
||||
assertEquals(false, Month.AUGUST.isSupported(ChronoField.DAY_OF_MONTH));
|
||||
assertEquals(false, Month.AUGUST.isSupported(ChronoField.DAY_OF_YEAR));
|
||||
assertEquals(false, Month.AUGUST.isSupported(ChronoField.EPOCH_DAY));
|
||||
assertEquals(false, Month.AUGUST.isSupported(ChronoField.ALIGNED_WEEK_OF_MONTH));
|
||||
assertEquals(false, Month.AUGUST.isSupported(ChronoField.ALIGNED_WEEK_OF_YEAR));
|
||||
assertEquals(true, Month.AUGUST.isSupported(ChronoField.MONTH_OF_YEAR));
|
||||
assertEquals(false, Month.AUGUST.isSupported(ChronoField.PROLEPTIC_MONTH));
|
||||
assertEquals(false, Month.AUGUST.isSupported(ChronoField.YEAR));
|
||||
assertEquals(false, Month.AUGUST.isSupported(ChronoField.YEAR_OF_ERA));
|
||||
assertEquals(false, Month.AUGUST.isSupported(ChronoField.ERA));
|
||||
assertEquals(false, Month.AUGUST.isSupported(ChronoField.INSTANT_SECONDS));
|
||||
assertEquals(false, Month.AUGUST.isSupported(ChronoField.OFFSET_SECONDS));
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
@ -194,18 +198,17 @@ public class TCKMonth extends AbstractDateTimeTest {
|
||||
//-----------------------------------------------------------------------
|
||||
@Test
|
||||
public void test_get_TemporalField() {
|
||||
assertEquals(Month.JULY.get(ChronoField.MONTH_OF_YEAR), 7);
|
||||
assertEquals(7, Month.JULY.get(ChronoField.MONTH_OF_YEAR));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test_getLong_TemporalField() {
|
||||
assertEquals(Month.JULY.getLong(ChronoField.MONTH_OF_YEAR), 7);
|
||||
assertEquals(7, Month.JULY.getLong(ChronoField.MONTH_OF_YEAR));
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
// query(TemporalQuery)
|
||||
//-----------------------------------------------------------------------
|
||||
@DataProvider(name="query")
|
||||
Object[][] data_query() {
|
||||
return new Object[][] {
|
||||
{Month.JUNE, TemporalQueries.chronology(), IsoChronology.INSTANCE},
|
||||
@ -218,19 +221,21 @@ public class TCKMonth extends AbstractDateTimeTest {
|
||||
};
|
||||
}
|
||||
|
||||
@Test(dataProvider="query")
|
||||
@ParameterizedTest
|
||||
@MethodSource("data_query")
|
||||
public <T> void test_query(TemporalAccessor temporal, TemporalQuery<T> query, T expected) {
|
||||
assertEquals(temporal.query(query), expected);
|
||||
assertEquals(expected, temporal.query(query));
|
||||
}
|
||||
|
||||
@Test(dataProvider="query")
|
||||
@ParameterizedTest
|
||||
@MethodSource("data_query")
|
||||
public <T> void test_queryFrom(TemporalAccessor temporal, TemporalQuery<T> query, T expected) {
|
||||
assertEquals(query.queryFrom(temporal), expected);
|
||||
assertEquals(expected, query.queryFrom(temporal));
|
||||
}
|
||||
|
||||
@Test(expectedExceptions=NullPointerException.class)
|
||||
@Test
|
||||
public void test_query_null() {
|
||||
Month.JUNE.query(null);
|
||||
Assertions.assertThrows(NullPointerException.class, () -> Month.JUNE.query(null));
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
@ -238,23 +243,22 @@ public class TCKMonth extends AbstractDateTimeTest {
|
||||
//-----------------------------------------------------------------------
|
||||
@Test
|
||||
public void test_getText() {
|
||||
assertEquals(Month.JANUARY.getDisplayName(TextStyle.SHORT, Locale.US), "Jan");
|
||||
assertEquals("Jan", Month.JANUARY.getDisplayName(TextStyle.SHORT, Locale.US));
|
||||
}
|
||||
|
||||
@Test(expectedExceptions = NullPointerException.class)
|
||||
@Test
|
||||
public void test_getText_nullStyle() {
|
||||
Month.JANUARY.getDisplayName(null, Locale.US);
|
||||
Assertions.assertThrows(NullPointerException.class, () -> Month.JANUARY.getDisplayName(null, Locale.US));
|
||||
}
|
||||
|
||||
@Test(expectedExceptions = NullPointerException.class)
|
||||
@Test
|
||||
public void test_getText_nullLocale() {
|
||||
Month.JANUARY.getDisplayName(TextStyle.FULL, null);
|
||||
Assertions.assertThrows(NullPointerException.class, () -> Month.JANUARY.getDisplayName(TextStyle.FULL, null));
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
// plus(long), plus(long,unit)
|
||||
//-----------------------------------------------------------------------
|
||||
@DataProvider(name="plus")
|
||||
Object[][] data_plus() {
|
||||
return new Object[][] {
|
||||
{1, -13, 12},
|
||||
@ -313,15 +317,15 @@ public class TCKMonth extends AbstractDateTimeTest {
|
||||
};
|
||||
}
|
||||
|
||||
@Test(dataProvider="plus")
|
||||
@ParameterizedTest
|
||||
@MethodSource("data_plus")
|
||||
public void test_plus_long(int base, long amount, int expected) {
|
||||
assertEquals(Month.of(base).plus(amount), Month.of(expected));
|
||||
assertEquals(Month.of(expected), Month.of(base).plus(amount));
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
// minus(long), minus(long,unit)
|
||||
//-----------------------------------------------------------------------
|
||||
@DataProvider(name="minus")
|
||||
Object[][] data_minus() {
|
||||
return new Object[][] {
|
||||
{1, -13, 2},
|
||||
@ -354,9 +358,10 @@ public class TCKMonth extends AbstractDateTimeTest {
|
||||
};
|
||||
}
|
||||
|
||||
@Test(dataProvider="minus")
|
||||
@ParameterizedTest
|
||||
@MethodSource("data_minus")
|
||||
public void test_minus_long(int base, long amount, int expected) {
|
||||
assertEquals(Month.of(base).minus(amount), Month.of(expected));
|
||||
assertEquals(Month.of(expected), Month.of(base).minus(amount));
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
@ -364,34 +369,34 @@ public class TCKMonth extends AbstractDateTimeTest {
|
||||
//-----------------------------------------------------------------------
|
||||
@Test
|
||||
public void test_length_boolean_notLeapYear() {
|
||||
assertEquals(Month.JANUARY.length(false), 31);
|
||||
assertEquals(Month.FEBRUARY.length(false), 28);
|
||||
assertEquals(Month.MARCH.length(false), 31);
|
||||
assertEquals(Month.APRIL.length(false), 30);
|
||||
assertEquals(Month.MAY.length(false), 31);
|
||||
assertEquals(Month.JUNE.length(false), 30);
|
||||
assertEquals(Month.JULY.length(false), 31);
|
||||
assertEquals(Month.AUGUST.length(false), 31);
|
||||
assertEquals(Month.SEPTEMBER.length(false), 30);
|
||||
assertEquals(Month.OCTOBER.length(false), 31);
|
||||
assertEquals(Month.NOVEMBER.length(false), 30);
|
||||
assertEquals(Month.DECEMBER.length(false), 31);
|
||||
assertEquals(31, Month.JANUARY.length(false));
|
||||
assertEquals(28, Month.FEBRUARY.length(false));
|
||||
assertEquals(31, Month.MARCH.length(false));
|
||||
assertEquals(30, Month.APRIL.length(false));
|
||||
assertEquals(31, Month.MAY.length(false));
|
||||
assertEquals(30, Month.JUNE.length(false));
|
||||
assertEquals(31, Month.JULY.length(false));
|
||||
assertEquals(31, Month.AUGUST.length(false));
|
||||
assertEquals(30, Month.SEPTEMBER.length(false));
|
||||
assertEquals(31, Month.OCTOBER.length(false));
|
||||
assertEquals(30, Month.NOVEMBER.length(false));
|
||||
assertEquals(31, Month.DECEMBER.length(false));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test_length_boolean_leapYear() {
|
||||
assertEquals(Month.JANUARY.length(true), 31);
|
||||
assertEquals(Month.FEBRUARY.length(true), 29);
|
||||
assertEquals(Month.MARCH.length(true), 31);
|
||||
assertEquals(Month.APRIL.length(true), 30);
|
||||
assertEquals(Month.MAY.length(true), 31);
|
||||
assertEquals(Month.JUNE.length(true), 30);
|
||||
assertEquals(Month.JULY.length(true), 31);
|
||||
assertEquals(Month.AUGUST.length(true), 31);
|
||||
assertEquals(Month.SEPTEMBER.length(true), 30);
|
||||
assertEquals(Month.OCTOBER.length(true), 31);
|
||||
assertEquals(Month.NOVEMBER.length(true), 30);
|
||||
assertEquals(Month.DECEMBER.length(true), 31);
|
||||
assertEquals(31, Month.JANUARY.length(true));
|
||||
assertEquals(29, Month.FEBRUARY.length(true));
|
||||
assertEquals(31, Month.MARCH.length(true));
|
||||
assertEquals(30, Month.APRIL.length(true));
|
||||
assertEquals(31, Month.MAY.length(true));
|
||||
assertEquals(30, Month.JUNE.length(true));
|
||||
assertEquals(31, Month.JULY.length(true));
|
||||
assertEquals(31, Month.AUGUST.length(true));
|
||||
assertEquals(30, Month.SEPTEMBER.length(true));
|
||||
assertEquals(31, Month.OCTOBER.length(true));
|
||||
assertEquals(30, Month.NOVEMBER.length(true));
|
||||
assertEquals(31, Month.DECEMBER.length(true));
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
@ -399,18 +404,18 @@ public class TCKMonth extends AbstractDateTimeTest {
|
||||
//-----------------------------------------------------------------------
|
||||
@Test
|
||||
public void test_minLength() {
|
||||
assertEquals(Month.JANUARY.minLength(), 31);
|
||||
assertEquals(Month.FEBRUARY.minLength(), 28);
|
||||
assertEquals(Month.MARCH.minLength(), 31);
|
||||
assertEquals(Month.APRIL.minLength(), 30);
|
||||
assertEquals(Month.MAY.minLength(), 31);
|
||||
assertEquals(Month.JUNE.minLength(), 30);
|
||||
assertEquals(Month.JULY.minLength(), 31);
|
||||
assertEquals(Month.AUGUST.minLength(), 31);
|
||||
assertEquals(Month.SEPTEMBER.minLength(), 30);
|
||||
assertEquals(Month.OCTOBER.minLength(), 31);
|
||||
assertEquals(Month.NOVEMBER.minLength(), 30);
|
||||
assertEquals(Month.DECEMBER.minLength(), 31);
|
||||
assertEquals(31, Month.JANUARY.minLength());
|
||||
assertEquals(28, Month.FEBRUARY.minLength());
|
||||
assertEquals(31, Month.MARCH.minLength());
|
||||
assertEquals(30, Month.APRIL.minLength());
|
||||
assertEquals(31, Month.MAY.minLength());
|
||||
assertEquals(30, Month.JUNE.minLength());
|
||||
assertEquals(31, Month.JULY.minLength());
|
||||
assertEquals(31, Month.AUGUST.minLength());
|
||||
assertEquals(30, Month.SEPTEMBER.minLength());
|
||||
assertEquals(31, Month.OCTOBER.minLength());
|
||||
assertEquals(30, Month.NOVEMBER.minLength());
|
||||
assertEquals(31, Month.DECEMBER.minLength());
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
@ -418,18 +423,18 @@ public class TCKMonth extends AbstractDateTimeTest {
|
||||
//-----------------------------------------------------------------------
|
||||
@Test
|
||||
public void test_maxLength() {
|
||||
assertEquals(Month.JANUARY.maxLength(), 31);
|
||||
assertEquals(Month.FEBRUARY.maxLength(), 29);
|
||||
assertEquals(Month.MARCH.maxLength(), 31);
|
||||
assertEquals(Month.APRIL.maxLength(), 30);
|
||||
assertEquals(Month.MAY.maxLength(), 31);
|
||||
assertEquals(Month.JUNE.maxLength(), 30);
|
||||
assertEquals(Month.JULY.maxLength(), 31);
|
||||
assertEquals(Month.AUGUST.maxLength(), 31);
|
||||
assertEquals(Month.SEPTEMBER.maxLength(), 30);
|
||||
assertEquals(Month.OCTOBER.maxLength(), 31);
|
||||
assertEquals(Month.NOVEMBER.maxLength(), 30);
|
||||
assertEquals(Month.DECEMBER.maxLength(), 31);
|
||||
assertEquals(31, Month.JANUARY.maxLength());
|
||||
assertEquals(29, Month.FEBRUARY.maxLength());
|
||||
assertEquals(31, Month.MARCH.maxLength());
|
||||
assertEquals(30, Month.APRIL.maxLength());
|
||||
assertEquals(31, Month.MAY.maxLength());
|
||||
assertEquals(30, Month.JUNE.maxLength());
|
||||
assertEquals(31, Month.JULY.maxLength());
|
||||
assertEquals(31, Month.AUGUST.maxLength());
|
||||
assertEquals(30, Month.SEPTEMBER.maxLength());
|
||||
assertEquals(31, Month.OCTOBER.maxLength());
|
||||
assertEquals(30, Month.NOVEMBER.maxLength());
|
||||
assertEquals(31, Month.DECEMBER.maxLength());
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
@ -437,34 +442,34 @@ public class TCKMonth extends AbstractDateTimeTest {
|
||||
//-----------------------------------------------------------------------
|
||||
@Test
|
||||
public void test_firstDayOfYear_notLeapYear() {
|
||||
assertEquals(Month.JANUARY.firstDayOfYear(false), 1);
|
||||
assertEquals(Month.FEBRUARY.firstDayOfYear(false), 1 + 31);
|
||||
assertEquals(Month.MARCH.firstDayOfYear(false), 1 + 31 + 28);
|
||||
assertEquals(Month.APRIL.firstDayOfYear(false), 1 + 31 + 28 + 31);
|
||||
assertEquals(Month.MAY.firstDayOfYear(false), 1 + 31 + 28 + 31 + 30);
|
||||
assertEquals(Month.JUNE.firstDayOfYear(false), 1 + 31 + 28 + 31 + 30 + 31);
|
||||
assertEquals(Month.JULY.firstDayOfYear(false), 1 + 31 + 28 + 31 + 30 + 31 + 30);
|
||||
assertEquals(Month.AUGUST.firstDayOfYear(false), 1 + 31 + 28 + 31 + 30 + 31 + 30 + 31);
|
||||
assertEquals(Month.SEPTEMBER.firstDayOfYear(false), 1 + 31 + 28 + 31 + 30 + 31 + 30 + 31 + 31);
|
||||
assertEquals(Month.OCTOBER.firstDayOfYear(false), 1 + 31 + 28 + 31 + 30 + 31 + 30 + 31 + 31 + 30);
|
||||
assertEquals(Month.NOVEMBER.firstDayOfYear(false), 1 + 31 + 28 + 31 + 30 + 31 + 30 + 31 + 31 + 30 + 31);
|
||||
assertEquals(Month.DECEMBER.firstDayOfYear(false), 1 + 31 + 28 + 31 + 30 + 31 + 30 + 31 + 31 + 30 + 31 + 30);
|
||||
assertEquals(1, Month.JANUARY.firstDayOfYear(false));
|
||||
assertEquals(1 + 31, Month.FEBRUARY.firstDayOfYear(false));
|
||||
assertEquals(1 + 31 + 28, Month.MARCH.firstDayOfYear(false));
|
||||
assertEquals(1 + 31 + 28 + 31, Month.APRIL.firstDayOfYear(false));
|
||||
assertEquals(1 + 31 + 28 + 31 + 30, Month.MAY.firstDayOfYear(false));
|
||||
assertEquals(1 + 31 + 28 + 31 + 30 + 31, Month.JUNE.firstDayOfYear(false));
|
||||
assertEquals(1 + 31 + 28 + 31 + 30 + 31 + 30, Month.JULY.firstDayOfYear(false));
|
||||
assertEquals(1 + 31 + 28 + 31 + 30 + 31 + 30 + 31, Month.AUGUST.firstDayOfYear(false));
|
||||
assertEquals(1 + 31 + 28 + 31 + 30 + 31 + 30 + 31 + 31, Month.SEPTEMBER.firstDayOfYear(false));
|
||||
assertEquals(1 + 31 + 28 + 31 + 30 + 31 + 30 + 31 + 31 + 30, Month.OCTOBER.firstDayOfYear(false));
|
||||
assertEquals(1 + 31 + 28 + 31 + 30 + 31 + 30 + 31 + 31 + 30 + 31, Month.NOVEMBER.firstDayOfYear(false));
|
||||
assertEquals(1 + 31 + 28 + 31 + 30 + 31 + 30 + 31 + 31 + 30 + 31 + 30, Month.DECEMBER.firstDayOfYear(false));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test_firstDayOfYear_leapYear() {
|
||||
assertEquals(Month.JANUARY.firstDayOfYear(true), 1);
|
||||
assertEquals(Month.FEBRUARY.firstDayOfYear(true), 1 + 31);
|
||||
assertEquals(Month.MARCH.firstDayOfYear(true), 1 + 31 + 29);
|
||||
assertEquals(Month.APRIL.firstDayOfYear(true), 1 + 31 + 29 + 31);
|
||||
assertEquals(Month.MAY.firstDayOfYear(true), 1 + 31 + 29 + 31 + 30);
|
||||
assertEquals(Month.JUNE.firstDayOfYear(true), 1 + 31 + 29 + 31 + 30 + 31);
|
||||
assertEquals(Month.JULY.firstDayOfYear(true), 1 + 31 + 29 + 31 + 30 + 31 + 30);
|
||||
assertEquals(Month.AUGUST.firstDayOfYear(true), 1 + 31 + 29 + 31 + 30 + 31 + 30 + 31);
|
||||
assertEquals(Month.SEPTEMBER.firstDayOfYear(true), 1 + 31 + 29 + 31 + 30 + 31 + 30 + 31 + 31);
|
||||
assertEquals(Month.OCTOBER.firstDayOfYear(true), 1 + 31 + 29 + 31 + 30 + 31 + 30 + 31 + 31 + 30);
|
||||
assertEquals(Month.NOVEMBER.firstDayOfYear(true), 1 + 31 + 29 + 31 + 30 + 31 + 30 + 31 + 31 + 30 + 31);
|
||||
assertEquals(Month.DECEMBER.firstDayOfYear(true), 1 + 31 + 29 + 31 + 30 + 31 + 30 + 31 + 31 + 30 + 31 + 30);
|
||||
assertEquals(1, Month.JANUARY.firstDayOfYear(true));
|
||||
assertEquals(1 + 31, Month.FEBRUARY.firstDayOfYear(true));
|
||||
assertEquals(1 + 31 + 29, Month.MARCH.firstDayOfYear(true));
|
||||
assertEquals(1 + 31 + 29 + 31, Month.APRIL.firstDayOfYear(true));
|
||||
assertEquals(1 + 31 + 29 + 31 + 30, Month.MAY.firstDayOfYear(true));
|
||||
assertEquals(1 + 31 + 29 + 31 + 30 + 31, Month.JUNE.firstDayOfYear(true));
|
||||
assertEquals(1 + 31 + 29 + 31 + 30 + 31 + 30, Month.JULY.firstDayOfYear(true));
|
||||
assertEquals(1 + 31 + 29 + 31 + 30 + 31 + 30 + 31, Month.AUGUST.firstDayOfYear(true));
|
||||
assertEquals(1 + 31 + 29 + 31 + 30 + 31 + 30 + 31 + 31, Month.SEPTEMBER.firstDayOfYear(true));
|
||||
assertEquals(1 + 31 + 29 + 31 + 30 + 31 + 30 + 31 + 31 + 30, Month.OCTOBER.firstDayOfYear(true));
|
||||
assertEquals(1 + 31 + 29 + 31 + 30 + 31 + 30 + 31 + 31 + 30 + 31, Month.NOVEMBER.firstDayOfYear(true));
|
||||
assertEquals(1 + 31 + 29 + 31 + 30 + 31 + 30 + 31 + 31 + 30 + 31 + 30, Month.DECEMBER.firstDayOfYear(true));
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
@ -472,18 +477,18 @@ public class TCKMonth extends AbstractDateTimeTest {
|
||||
//-----------------------------------------------------------------------
|
||||
@Test
|
||||
public void test_firstMonthOfQuarter() {
|
||||
assertEquals(Month.JANUARY.firstMonthOfQuarter(), Month.JANUARY);
|
||||
assertEquals(Month.FEBRUARY.firstMonthOfQuarter(), Month.JANUARY);
|
||||
assertEquals(Month.MARCH.firstMonthOfQuarter(), Month.JANUARY);
|
||||
assertEquals(Month.APRIL.firstMonthOfQuarter(), Month.APRIL);
|
||||
assertEquals(Month.MAY.firstMonthOfQuarter(), Month.APRIL);
|
||||
assertEquals(Month.JUNE.firstMonthOfQuarter(), Month.APRIL);
|
||||
assertEquals(Month.JULY.firstMonthOfQuarter(), Month.JULY);
|
||||
assertEquals(Month.AUGUST.firstMonthOfQuarter(), Month.JULY);
|
||||
assertEquals(Month.SEPTEMBER.firstMonthOfQuarter(), Month.JULY);
|
||||
assertEquals(Month.OCTOBER.firstMonthOfQuarter(), Month.OCTOBER);
|
||||
assertEquals(Month.NOVEMBER.firstMonthOfQuarter(), Month.OCTOBER);
|
||||
assertEquals(Month.DECEMBER.firstMonthOfQuarter(), Month.OCTOBER);
|
||||
assertEquals(Month.JANUARY, Month.JANUARY.firstMonthOfQuarter());
|
||||
assertEquals(Month.JANUARY, Month.FEBRUARY.firstMonthOfQuarter());
|
||||
assertEquals(Month.JANUARY, Month.MARCH.firstMonthOfQuarter());
|
||||
assertEquals(Month.APRIL, Month.APRIL.firstMonthOfQuarter());
|
||||
assertEquals(Month.APRIL, Month.MAY.firstMonthOfQuarter());
|
||||
assertEquals(Month.APRIL, Month.JUNE.firstMonthOfQuarter());
|
||||
assertEquals(Month.JULY, Month.JULY.firstMonthOfQuarter());
|
||||
assertEquals(Month.JULY, Month.AUGUST.firstMonthOfQuarter());
|
||||
assertEquals(Month.JULY, Month.SEPTEMBER.firstMonthOfQuarter());
|
||||
assertEquals(Month.OCTOBER, Month.OCTOBER.firstMonthOfQuarter());
|
||||
assertEquals(Month.OCTOBER, Month.NOVEMBER.firstMonthOfQuarter());
|
||||
assertEquals(Month.OCTOBER, Month.DECEMBER.firstMonthOfQuarter());
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
@ -491,18 +496,18 @@ public class TCKMonth extends AbstractDateTimeTest {
|
||||
//-----------------------------------------------------------------------
|
||||
@Test
|
||||
public void test_toString() {
|
||||
assertEquals(Month.JANUARY.toString(), "JANUARY");
|
||||
assertEquals(Month.FEBRUARY.toString(), "FEBRUARY");
|
||||
assertEquals(Month.MARCH.toString(), "MARCH");
|
||||
assertEquals(Month.APRIL.toString(), "APRIL");
|
||||
assertEquals(Month.MAY.toString(), "MAY");
|
||||
assertEquals(Month.JUNE.toString(), "JUNE");
|
||||
assertEquals(Month.JULY.toString(), "JULY");
|
||||
assertEquals(Month.AUGUST.toString(), "AUGUST");
|
||||
assertEquals(Month.SEPTEMBER.toString(), "SEPTEMBER");
|
||||
assertEquals(Month.OCTOBER.toString(), "OCTOBER");
|
||||
assertEquals(Month.NOVEMBER.toString(), "NOVEMBER");
|
||||
assertEquals(Month.DECEMBER.toString(), "DECEMBER");
|
||||
assertEquals("JANUARY", Month.JANUARY.toString());
|
||||
assertEquals("FEBRUARY", Month.FEBRUARY.toString());
|
||||
assertEquals("MARCH", Month.MARCH.toString());
|
||||
assertEquals("APRIL", Month.APRIL.toString());
|
||||
assertEquals("MAY", Month.MAY.toString());
|
||||
assertEquals("JUNE", Month.JUNE.toString());
|
||||
assertEquals("JULY", Month.JULY.toString());
|
||||
assertEquals("AUGUST", Month.AUGUST.toString());
|
||||
assertEquals("SEPTEMBER", Month.SEPTEMBER.toString());
|
||||
assertEquals("OCTOBER", Month.OCTOBER.toString());
|
||||
assertEquals("NOVEMBER", Month.NOVEMBER.toString());
|
||||
assertEquals("DECEMBER", Month.DECEMBER.toString());
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
@ -510,8 +515,8 @@ public class TCKMonth extends AbstractDateTimeTest {
|
||||
//-----------------------------------------------------------------------
|
||||
@Test
|
||||
public void test_enum() {
|
||||
assertEquals(Month.valueOf("JANUARY"), Month.JANUARY);
|
||||
assertEquals(Month.values()[0], Month.JANUARY);
|
||||
assertEquals(Month.JANUARY, Month.valueOf("JANUARY"));
|
||||
assertEquals(Month.JANUARY, Month.values()[0]);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2012, 2013, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2012, 2025, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
@ -61,9 +61,10 @@ package tck.java.time;
|
||||
|
||||
import static java.time.temporal.ChronoField.DAY_OF_MONTH;
|
||||
import static java.time.temporal.ChronoField.MONTH_OF_YEAR;
|
||||
import static org.testng.Assert.assertEquals;
|
||||
import static org.testng.Assert.assertTrue;
|
||||
import static org.testng.Assert.fail;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
import static org.junit.jupiter.api.Assertions.fail;
|
||||
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.DataOutputStream;
|
||||
@ -94,19 +95,22 @@ import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import org.testng.annotations.BeforeMethod;
|
||||
import org.testng.annotations.DataProvider;
|
||||
import org.testng.annotations.Test;
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.TestInstance;
|
||||
import org.junit.jupiter.params.ParameterizedTest;
|
||||
import org.junit.jupiter.params.provider.MethodSource;
|
||||
|
||||
/**
|
||||
* Test MonthDay.
|
||||
*/
|
||||
@Test
|
||||
@TestInstance(TestInstance.Lifecycle.PER_CLASS)
|
||||
public class TCKMonthDay extends AbstractDateTimeTest {
|
||||
|
||||
private MonthDay TEST_07_15;
|
||||
|
||||
@BeforeMethod
|
||||
@BeforeEach
|
||||
public void setUp() {
|
||||
TEST_07_15 = MonthDay.of(7, 15);
|
||||
}
|
||||
@ -139,8 +143,8 @@ public class TCKMonthDay extends AbstractDateTimeTest {
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
void check(MonthDay test, int m, int d) {
|
||||
assertEquals(test.getMonth().getValue(), m);
|
||||
assertEquals(test.getDayOfMonth(), d);
|
||||
assertEquals(m, test.getMonth().getValue());
|
||||
assertEquals(d, test.getDayOfMonth());
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
@ -157,15 +161,15 @@ public class TCKMonthDay extends AbstractDateTimeTest {
|
||||
expected = MonthDay.now(Clock.systemDefaultZone());
|
||||
test = MonthDay.now();
|
||||
}
|
||||
assertEquals(test, expected);
|
||||
assertEquals(expected, test);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
// now(ZoneId)
|
||||
//-----------------------------------------------------------------------
|
||||
@Test(expectedExceptions=NullPointerException.class)
|
||||
@Test
|
||||
public void now_ZoneId_nullZoneId() {
|
||||
MonthDay.now((ZoneId) null);
|
||||
Assertions.assertThrows(NullPointerException.class, () -> MonthDay.now((ZoneId) null));
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -180,7 +184,7 @@ public class TCKMonthDay extends AbstractDateTimeTest {
|
||||
expected = MonthDay.now(Clock.system(zone));
|
||||
test = MonthDay.now(zone);
|
||||
}
|
||||
assertEquals(test, expected);
|
||||
assertEquals(expected, test);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
@ -191,34 +195,34 @@ public class TCKMonthDay extends AbstractDateTimeTest {
|
||||
Instant instant = LocalDateTime.of(2010, 12, 31, 0, 0).toInstant(ZoneOffset.UTC);
|
||||
Clock clock = Clock.fixed(instant, ZoneOffset.UTC);
|
||||
MonthDay test = MonthDay.now(clock);
|
||||
assertEquals(test.getMonth(), Month.DECEMBER);
|
||||
assertEquals(test.getDayOfMonth(), 31);
|
||||
assertEquals(Month.DECEMBER, test.getMonth());
|
||||
assertEquals(31, test.getDayOfMonth());
|
||||
}
|
||||
|
||||
@Test(expectedExceptions=NullPointerException.class)
|
||||
@Test
|
||||
public void now_Clock_nullClock() {
|
||||
MonthDay.now((Clock) null);
|
||||
Assertions.assertThrows(NullPointerException.class, () -> MonthDay.now((Clock) null));
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
@Test
|
||||
public void factory_intMonth() {
|
||||
assertEquals(TEST_07_15, MonthDay.of(Month.JULY, 15));
|
||||
assertEquals(MonthDay.of(Month.JULY, 15), TEST_07_15);
|
||||
}
|
||||
|
||||
@Test(expectedExceptions=DateTimeException.class)
|
||||
@Test
|
||||
public void test_factory_intMonth_dayTooLow() {
|
||||
MonthDay.of(Month.JANUARY, 0);
|
||||
Assertions.assertThrows(DateTimeException.class, () -> MonthDay.of(Month.JANUARY, 0));
|
||||
}
|
||||
|
||||
@Test(expectedExceptions=DateTimeException.class)
|
||||
@Test
|
||||
public void test_factory_intMonth_dayTooHigh() {
|
||||
MonthDay.of(Month.JANUARY, 32);
|
||||
Assertions.assertThrows(DateTimeException.class, () -> MonthDay.of(Month.JANUARY, 32));
|
||||
}
|
||||
|
||||
@Test(expectedExceptions=NullPointerException.class)
|
||||
@Test
|
||||
public void factory_intMonth_nullMonth() {
|
||||
MonthDay.of(null, 15);
|
||||
Assertions.assertThrows(NullPointerException.class, () -> MonthDay.of(null, 15));
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
@ -227,47 +231,46 @@ public class TCKMonthDay extends AbstractDateTimeTest {
|
||||
check(TEST_07_15, 7, 15);
|
||||
}
|
||||
|
||||
@Test(expectedExceptions=DateTimeException.class)
|
||||
@Test
|
||||
public void test_factory_ints_dayTooLow() {
|
||||
MonthDay.of(1, 0);
|
||||
Assertions.assertThrows(DateTimeException.class, () -> MonthDay.of(1, 0));
|
||||
}
|
||||
|
||||
@Test(expectedExceptions=DateTimeException.class)
|
||||
@Test
|
||||
public void test_factory_ints_dayTooHigh() {
|
||||
MonthDay.of(1, 32);
|
||||
Assertions.assertThrows(DateTimeException.class, () -> MonthDay.of(1, 32));
|
||||
}
|
||||
|
||||
|
||||
@Test(expectedExceptions=DateTimeException.class)
|
||||
@Test
|
||||
public void test_factory_ints_monthTooLow() {
|
||||
MonthDay.of(0, 1);
|
||||
Assertions.assertThrows(DateTimeException.class, () -> MonthDay.of(0, 1));
|
||||
}
|
||||
|
||||
@Test(expectedExceptions=DateTimeException.class)
|
||||
@Test
|
||||
public void test_factory_ints_monthTooHigh() {
|
||||
MonthDay.of(13, 1);
|
||||
Assertions.assertThrows(DateTimeException.class, () -> MonthDay.of(13, 1));
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
@Test
|
||||
public void test_factory_CalendricalObject() {
|
||||
assertEquals(MonthDay.from(LocalDate.of(2007, 7, 15)), TEST_07_15);
|
||||
assertEquals(TEST_07_15, MonthDay.from(LocalDate.of(2007, 7, 15)));
|
||||
}
|
||||
|
||||
@Test(expectedExceptions=DateTimeException.class)
|
||||
@Test
|
||||
public void test_factory_CalendricalObject_invalid_noDerive() {
|
||||
MonthDay.from(LocalTime.of(12, 30));
|
||||
Assertions.assertThrows(DateTimeException.class, () -> MonthDay.from(LocalTime.of(12, 30)));
|
||||
}
|
||||
|
||||
@Test(expectedExceptions=NullPointerException.class)
|
||||
@Test
|
||||
public void test_factory_CalendricalObject_null() {
|
||||
MonthDay.from((TemporalAccessor) null);
|
||||
Assertions.assertThrows(NullPointerException.class, () -> MonthDay.from((TemporalAccessor) null));
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
// parse()
|
||||
//-----------------------------------------------------------------------
|
||||
@DataProvider(name="goodParseData")
|
||||
Object[][] provider_goodParseData() {
|
||||
return new Object[][] {
|
||||
{"--01-01", MonthDay.of(1, 1)},
|
||||
@ -297,14 +300,14 @@ public class TCKMonthDay extends AbstractDateTimeTest {
|
||||
};
|
||||
}
|
||||
|
||||
@Test(dataProvider="goodParseData")
|
||||
@ParameterizedTest
|
||||
@MethodSource("provider_goodParseData")
|
||||
public void factory_parse_success(String text, MonthDay expected) {
|
||||
MonthDay monthDay = MonthDay.parse(text);
|
||||
assertEquals(monthDay, expected);
|
||||
assertEquals(expected, monthDay);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
@DataProvider(name="badParseData")
|
||||
Object[][] provider_badParseData() {
|
||||
return new Object[][] {
|
||||
{"", 0},
|
||||
@ -315,38 +318,40 @@ public class TCKMonthDay extends AbstractDateTimeTest {
|
||||
};
|
||||
}
|
||||
|
||||
@Test(dataProvider="badParseData", expectedExceptions=DateTimeParseException.class)
|
||||
@ParameterizedTest
|
||||
@MethodSource("provider_badParseData")
|
||||
public void factory_parse_fail(String text, int pos) {
|
||||
try {
|
||||
MonthDay.parse(text);
|
||||
fail(String.format("Parse should have failed for %s at position %d", text, pos));
|
||||
}
|
||||
catch (DateTimeParseException ex) {
|
||||
assertEquals(ex.getParsedString(), text);
|
||||
assertEquals(ex.getErrorIndex(), pos);
|
||||
throw ex;
|
||||
}
|
||||
Assertions.assertThrows(DateTimeParseException.class, () -> {
|
||||
try {
|
||||
MonthDay.parse(text);
|
||||
fail(String.format("Parse should have failed for %s at position %d", text, pos));
|
||||
} catch (DateTimeParseException ex) {
|
||||
assertEquals(text, ex.getParsedString());
|
||||
assertEquals(pos, ex.getErrorIndex());
|
||||
throw ex;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
@Test(expectedExceptions=DateTimeParseException.class)
|
||||
@Test
|
||||
public void factory_parse_illegalValue_Day() {
|
||||
MonthDay.parse("--06-32");
|
||||
Assertions.assertThrows(DateTimeParseException.class, () -> MonthDay.parse("--06-32"));
|
||||
}
|
||||
|
||||
@Test(expectedExceptions=DateTimeParseException.class)
|
||||
@Test
|
||||
public void factory_parse_invalidValue_Day() {
|
||||
MonthDay.parse("--06-31");
|
||||
Assertions.assertThrows(DateTimeParseException.class, () -> MonthDay.parse("--06-31"));
|
||||
}
|
||||
|
||||
@Test(expectedExceptions=DateTimeParseException.class)
|
||||
@Test
|
||||
public void factory_parse_illegalValue_Month() {
|
||||
MonthDay.parse("--13-25");
|
||||
Assertions.assertThrows(DateTimeParseException.class, () -> MonthDay.parse("--13-25"));
|
||||
}
|
||||
|
||||
@Test(expectedExceptions=NullPointerException.class)
|
||||
@Test
|
||||
public void factory_parse_nullText() {
|
||||
MonthDay.parse(null);
|
||||
Assertions.assertThrows(NullPointerException.class, () -> MonthDay.parse(null));
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
@ -356,18 +361,20 @@ public class TCKMonthDay extends AbstractDateTimeTest {
|
||||
public void factory_parse_formatter() {
|
||||
DateTimeFormatter f = DateTimeFormatter.ofPattern("M d");
|
||||
MonthDay test = MonthDay.parse("12 3", f);
|
||||
assertEquals(test, MonthDay.of(12, 3));
|
||||
assertEquals(MonthDay.of(12, 3), test);
|
||||
}
|
||||
|
||||
@Test(expectedExceptions=NullPointerException.class)
|
||||
@Test
|
||||
public void factory_parse_formatter_nullText() {
|
||||
DateTimeFormatter f = DateTimeFormatter.ofPattern("M d");
|
||||
MonthDay.parse((String) null, f);
|
||||
Assertions.assertThrows(NullPointerException.class, () -> {
|
||||
DateTimeFormatter f = DateTimeFormatter.ofPattern("M d");
|
||||
MonthDay.parse((String) null, f);
|
||||
});
|
||||
}
|
||||
|
||||
@Test(expectedExceptions=NullPointerException.class)
|
||||
@Test
|
||||
public void factory_parse_formatter_nullFormatter() {
|
||||
MonthDay.parse("ANY", null);
|
||||
Assertions.assertThrows(NullPointerException.class, () -> MonthDay.parse("ANY", null));
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
@ -375,37 +382,37 @@ public class TCKMonthDay extends AbstractDateTimeTest {
|
||||
//-----------------------------------------------------------------------
|
||||
@Test
|
||||
public void test_isSupported_TemporalField() {
|
||||
assertEquals(TEST_07_15.isSupported((TemporalField) null), false);
|
||||
assertEquals(TEST_07_15.isSupported(ChronoField.NANO_OF_SECOND), false);
|
||||
assertEquals(TEST_07_15.isSupported(ChronoField.NANO_OF_DAY), false);
|
||||
assertEquals(TEST_07_15.isSupported(ChronoField.MICRO_OF_SECOND), false);
|
||||
assertEquals(TEST_07_15.isSupported(ChronoField.MICRO_OF_DAY), false);
|
||||
assertEquals(TEST_07_15.isSupported(ChronoField.MILLI_OF_SECOND), false);
|
||||
assertEquals(TEST_07_15.isSupported(ChronoField.MILLI_OF_DAY), false);
|
||||
assertEquals(TEST_07_15.isSupported(ChronoField.SECOND_OF_MINUTE), false);
|
||||
assertEquals(TEST_07_15.isSupported(ChronoField.SECOND_OF_DAY), false);
|
||||
assertEquals(TEST_07_15.isSupported(ChronoField.MINUTE_OF_HOUR), false);
|
||||
assertEquals(TEST_07_15.isSupported(ChronoField.MINUTE_OF_DAY), false);
|
||||
assertEquals(TEST_07_15.isSupported(ChronoField.HOUR_OF_AMPM), false);
|
||||
assertEquals(TEST_07_15.isSupported(ChronoField.CLOCK_HOUR_OF_AMPM), false);
|
||||
assertEquals(TEST_07_15.isSupported(ChronoField.HOUR_OF_DAY), false);
|
||||
assertEquals(TEST_07_15.isSupported(ChronoField.CLOCK_HOUR_OF_DAY), false);
|
||||
assertEquals(TEST_07_15.isSupported(ChronoField.AMPM_OF_DAY), false);
|
||||
assertEquals(TEST_07_15.isSupported(ChronoField.DAY_OF_WEEK), false);
|
||||
assertEquals(TEST_07_15.isSupported(ChronoField.ALIGNED_DAY_OF_WEEK_IN_MONTH), false);
|
||||
assertEquals(TEST_07_15.isSupported(ChronoField.ALIGNED_DAY_OF_WEEK_IN_YEAR), false);
|
||||
assertEquals(TEST_07_15.isSupported(ChronoField.DAY_OF_MONTH), true);
|
||||
assertEquals(TEST_07_15.isSupported(ChronoField.DAY_OF_YEAR), false);
|
||||
assertEquals(TEST_07_15.isSupported(ChronoField.EPOCH_DAY), false);
|
||||
assertEquals(TEST_07_15.isSupported(ChronoField.ALIGNED_WEEK_OF_MONTH), false);
|
||||
assertEquals(TEST_07_15.isSupported(ChronoField.ALIGNED_WEEK_OF_YEAR), false);
|
||||
assertEquals(TEST_07_15.isSupported(ChronoField.MONTH_OF_YEAR), true);
|
||||
assertEquals(TEST_07_15.isSupported(ChronoField.PROLEPTIC_MONTH), false);
|
||||
assertEquals(TEST_07_15.isSupported(ChronoField.YEAR), false);
|
||||
assertEquals(TEST_07_15.isSupported(ChronoField.YEAR_OF_ERA), false);
|
||||
assertEquals(TEST_07_15.isSupported(ChronoField.ERA), false);
|
||||
assertEquals(TEST_07_15.isSupported(ChronoField.INSTANT_SECONDS), false);
|
||||
assertEquals(TEST_07_15.isSupported(ChronoField.OFFSET_SECONDS), false);
|
||||
assertEquals(false, TEST_07_15.isSupported((TemporalField) null));
|
||||
assertEquals(false, TEST_07_15.isSupported(ChronoField.NANO_OF_SECOND));
|
||||
assertEquals(false, TEST_07_15.isSupported(ChronoField.NANO_OF_DAY));
|
||||
assertEquals(false, TEST_07_15.isSupported(ChronoField.MICRO_OF_SECOND));
|
||||
assertEquals(false, TEST_07_15.isSupported(ChronoField.MICRO_OF_DAY));
|
||||
assertEquals(false, TEST_07_15.isSupported(ChronoField.MILLI_OF_SECOND));
|
||||
assertEquals(false, TEST_07_15.isSupported(ChronoField.MILLI_OF_DAY));
|
||||
assertEquals(false, TEST_07_15.isSupported(ChronoField.SECOND_OF_MINUTE));
|
||||
assertEquals(false, TEST_07_15.isSupported(ChronoField.SECOND_OF_DAY));
|
||||
assertEquals(false, TEST_07_15.isSupported(ChronoField.MINUTE_OF_HOUR));
|
||||
assertEquals(false, TEST_07_15.isSupported(ChronoField.MINUTE_OF_DAY));
|
||||
assertEquals(false, TEST_07_15.isSupported(ChronoField.HOUR_OF_AMPM));
|
||||
assertEquals(false, TEST_07_15.isSupported(ChronoField.CLOCK_HOUR_OF_AMPM));
|
||||
assertEquals(false, TEST_07_15.isSupported(ChronoField.HOUR_OF_DAY));
|
||||
assertEquals(false, TEST_07_15.isSupported(ChronoField.CLOCK_HOUR_OF_DAY));
|
||||
assertEquals(false, TEST_07_15.isSupported(ChronoField.AMPM_OF_DAY));
|
||||
assertEquals(false, TEST_07_15.isSupported(ChronoField.DAY_OF_WEEK));
|
||||
assertEquals(false, TEST_07_15.isSupported(ChronoField.ALIGNED_DAY_OF_WEEK_IN_MONTH));
|
||||
assertEquals(false, TEST_07_15.isSupported(ChronoField.ALIGNED_DAY_OF_WEEK_IN_YEAR));
|
||||
assertEquals(true, TEST_07_15.isSupported(ChronoField.DAY_OF_MONTH));
|
||||
assertEquals(false, TEST_07_15.isSupported(ChronoField.DAY_OF_YEAR));
|
||||
assertEquals(false, TEST_07_15.isSupported(ChronoField.EPOCH_DAY));
|
||||
assertEquals(false, TEST_07_15.isSupported(ChronoField.ALIGNED_WEEK_OF_MONTH));
|
||||
assertEquals(false, TEST_07_15.isSupported(ChronoField.ALIGNED_WEEK_OF_YEAR));
|
||||
assertEquals(true, TEST_07_15.isSupported(ChronoField.MONTH_OF_YEAR));
|
||||
assertEquals(false, TEST_07_15.isSupported(ChronoField.PROLEPTIC_MONTH));
|
||||
assertEquals(false, TEST_07_15.isSupported(ChronoField.YEAR));
|
||||
assertEquals(false, TEST_07_15.isSupported(ChronoField.YEAR_OF_ERA));
|
||||
assertEquals(false, TEST_07_15.isSupported(ChronoField.ERA));
|
||||
assertEquals(false, TEST_07_15.isSupported(ChronoField.INSTANT_SECONDS));
|
||||
assertEquals(false, TEST_07_15.isSupported(ChronoField.OFFSET_SECONDS));
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
@ -413,20 +420,19 @@ public class TCKMonthDay extends AbstractDateTimeTest {
|
||||
//-----------------------------------------------------------------------
|
||||
@Test
|
||||
public void test_get_TemporalField() {
|
||||
assertEquals(TEST_07_15.get(ChronoField.DAY_OF_MONTH), 15);
|
||||
assertEquals(TEST_07_15.get(ChronoField.MONTH_OF_YEAR), 7);
|
||||
assertEquals(15, TEST_07_15.get(ChronoField.DAY_OF_MONTH));
|
||||
assertEquals(7, TEST_07_15.get(ChronoField.MONTH_OF_YEAR));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test_getLong_TemporalField() {
|
||||
assertEquals(TEST_07_15.getLong(ChronoField.DAY_OF_MONTH), 15);
|
||||
assertEquals(TEST_07_15.getLong(ChronoField.MONTH_OF_YEAR), 7);
|
||||
assertEquals(15, TEST_07_15.getLong(ChronoField.DAY_OF_MONTH));
|
||||
assertEquals(7, TEST_07_15.getLong(ChronoField.MONTH_OF_YEAR));
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
// query(TemporalQuery)
|
||||
//-----------------------------------------------------------------------
|
||||
@DataProvider(name="query")
|
||||
Object[][] data_query() {
|
||||
return new Object[][] {
|
||||
{TEST_07_15, TemporalQueries.chronology(), IsoChronology.INSTANCE},
|
||||
@ -439,25 +445,26 @@ public class TCKMonthDay extends AbstractDateTimeTest {
|
||||
};
|
||||
}
|
||||
|
||||
@Test(dataProvider="query")
|
||||
@ParameterizedTest
|
||||
@MethodSource("data_query")
|
||||
public <T> void test_query(TemporalAccessor temporal, TemporalQuery<T> query, T expected) {
|
||||
assertEquals(temporal.query(query), expected);
|
||||
assertEquals(expected, temporal.query(query));
|
||||
}
|
||||
|
||||
@Test(dataProvider="query")
|
||||
@ParameterizedTest
|
||||
@MethodSource("data_query")
|
||||
public <T> void test_queryFrom(TemporalAccessor temporal, TemporalQuery<T> query, T expected) {
|
||||
assertEquals(query.queryFrom(temporal), expected);
|
||||
assertEquals(expected, query.queryFrom(temporal));
|
||||
}
|
||||
|
||||
@Test(expectedExceptions=NullPointerException.class)
|
||||
@Test
|
||||
public void test_query_null() {
|
||||
TEST_07_15.query(null);
|
||||
Assertions.assertThrows(NullPointerException.class, () -> TEST_07_15.query(null));
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
// get*()
|
||||
//-----------------------------------------------------------------------
|
||||
@DataProvider(name="sampleDates")
|
||||
Object[][] provider_sampleDates() {
|
||||
return new Object[][] {
|
||||
{1, 1},
|
||||
@ -470,12 +477,13 @@ public class TCKMonthDay extends AbstractDateTimeTest {
|
||||
};
|
||||
}
|
||||
|
||||
@Test(dataProvider="sampleDates")
|
||||
@ParameterizedTest
|
||||
@MethodSource("provider_sampleDates")
|
||||
public void test_get(int m, int d) {
|
||||
MonthDay a = MonthDay.of(m, d);
|
||||
assertEquals(a.getMonth(), Month.of(m));
|
||||
assertEquals(a.getMonthValue(), m);
|
||||
assertEquals(a.getDayOfMonth(), d);
|
||||
assertEquals(Month.of(m), a.getMonth());
|
||||
assertEquals(m, a.getMonthValue());
|
||||
assertEquals(d, a.getDayOfMonth());
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
@ -483,28 +491,28 @@ public class TCKMonthDay extends AbstractDateTimeTest {
|
||||
//-----------------------------------------------------------------------
|
||||
@Test
|
||||
public void test_with_Month() {
|
||||
assertEquals(MonthDay.of(6, 30).with(Month.JANUARY), MonthDay.of(1, 30));
|
||||
assertEquals(MonthDay.of(1, 30), MonthDay.of(6, 30).with(Month.JANUARY));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test_with_Month_adjustToValid() {
|
||||
assertEquals(MonthDay.of(7, 31).with(Month.JUNE), MonthDay.of(6, 30));
|
||||
assertEquals(MonthDay.of(6, 30), MonthDay.of(7, 31).with(Month.JUNE));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test_with_Month_adjustToValidFeb() {
|
||||
assertEquals(MonthDay.of(7, 31).with(Month.FEBRUARY), MonthDay.of(2, 29));
|
||||
assertEquals(MonthDay.of(2, 29), MonthDay.of(7, 31).with(Month.FEBRUARY));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test_with_Month_noChangeEqual() {
|
||||
MonthDay test = MonthDay.of(6, 30);
|
||||
assertEquals(test.with(Month.JUNE), test);
|
||||
assertEquals(test, test.with(Month.JUNE));
|
||||
}
|
||||
|
||||
@Test(expectedExceptions=NullPointerException.class)
|
||||
@Test
|
||||
public void test_with_Month_null() {
|
||||
MonthDay.of(6, 30).with((Month) null);
|
||||
Assertions.assertThrows(NullPointerException.class, () -> MonthDay.of(6, 30).with((Month) null));
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
@ -512,33 +520,33 @@ public class TCKMonthDay extends AbstractDateTimeTest {
|
||||
//-----------------------------------------------------------------------
|
||||
@Test
|
||||
public void test_withMonth() {
|
||||
assertEquals(MonthDay.of(6, 30).withMonth(1), MonthDay.of(1, 30));
|
||||
assertEquals(MonthDay.of(1, 30), MonthDay.of(6, 30).withMonth(1));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test_withMonth_adjustToValid() {
|
||||
assertEquals(MonthDay.of(7, 31).withMonth(6), MonthDay.of(6, 30));
|
||||
assertEquals(MonthDay.of(6, 30), MonthDay.of(7, 31).withMonth(6));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test_withMonth_adjustToValidFeb() {
|
||||
assertEquals(MonthDay.of(7, 31).withMonth(2), MonthDay.of(2, 29));
|
||||
assertEquals(MonthDay.of(2, 29), MonthDay.of(7, 31).withMonth(2));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test_withMonth_int_noChangeEqual() {
|
||||
MonthDay test = MonthDay.of(6, 30);
|
||||
assertEquals(test.withMonth(6), test);
|
||||
assertEquals(test, test.withMonth(6));
|
||||
}
|
||||
|
||||
@Test(expectedExceptions=DateTimeException.class)
|
||||
@Test
|
||||
public void test_withMonth_tooLow() {
|
||||
MonthDay.of(6, 30).withMonth(0);
|
||||
Assertions.assertThrows(DateTimeException.class, () -> MonthDay.of(6, 30).withMonth(0));
|
||||
}
|
||||
|
||||
@Test(expectedExceptions=DateTimeException.class)
|
||||
@Test
|
||||
public void test_withMonth_tooHigh() {
|
||||
MonthDay.of(6, 30).withMonth(13);
|
||||
Assertions.assertThrows(DateTimeException.class, () -> MonthDay.of(6, 30).withMonth(13));
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
@ -546,33 +554,33 @@ public class TCKMonthDay extends AbstractDateTimeTest {
|
||||
//-----------------------------------------------------------------------
|
||||
@Test
|
||||
public void test_withDayOfMonth() {
|
||||
assertEquals(MonthDay.of(6, 30).withDayOfMonth(1), MonthDay.of(6, 1));
|
||||
assertEquals(MonthDay.of(6, 1), MonthDay.of(6, 30).withDayOfMonth(1));
|
||||
}
|
||||
|
||||
@Test(expectedExceptions=DateTimeException.class)
|
||||
@Test
|
||||
public void test_withDayOfMonth_invalid() {
|
||||
MonthDay.of(6, 30).withDayOfMonth(31);
|
||||
Assertions.assertThrows(DateTimeException.class, () -> MonthDay.of(6, 30).withDayOfMonth(31));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test_withDayOfMonth_adjustToValidFeb() {
|
||||
assertEquals(MonthDay.of(2, 1).withDayOfMonth(29), MonthDay.of(2, 29));
|
||||
assertEquals(MonthDay.of(2, 29), MonthDay.of(2, 1).withDayOfMonth(29));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test_withDayOfMonth_noChangeEqual() {
|
||||
MonthDay test = MonthDay.of(6, 30);
|
||||
assertEquals(test.withDayOfMonth(30), test);
|
||||
assertEquals(test, test.withDayOfMonth(30));
|
||||
}
|
||||
|
||||
@Test(expectedExceptions=DateTimeException.class)
|
||||
@Test
|
||||
public void test_withDayOfMonth_tooLow() {
|
||||
MonthDay.of(6, 30).withDayOfMonth(0);
|
||||
Assertions.assertThrows(DateTimeException.class, () -> MonthDay.of(6, 30).withDayOfMonth(0));
|
||||
}
|
||||
|
||||
@Test(expectedExceptions=DateTimeException.class)
|
||||
@Test
|
||||
public void test_withDayOfMonth_tooHigh() {
|
||||
MonthDay.of(6, 30).withDayOfMonth(32);
|
||||
Assertions.assertThrows(DateTimeException.class, () -> MonthDay.of(6, 30).withDayOfMonth(32));
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
@ -582,26 +590,26 @@ public class TCKMonthDay extends AbstractDateTimeTest {
|
||||
public void test_adjustDate() {
|
||||
MonthDay test = MonthDay.of(6, 30);
|
||||
LocalDate date = LocalDate.of(2007, 1, 1);
|
||||
assertEquals(test.adjustInto(date), LocalDate.of(2007, 6, 30));
|
||||
assertEquals(LocalDate.of(2007, 6, 30), test.adjustInto(date));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test_adjustDate_resolve() {
|
||||
MonthDay test = MonthDay.of(2, 29);
|
||||
LocalDate date = LocalDate.of(2007, 6, 30);
|
||||
assertEquals(test.adjustInto(date), LocalDate.of(2007, 2, 28));
|
||||
assertEquals(LocalDate.of(2007, 2, 28), test.adjustInto(date));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test_adjustDate_equal() {
|
||||
MonthDay test = MonthDay.of(6, 30);
|
||||
LocalDate date = LocalDate.of(2007, 6, 30);
|
||||
assertEquals(test.adjustInto(date), date);
|
||||
assertEquals(date, test.adjustInto(date));
|
||||
}
|
||||
|
||||
@Test(expectedExceptions=NullPointerException.class)
|
||||
@Test
|
||||
public void test_adjustDate_null() {
|
||||
TEST_07_15.adjustInto((LocalDate) null);
|
||||
Assertions.assertThrows(NullPointerException.class, () -> TEST_07_15.adjustInto((LocalDate) null));
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
@ -610,19 +618,19 @@ public class TCKMonthDay extends AbstractDateTimeTest {
|
||||
@Test
|
||||
public void test_isValidYear_june() {
|
||||
MonthDay test = MonthDay.of(6, 30);
|
||||
assertEquals(test.isValidYear(2007), true);
|
||||
assertEquals(true, test.isValidYear(2007));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test_isValidYear_febNonLeap() {
|
||||
MonthDay test = MonthDay.of(2, 29);
|
||||
assertEquals(test.isValidYear(2007), false);
|
||||
assertEquals(false, test.isValidYear(2007));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test_isValidYear_febLeap() {
|
||||
MonthDay test = MonthDay.of(2, 29);
|
||||
assertEquals(test.isValidYear(2008), true);
|
||||
assertEquals(true, test.isValidYear(2008));
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
@ -632,12 +640,12 @@ public class TCKMonthDay extends AbstractDateTimeTest {
|
||||
public void test_format_formatter() {
|
||||
DateTimeFormatter f = DateTimeFormatter.ofPattern("M d");
|
||||
String t = MonthDay.of(12, 3).format(f);
|
||||
assertEquals(t, "12 3");
|
||||
assertEquals("12 3", t);
|
||||
}
|
||||
|
||||
@Test(expectedExceptions=NullPointerException.class)
|
||||
@Test
|
||||
public void test_format_formatter_null() {
|
||||
MonthDay.of(12, 3).format(null);
|
||||
Assertions.assertThrows(NullPointerException.class, () -> MonthDay.of(12, 3).format(null));
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
@ -646,19 +654,21 @@ public class TCKMonthDay extends AbstractDateTimeTest {
|
||||
@Test
|
||||
public void test_atYear_int() {
|
||||
MonthDay test = MonthDay.of(6, 30);
|
||||
assertEquals(test.atYear(2008), LocalDate.of(2008, 6, 30));
|
||||
assertEquals(LocalDate.of(2008, 6, 30), test.atYear(2008));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test_atYear_int_leapYearAdjust() {
|
||||
MonthDay test = MonthDay.of(2, 29);
|
||||
assertEquals(test.atYear(2005), LocalDate.of(2005, 2, 28));
|
||||
assertEquals(LocalDate.of(2005, 2, 28), test.atYear(2005));
|
||||
}
|
||||
|
||||
@Test(expectedExceptions=DateTimeException.class)
|
||||
@Test
|
||||
public void test_atYear_int_invalidYear() {
|
||||
MonthDay test = MonthDay.of(6, 30);
|
||||
test.atYear(Integer.MIN_VALUE);
|
||||
Assertions.assertThrows(DateTimeException.class, () -> {
|
||||
MonthDay test = MonthDay.of(6, 30);
|
||||
test.atYear(Integer.MIN_VALUE);
|
||||
});
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
@ -683,37 +693,37 @@ public class TCKMonthDay extends AbstractDateTimeTest {
|
||||
MonthDay b = localDates[j];
|
||||
if (i < j) {
|
||||
assertTrue(a.compareTo(b) < 0, a + " <=> " + b);
|
||||
assertEquals(a.isBefore(b), true, a + " <=> " + b);
|
||||
assertEquals(a.isAfter(b), false, a + " <=> " + b);
|
||||
assertEquals(a.equals(b), false, a + " <=> " + b);
|
||||
assertEquals(true, a.isBefore(b), a + " <=> " + b);
|
||||
assertEquals(false, a.isAfter(b), a + " <=> " + b);
|
||||
assertEquals(false, a.equals(b), a + " <=> " + b);
|
||||
} else if (i > j) {
|
||||
assertTrue(a.compareTo(b) > 0, a + " <=> " + b);
|
||||
assertEquals(a.isBefore(b), false, a + " <=> " + b);
|
||||
assertEquals(a.isAfter(b), true, a + " <=> " + b);
|
||||
assertEquals(a.equals(b), false, a + " <=> " + b);
|
||||
assertEquals(false, a.isBefore(b), a + " <=> " + b);
|
||||
assertEquals(true, a.isAfter(b), a + " <=> " + b);
|
||||
assertEquals(false, a.equals(b), a + " <=> " + b);
|
||||
} else {
|
||||
assertEquals(a.compareTo(b), 0, a + " <=> " + b);
|
||||
assertEquals(a.isBefore(b), false, a + " <=> " + b);
|
||||
assertEquals(a.isAfter(b), false, a + " <=> " + b);
|
||||
assertEquals(a.equals(b), true, a + " <=> " + b);
|
||||
assertEquals(0, a.compareTo(b), a + " <=> " + b);
|
||||
assertEquals(false, a.isBefore(b), a + " <=> " + b);
|
||||
assertEquals(false, a.isAfter(b), a + " <=> " + b);
|
||||
assertEquals(true, a.equals(b), a + " <=> " + b);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Test(expectedExceptions=NullPointerException.class)
|
||||
@Test
|
||||
public void test_compareTo_ObjectNull() {
|
||||
TEST_07_15.compareTo(null);
|
||||
Assertions.assertThrows(NullPointerException.class, () -> TEST_07_15.compareTo(null));
|
||||
}
|
||||
|
||||
@Test(expectedExceptions=NullPointerException.class)
|
||||
@Test
|
||||
public void test_isBefore_ObjectNull() {
|
||||
TEST_07_15.isBefore(null);
|
||||
Assertions.assertThrows(NullPointerException.class, () -> TEST_07_15.isBefore(null));
|
||||
}
|
||||
|
||||
@Test(expectedExceptions=NullPointerException.class)
|
||||
@Test
|
||||
public void test_isAfter_ObjectNull() {
|
||||
TEST_07_15.isAfter(null);
|
||||
Assertions.assertThrows(NullPointerException.class, () -> TEST_07_15.isAfter(null));
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
@ -726,51 +736,52 @@ public class TCKMonthDay extends AbstractDateTimeTest {
|
||||
MonthDay c = MonthDay.of(2, 1);
|
||||
MonthDay d = MonthDay.of(1, 2);
|
||||
|
||||
assertEquals(a.equals(a), true);
|
||||
assertEquals(a.equals(b), true);
|
||||
assertEquals(a.equals(c), false);
|
||||
assertEquals(a.equals(d), false);
|
||||
assertEquals(true, a.equals(a));
|
||||
assertEquals(true, a.equals(b));
|
||||
assertEquals(false, a.equals(c));
|
||||
assertEquals(false, a.equals(d));
|
||||
|
||||
assertEquals(b.equals(a), true);
|
||||
assertEquals(b.equals(b), true);
|
||||
assertEquals(b.equals(c), false);
|
||||
assertEquals(b.equals(d), false);
|
||||
assertEquals(true, b.equals(a));
|
||||
assertEquals(true, b.equals(b));
|
||||
assertEquals(false, b.equals(c));
|
||||
assertEquals(false, b.equals(d));
|
||||
|
||||
assertEquals(c.equals(a), false);
|
||||
assertEquals(c.equals(b), false);
|
||||
assertEquals(c.equals(c), true);
|
||||
assertEquals(c.equals(d), false);
|
||||
assertEquals(false, c.equals(a));
|
||||
assertEquals(false, c.equals(b));
|
||||
assertEquals(true, c.equals(c));
|
||||
assertEquals(false, c.equals(d));
|
||||
|
||||
assertEquals(d.equals(a), false);
|
||||
assertEquals(d.equals(b), false);
|
||||
assertEquals(d.equals(c), false);
|
||||
assertEquals(d.equals(d), true);
|
||||
assertEquals(false, d.equals(a));
|
||||
assertEquals(false, d.equals(b));
|
||||
assertEquals(false, d.equals(c));
|
||||
assertEquals(true, d.equals(d));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test_equals_itself_true() {
|
||||
assertEquals(TEST_07_15.equals(TEST_07_15), true);
|
||||
assertEquals(true, TEST_07_15.equals(TEST_07_15));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test_equals_string_false() {
|
||||
assertEquals(TEST_07_15.equals("2007-07-15"), false);
|
||||
assertEquals(false, TEST_07_15.equals("2007-07-15"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test_equals_null_false() {
|
||||
assertEquals(TEST_07_15.equals(null), false);
|
||||
assertEquals(false, TEST_07_15.equals(null));
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
// hashCode()
|
||||
//-----------------------------------------------------------------------
|
||||
@Test(dataProvider="sampleDates")
|
||||
@ParameterizedTest
|
||||
@MethodSource("provider_sampleDates")
|
||||
public void test_hashCode(int m, int d) {
|
||||
MonthDay a = MonthDay.of(m, d);
|
||||
assertEquals(a.hashCode(), a.hashCode());
|
||||
MonthDay b = MonthDay.of(m, d);
|
||||
assertEquals(a.hashCode(), b.hashCode());
|
||||
assertEquals(b.hashCode(), a.hashCode());
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -789,7 +800,6 @@ public class TCKMonthDay extends AbstractDateTimeTest {
|
||||
//-----------------------------------------------------------------------
|
||||
// toString()
|
||||
//-----------------------------------------------------------------------
|
||||
@DataProvider(name="sampleToString")
|
||||
Object[][] provider_sampleToString() {
|
||||
return new Object[][] {
|
||||
{7, 5, "--07-05"},
|
||||
@ -798,11 +808,12 @@ public class TCKMonthDay extends AbstractDateTimeTest {
|
||||
};
|
||||
}
|
||||
|
||||
@Test(dataProvider="sampleToString")
|
||||
@ParameterizedTest
|
||||
@MethodSource("provider_sampleToString")
|
||||
public void test_toString(int m, int d, String expected) {
|
||||
MonthDay test = MonthDay.of(m, d);
|
||||
String str = test.toString();
|
||||
assertEquals(str, expected);
|
||||
assertEquals(expected, str);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2012, 2013, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2012, 2025, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
@ -62,7 +62,8 @@ package tck.java.time;
|
||||
import static java.time.temporal.ChronoUnit.DAYS;
|
||||
import static java.time.temporal.ChronoUnit.HOURS;
|
||||
import static java.time.temporal.ChronoUnit.YEARS;
|
||||
import static org.testng.Assert.assertEquals;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
|
||||
import java.time.DateTimeException;
|
||||
import java.time.Duration;
|
||||
@ -79,13 +80,16 @@ import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
|
||||
import org.testng.annotations.DataProvider;
|
||||
import org.testng.annotations.Test;
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.TestInstance;
|
||||
import org.junit.jupiter.params.ParameterizedTest;
|
||||
import org.junit.jupiter.params.provider.MethodSource;
|
||||
|
||||
/**
|
||||
* Test Period.
|
||||
*/
|
||||
@Test
|
||||
@TestInstance(TestInstance.Lifecycle.PER_CLASS)
|
||||
public class TCKPeriod extends AbstractTCKTest {
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
@ -191,78 +195,81 @@ public class TCKPeriod extends AbstractTCKTest {
|
||||
assertPeriod(Period.from(amount), 23, 0, 45);
|
||||
}
|
||||
|
||||
@Test(expectedExceptions = ArithmeticException.class)
|
||||
@Test
|
||||
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);
|
||||
}
|
||||
|
||||
@Test(expectedExceptions = DateTimeException.class)
|
||||
public void factory_from_TemporalAmount_DaysHours() {
|
||||
TemporalAmount amount = new TemporalAmount() {
|
||||
@Override
|
||||
public long get(TemporalUnit unit) {
|
||||
if (unit == DAYS) {
|
||||
return 1;
|
||||
} else {
|
||||
return 2;
|
||||
Assertions.assertThrows(ArithmeticException.class, () -> {
|
||||
TemporalAmount amount = new TemporalAmount() {
|
||||
@Override
|
||||
public long get(TemporalUnit unit) {
|
||||
return ((long) (Integer.MAX_VALUE)) + 1;
|
||||
}
|
||||
}
|
||||
@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();
|
||||
}
|
||||
};
|
||||
Period.from(amount);
|
||||
@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);
|
||||
});
|
||||
}
|
||||
|
||||
@Test(expectedExceptions = DateTimeException.class)
|
||||
@Test
|
||||
public void factory_from_TemporalAmount_DaysHours() {
|
||||
Assertions.assertThrows(DateTimeException.class, () -> {
|
||||
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();
|
||||
}
|
||||
};
|
||||
Period.from(amount);
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
public void factory_from_TemporalAmount_NonISO() {
|
||||
Period.from(ThaiBuddhistChronology.INSTANCE.period(1, 1, 1));
|
||||
Assertions.assertThrows(DateTimeException.class, () -> Period.from(ThaiBuddhistChronology.INSTANCE.period(1, 1, 1)));
|
||||
}
|
||||
|
||||
@Test(expectedExceptions = DateTimeException.class)
|
||||
@Test
|
||||
public void factory_from_TemporalAmount_Duration() {
|
||||
Period.from(Duration.ZERO);
|
||||
Assertions.assertThrows(DateTimeException.class, () -> Period.from(Duration.ZERO));
|
||||
}
|
||||
|
||||
@Test(expectedExceptions = NullPointerException.class)
|
||||
@Test
|
||||
public void factory_from_TemporalAmount_null() {
|
||||
Period.from(null);
|
||||
Assertions.assertThrows(NullPointerException.class, () -> Period.from(null));
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
// parse(String)
|
||||
//-----------------------------------------------------------------------
|
||||
@DataProvider(name="parseSuccess")
|
||||
Object[][] data_factory_parseSuccess() {
|
||||
return new Object[][] {
|
||||
{"P1Y", Period.ofYears(1)},
|
||||
@ -335,40 +342,43 @@ public class TCKPeriod extends AbstractTCKTest {
|
||||
};
|
||||
}
|
||||
|
||||
@Test(dataProvider="parseSuccess")
|
||||
@ParameterizedTest
|
||||
@MethodSource("data_factory_parseSuccess")
|
||||
public void factory_parse(String text, Period expected) {
|
||||
Period p = Period.parse(text);
|
||||
assertEquals(p, expected);
|
||||
assertEquals(expected, p);
|
||||
}
|
||||
|
||||
@Test(dataProvider="parseSuccess")
|
||||
@ParameterizedTest
|
||||
@MethodSource("data_factory_parseSuccess")
|
||||
public void factory_parse_plus(String text, Period expected) {
|
||||
Period p = Period.parse("+" + text);
|
||||
assertEquals(p, expected);
|
||||
assertEquals(expected, p);
|
||||
}
|
||||
|
||||
@Test(dataProvider="parseSuccess")
|
||||
@ParameterizedTest
|
||||
@MethodSource("data_factory_parseSuccess")
|
||||
public void factory_parse_minus(String text, Period expected) {
|
||||
Period p = null;
|
||||
try {
|
||||
p = Period.parse("-" + text);
|
||||
} catch (DateTimeParseException ex) {
|
||||
assertEquals(expected.getYears() == Integer.MIN_VALUE ||
|
||||
assertEquals(true, expected.getYears() == Integer.MIN_VALUE ||
|
||||
expected.getMonths() == Integer.MIN_VALUE ||
|
||||
expected.getDays() == Integer.MIN_VALUE, true);
|
||||
expected.getDays() == Integer.MIN_VALUE);
|
||||
return;
|
||||
}
|
||||
// not inside try/catch or it breaks test
|
||||
assertEquals(p, expected.negated());
|
||||
assertEquals(expected.negated(), p);
|
||||
}
|
||||
|
||||
@Test(dataProvider="parseSuccess")
|
||||
@ParameterizedTest
|
||||
@MethodSource("data_factory_parseSuccess")
|
||||
public void factory_parse_lowerCase(String text, Period expected) {
|
||||
Period p = Period.parse(text.toLowerCase(Locale.ENGLISH));
|
||||
assertEquals(p, expected);
|
||||
assertEquals(expected, p);
|
||||
}
|
||||
|
||||
@DataProvider(name="parseFailure")
|
||||
Object[][] data_parseFailure() {
|
||||
return new Object[][] {
|
||||
{""},
|
||||
@ -417,25 +427,27 @@ public class TCKPeriod extends AbstractTCKTest {
|
||||
};
|
||||
}
|
||||
|
||||
@Test(dataProvider="parseFailure", expectedExceptions=DateTimeParseException.class)
|
||||
@ParameterizedTest
|
||||
@MethodSource("data_parseFailure")
|
||||
public void factory_parseFailures(String text) {
|
||||
try {
|
||||
Period.parse(text);
|
||||
} catch (DateTimeParseException ex) {
|
||||
assertEquals(ex.getParsedString(), text);
|
||||
throw ex;
|
||||
}
|
||||
Assertions.assertThrows(DateTimeParseException.class, () -> {
|
||||
try {
|
||||
Period.parse(text);
|
||||
} catch (DateTimeParseException ex) {
|
||||
assertEquals(text, ex.getParsedString());
|
||||
throw ex;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Test(expectedExceptions=NullPointerException.class)
|
||||
@Test
|
||||
public void factory_parse_null() {
|
||||
Period.parse(null);
|
||||
Assertions.assertThrows(NullPointerException.class, () -> Period.parse(null));
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
// between(LocalDate,LocalDate)
|
||||
//-----------------------------------------------------------------------
|
||||
@DataProvider(name="between")
|
||||
Object[][] data_between() {
|
||||
return new Object[][] {
|
||||
{2010, 1, 1, 2010, 1, 1, 0, 0, 0},
|
||||
@ -522,7 +534,8 @@ public class TCKPeriod extends AbstractTCKTest {
|
||||
};
|
||||
}
|
||||
|
||||
@Test(dataProvider="between")
|
||||
@ParameterizedTest
|
||||
@MethodSource("data_between")
|
||||
public void factory_between_LocalDate(int y1, int m1, int d1, int y2, int m2, int d2, int ye, int me, int de) {
|
||||
LocalDate start = LocalDate.of(y1, m1, d1);
|
||||
LocalDate end = LocalDate.of(y2, m2, d2);
|
||||
@ -531,14 +544,14 @@ public class TCKPeriod extends AbstractTCKTest {
|
||||
//assertEquals(start.plus(test), end);
|
||||
}
|
||||
|
||||
@Test(expectedExceptions=NullPointerException.class)
|
||||
@Test
|
||||
public void factory_between_LocalDate_nullFirst() {
|
||||
Period.between((LocalDate) null, LocalDate.of(2010, 1, 1));
|
||||
Assertions.assertThrows(NullPointerException.class, () -> Period.between((LocalDate) null, LocalDate.of(2010, 1, 1)));
|
||||
}
|
||||
|
||||
@Test(expectedExceptions=NullPointerException.class)
|
||||
@Test
|
||||
public void factory_between_LocalDate_nullSecond() {
|
||||
Period.between(LocalDate.of(2010, 1, 1), (LocalDate) null);
|
||||
Assertions.assertThrows(NullPointerException.class, () -> Period.between(LocalDate.of(2010, 1, 1), (LocalDate) null));
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
@ -546,11 +559,11 @@ public class TCKPeriod extends AbstractTCKTest {
|
||||
//-----------------------------------------------------------------------
|
||||
@Test
|
||||
public void test_isZero() {
|
||||
assertEquals(Period.of(0, 0, 0).isZero(), true);
|
||||
assertEquals(Period.of(1, 2, 3).isZero(), false);
|
||||
assertEquals(Period.of(1, 0, 0).isZero(), false);
|
||||
assertEquals(Period.of(0, 2, 0).isZero(), false);
|
||||
assertEquals(Period.of(0, 0, 3).isZero(), false);
|
||||
assertEquals(true, Period.of(0, 0, 0).isZero());
|
||||
assertEquals(false, Period.of(1, 2, 3).isZero());
|
||||
assertEquals(false, Period.of(1, 0, 0).isZero());
|
||||
assertEquals(false, Period.of(0, 2, 0).isZero());
|
||||
assertEquals(false, Period.of(0, 0, 3).isZero());
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
@ -558,19 +571,19 @@ public class TCKPeriod extends AbstractTCKTest {
|
||||
//-----------------------------------------------------------------------
|
||||
@Test
|
||||
public void test_isPositive() {
|
||||
assertEquals(Period.of(0, 0, 0).isNegative(), false);
|
||||
assertEquals(Period.of(1, 2, 3).isNegative(), false);
|
||||
assertEquals(Period.of(1, 0, 0).isNegative(), false);
|
||||
assertEquals(Period.of(0, 2, 0).isNegative(), false);
|
||||
assertEquals(Period.of(0, 0, 3).isNegative(), false);
|
||||
assertEquals(false, Period.of(0, 0, 0).isNegative());
|
||||
assertEquals(false, Period.of(1, 2, 3).isNegative());
|
||||
assertEquals(false, Period.of(1, 0, 0).isNegative());
|
||||
assertEquals(false, Period.of(0, 2, 0).isNegative());
|
||||
assertEquals(false, Period.of(0, 0, 3).isNegative());
|
||||
|
||||
assertEquals(Period.of(-1, -2, -3).isNegative(), true);
|
||||
assertEquals(Period.of(-1, -2, 3).isNegative(), true);
|
||||
assertEquals(Period.of(1, -2, -3).isNegative(), true);
|
||||
assertEquals(Period.of(-1, 2, -3).isNegative(), true);
|
||||
assertEquals(Period.of(-1, 2, 3).isNegative(), true);
|
||||
assertEquals(Period.of(1, -2, 3).isNegative(), true);
|
||||
assertEquals(Period.of(1, 2, -3).isNegative(), true);
|
||||
assertEquals(true, Period.of(-1, -2, -3).isNegative());
|
||||
assertEquals(true, Period.of(-1, -2, 3).isNegative());
|
||||
assertEquals(true, Period.of(1, -2, -3).isNegative());
|
||||
assertEquals(true, Period.of(-1, 2, -3).isNegative());
|
||||
assertEquals(true, Period.of(-1, 2, 3).isNegative());
|
||||
assertEquals(true, Period.of(1, -2, 3).isNegative());
|
||||
assertEquals(true, Period.of(1, 2, -3).isNegative());
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
@ -612,7 +625,6 @@ public class TCKPeriod extends AbstractTCKTest {
|
||||
//-----------------------------------------------------------------------
|
||||
// plus(Period)
|
||||
//-----------------------------------------------------------------------
|
||||
@DataProvider(name="plus")
|
||||
Object[][] data_plus() {
|
||||
return new Object[][] {
|
||||
{pymd(0, 0, 0), pymd(0, 0, 0), pymd(0, 0, 0)},
|
||||
@ -630,44 +642,47 @@ public class TCKPeriod extends AbstractTCKTest {
|
||||
};
|
||||
}
|
||||
|
||||
@Test(dataProvider="plus")
|
||||
@ParameterizedTest
|
||||
@MethodSource("data_plus")
|
||||
public void test_plus_TemporalAmount(Period base, Period add, Period expected) {
|
||||
assertEquals(base.plus(add), expected);
|
||||
assertEquals(expected, base.plus(add));
|
||||
}
|
||||
|
||||
@Test(expectedExceptions = DateTimeException.class)
|
||||
@Test
|
||||
public void test_plus_TemporalAmount_nonISO() {
|
||||
pymd(4, 5, 6).plus(ThaiBuddhistChronology.INSTANCE.period(1, 0, 0));
|
||||
Assertions.assertThrows(DateTimeException.class, () -> pymd(4, 5, 6).plus(ThaiBuddhistChronology.INSTANCE.period(1, 0, 0)));
|
||||
}
|
||||
|
||||
@Test(expectedExceptions = DateTimeException.class)
|
||||
@Test
|
||||
public void test_plus_TemporalAmount_DaysHours() {
|
||||
TemporalAmount amount = new TemporalAmount() {
|
||||
@Override
|
||||
public long get(TemporalUnit unit) {
|
||||
if (unit == DAYS) {
|
||||
return 1;
|
||||
} else {
|
||||
return 2;
|
||||
Assertions.assertThrows(DateTimeException.class, () -> {
|
||||
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);
|
||||
@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);
|
||||
});
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
@ -686,16 +701,20 @@ public class TCKPeriod extends AbstractTCKTest {
|
||||
assertPeriod(Period.of(1, 2, 3).plus(Period.ofYears(-1)), 0, 2, 3);
|
||||
}
|
||||
|
||||
@Test(expectedExceptions=ArithmeticException.class)
|
||||
@Test
|
||||
public void test_plusYears_overflowTooBig() {
|
||||
Period test = Period.ofYears(Integer.MAX_VALUE);
|
||||
test.plusYears(1);
|
||||
Assertions.assertThrows(ArithmeticException.class, () -> {
|
||||
Period test = Period.ofYears(Integer.MAX_VALUE);
|
||||
test.plusYears(1);
|
||||
});
|
||||
}
|
||||
|
||||
@Test(expectedExceptions=ArithmeticException.class)
|
||||
@Test
|
||||
public void test_plusYears_overflowTooSmall() {
|
||||
Period test = Period.ofYears(Integer.MIN_VALUE);
|
||||
test.plusYears(-1);
|
||||
Assertions.assertThrows(ArithmeticException.class, () -> {
|
||||
Period test = Period.ofYears(Integer.MIN_VALUE);
|
||||
test.plusYears(-1);
|
||||
});
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
@ -714,16 +733,20 @@ public class TCKPeriod extends AbstractTCKTest {
|
||||
assertPeriod(Period.of(1, 2, 3).plus(Period.ofMonths(-2)), 1, 0, 3);
|
||||
}
|
||||
|
||||
@Test(expectedExceptions=ArithmeticException.class)
|
||||
@Test
|
||||
public void test_plusMonths_overflowTooBig() {
|
||||
Period test = Period.ofMonths(Integer.MAX_VALUE);
|
||||
test.plusMonths(1);
|
||||
Assertions.assertThrows(ArithmeticException.class, () -> {
|
||||
Period test = Period.ofMonths(Integer.MAX_VALUE);
|
||||
test.plusMonths(1);
|
||||
});
|
||||
}
|
||||
|
||||
@Test(expectedExceptions=ArithmeticException.class)
|
||||
@Test
|
||||
public void test_plusMonths_overflowTooSmall() {
|
||||
Period test = Period.ofMonths(Integer.MIN_VALUE);
|
||||
test.plusMonths(-1);
|
||||
Assertions.assertThrows(ArithmeticException.class, () -> {
|
||||
Period test = Period.ofMonths(Integer.MIN_VALUE);
|
||||
test.plusMonths(-1);
|
||||
});
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
@ -742,22 +765,25 @@ public class TCKPeriod extends AbstractTCKTest {
|
||||
assertPeriod(Period.of(1, 2, 3).plus(Period.ofDays(-3)), 1, 2, 0);
|
||||
}
|
||||
|
||||
@Test(expectedExceptions=ArithmeticException.class)
|
||||
@Test
|
||||
public void test_plusDays_overflowTooBig() {
|
||||
Period test = Period.ofDays(Integer.MAX_VALUE);
|
||||
test.plusDays(1);
|
||||
Assertions.assertThrows(ArithmeticException.class, () -> {
|
||||
Period test = Period.ofDays(Integer.MAX_VALUE);
|
||||
test.plusDays(1);
|
||||
});
|
||||
}
|
||||
|
||||
@Test(expectedExceptions=ArithmeticException.class)
|
||||
@Test
|
||||
public void test_plusDays_overflowTooSmall() {
|
||||
Period test = Period.ofDays(Integer.MIN_VALUE);
|
||||
test.plusDays(-1);
|
||||
Assertions.assertThrows(ArithmeticException.class, () -> {
|
||||
Period test = Period.ofDays(Integer.MIN_VALUE);
|
||||
test.plusDays(-1);
|
||||
});
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
// minus(Period)
|
||||
//-----------------------------------------------------------------------
|
||||
@DataProvider(name="minus")
|
||||
Object[][] data_minus() {
|
||||
return new Object[][] {
|
||||
{pymd(0, 0, 0), pymd(0, 0, 0), pymd(0, 0, 0)},
|
||||
@ -775,44 +801,47 @@ public class TCKPeriod extends AbstractTCKTest {
|
||||
};
|
||||
}
|
||||
|
||||
@Test(dataProvider="minus")
|
||||
@ParameterizedTest
|
||||
@MethodSource("data_minus")
|
||||
public void test_minus_TemporalAmount(Period base, Period subtract, Period expected) {
|
||||
assertEquals(base.minus(subtract), expected);
|
||||
assertEquals(expected, base.minus(subtract));
|
||||
}
|
||||
|
||||
@Test(expectedExceptions = DateTimeException.class)
|
||||
@Test
|
||||
public void test_minus_TemporalAmount_nonISO() {
|
||||
pymd(4, 5, 6).minus(ThaiBuddhistChronology.INSTANCE.period(1, 0, 0));
|
||||
Assertions.assertThrows(DateTimeException.class, () -> pymd(4, 5, 6).minus(ThaiBuddhistChronology.INSTANCE.period(1, 0, 0)));
|
||||
}
|
||||
|
||||
@Test(expectedExceptions = DateTimeException.class)
|
||||
@Test
|
||||
public void test_minus_TemporalAmount_DaysHours() {
|
||||
TemporalAmount amount = new TemporalAmount() {
|
||||
@Override
|
||||
public long get(TemporalUnit unit) {
|
||||
if (unit == DAYS) {
|
||||
return 1;
|
||||
} else {
|
||||
return 2;
|
||||
Assertions.assertThrows(DateTimeException.class, () -> {
|
||||
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);
|
||||
@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);
|
||||
});
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
@ -831,16 +860,20 @@ public class TCKPeriod extends AbstractTCKTest {
|
||||
assertPeriod(Period.of(1, 2, 3).minus(Period.ofYears(-1)), 2, 2, 3);
|
||||
}
|
||||
|
||||
@Test(expectedExceptions=ArithmeticException.class)
|
||||
@Test
|
||||
public void test_minusYears_overflowTooBig() {
|
||||
Period test = Period.ofYears(Integer.MAX_VALUE);
|
||||
test.minusYears(-1);
|
||||
Assertions.assertThrows(ArithmeticException.class, () -> {
|
||||
Period test = Period.ofYears(Integer.MAX_VALUE);
|
||||
test.minusYears(-1);
|
||||
});
|
||||
}
|
||||
|
||||
@Test(expectedExceptions=ArithmeticException.class)
|
||||
@Test
|
||||
public void test_minusYears_overflowTooSmall() {
|
||||
Period test = Period.ofYears(Integer.MIN_VALUE);
|
||||
test.minusYears(1);
|
||||
Assertions.assertThrows(ArithmeticException.class, () -> {
|
||||
Period test = Period.ofYears(Integer.MIN_VALUE);
|
||||
test.minusYears(1);
|
||||
});
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
@ -859,16 +892,20 @@ public class TCKPeriod extends AbstractTCKTest {
|
||||
assertPeriod(Period.of(1, 2, 3).minus(Period.ofMonths(-2)), 1, 4, 3);
|
||||
}
|
||||
|
||||
@Test(expectedExceptions=ArithmeticException.class)
|
||||
@Test
|
||||
public void test_minusMonths_overflowTooBig() {
|
||||
Period test = Period.ofMonths(Integer.MAX_VALUE);
|
||||
test.minusMonths(-1);
|
||||
Assertions.assertThrows(ArithmeticException.class, () -> {
|
||||
Period test = Period.ofMonths(Integer.MAX_VALUE);
|
||||
test.minusMonths(-1);
|
||||
});
|
||||
}
|
||||
|
||||
@Test(expectedExceptions=ArithmeticException.class)
|
||||
@Test
|
||||
public void test_minusMonths_overflowTooSmall() {
|
||||
Period test = Period.ofMonths(Integer.MIN_VALUE);
|
||||
test.minusMonths(1);
|
||||
Assertions.assertThrows(ArithmeticException.class, () -> {
|
||||
Period test = Period.ofMonths(Integer.MIN_VALUE);
|
||||
test.minusMonths(1);
|
||||
});
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
@ -887,16 +924,20 @@ public class TCKPeriod extends AbstractTCKTest {
|
||||
assertPeriod(Period.of(1, 2, 3).minus(Period.ofDays(-3)), 1, 2, 6);
|
||||
}
|
||||
|
||||
@Test(expectedExceptions=ArithmeticException.class)
|
||||
@Test
|
||||
public void test_minusDays_overflowTooBig() {
|
||||
Period test = Period.ofDays(Integer.MAX_VALUE);
|
||||
test.minusDays(-1);
|
||||
Assertions.assertThrows(ArithmeticException.class, () -> {
|
||||
Period test = Period.ofDays(Integer.MAX_VALUE);
|
||||
test.minusDays(-1);
|
||||
});
|
||||
}
|
||||
|
||||
@Test(expectedExceptions=ArithmeticException.class)
|
||||
@Test
|
||||
public void test_minusDays_overflowTooSmall() {
|
||||
Period test = Period.ofDays(Integer.MIN_VALUE);
|
||||
test.minusDays(1);
|
||||
Assertions.assertThrows(ArithmeticException.class, () -> {
|
||||
Period test = Period.ofDays(Integer.MIN_VALUE);
|
||||
test.minusDays(1);
|
||||
});
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
@ -916,16 +957,20 @@ public class TCKPeriod extends AbstractTCKTest {
|
||||
assertPeriod(Period.ZERO.multipliedBy(2), 0, 0, 0);
|
||||
}
|
||||
|
||||
@Test(expectedExceptions=ArithmeticException.class)
|
||||
@Test
|
||||
public void test_multipliedBy_overflowTooBig() {
|
||||
Period test = Period.ofYears(Integer.MAX_VALUE / 2 + 1);
|
||||
test.multipliedBy(2);
|
||||
Assertions.assertThrows(ArithmeticException.class, () -> {
|
||||
Period test = Period.ofYears(Integer.MAX_VALUE / 2 + 1);
|
||||
test.multipliedBy(2);
|
||||
});
|
||||
}
|
||||
|
||||
@Test(expectedExceptions=ArithmeticException.class)
|
||||
@Test
|
||||
public void test_multipliedBy_overflowTooSmall() {
|
||||
Period test = Period.ofYears(Integer.MIN_VALUE / 2 - 1);
|
||||
test.multipliedBy(2);
|
||||
Assertions.assertThrows(ArithmeticException.class, () -> {
|
||||
Period test = Period.ofYears(Integer.MIN_VALUE / 2 - 1);
|
||||
test.multipliedBy(2);
|
||||
});
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
@ -941,25 +986,24 @@ public class TCKPeriod extends AbstractTCKTest {
|
||||
-Integer.MAX_VALUE, -Integer.MAX_VALUE, -Integer.MAX_VALUE);
|
||||
}
|
||||
|
||||
@Test(expectedExceptions=ArithmeticException.class)
|
||||
@Test
|
||||
public void test_negated_overflow_years() {
|
||||
Period.ofYears(Integer.MIN_VALUE).negated();
|
||||
Assertions.assertThrows(ArithmeticException.class, () -> Period.ofYears(Integer.MIN_VALUE).negated());
|
||||
}
|
||||
|
||||
@Test(expectedExceptions=ArithmeticException.class)
|
||||
@Test
|
||||
public void test_negated_overflow_months() {
|
||||
Period.ofMonths(Integer.MIN_VALUE).negated();
|
||||
Assertions.assertThrows(ArithmeticException.class, () -> Period.ofMonths(Integer.MIN_VALUE).negated());
|
||||
}
|
||||
|
||||
@Test(expectedExceptions=ArithmeticException.class)
|
||||
@Test
|
||||
public void test_negated_overflow_days() {
|
||||
Period.ofDays(Integer.MIN_VALUE).negated();
|
||||
Assertions.assertThrows(ArithmeticException.class, () -> Period.ofDays(Integer.MIN_VALUE).negated());
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
// normalized()
|
||||
//-----------------------------------------------------------------------
|
||||
@DataProvider(name="normalized")
|
||||
Object[][] data_normalized() {
|
||||
return new Object[][] {
|
||||
{0, 0, 0, 0},
|
||||
@ -1002,32 +1046,37 @@ public class TCKPeriod extends AbstractTCKTest {
|
||||
};
|
||||
}
|
||||
|
||||
@Test(dataProvider="normalized")
|
||||
@ParameterizedTest
|
||||
@MethodSource("data_normalized")
|
||||
public void test_normalized(int inputYears, int inputMonths, int expectedYears, int expectedMonths) {
|
||||
assertPeriod(Period.of(inputYears, inputMonths, 0).normalized(), expectedYears, expectedMonths, 0);
|
||||
}
|
||||
|
||||
@Test(dataProvider="normalized")
|
||||
@ParameterizedTest
|
||||
@MethodSource("data_normalized")
|
||||
public void test_normalized_daysUnaffected(int inputYears, int inputMonths, int expectedYears, int expectedMonths) {
|
||||
assertPeriod(Period.of(inputYears, inputMonths, 5).normalized(), expectedYears, expectedMonths, 5);
|
||||
}
|
||||
|
||||
@Test(expectedExceptions=ArithmeticException.class)
|
||||
@Test
|
||||
public void test_normalized_min() {
|
||||
Period base = Period.of(Integer.MIN_VALUE, -12, 0);
|
||||
base.normalized();
|
||||
Assertions.assertThrows(ArithmeticException.class, () -> {
|
||||
Period base = Period.of(Integer.MIN_VALUE, -12, 0);
|
||||
base.normalized();
|
||||
});
|
||||
}
|
||||
|
||||
@Test(expectedExceptions=ArithmeticException.class)
|
||||
@Test
|
||||
public void test_normalized_max() {
|
||||
Period base = Period.of(Integer.MAX_VALUE, 12, 0);
|
||||
base.normalized();
|
||||
Assertions.assertThrows(ArithmeticException.class, () -> {
|
||||
Period base = Period.of(Integer.MAX_VALUE, 12, 0);
|
||||
base.normalized();
|
||||
});
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
// addTo()
|
||||
//-----------------------------------------------------------------------
|
||||
@DataProvider(name="addTo")
|
||||
Object[][] data_addTo() {
|
||||
return new Object[][] {
|
||||
{pymd(0, 0, 0), date(2012, 6, 30), date(2012, 6, 30)},
|
||||
@ -1056,30 +1105,31 @@ public class TCKPeriod extends AbstractTCKTest {
|
||||
};
|
||||
}
|
||||
|
||||
@Test(dataProvider="addTo")
|
||||
@ParameterizedTest
|
||||
@MethodSource("data_addTo")
|
||||
public void test_addTo(Period period, LocalDate baseDate, LocalDate expected) {
|
||||
assertEquals(period.addTo(baseDate), expected);
|
||||
assertEquals(expected, period.addTo(baseDate));
|
||||
}
|
||||
|
||||
@Test(dataProvider="addTo")
|
||||
@ParameterizedTest
|
||||
@MethodSource("data_addTo")
|
||||
public void test_addTo_usingLocalDatePlus(Period period, LocalDate baseDate, LocalDate expected) {
|
||||
assertEquals(baseDate.plus(period), expected);
|
||||
assertEquals(expected, baseDate.plus(period));
|
||||
}
|
||||
|
||||
@Test(expectedExceptions=NullPointerException.class)
|
||||
@Test
|
||||
public void test_addTo_nullZero() {
|
||||
Period.ZERO.addTo(null);
|
||||
Assertions.assertThrows(NullPointerException.class, () -> Period.ZERO.addTo(null));
|
||||
}
|
||||
|
||||
@Test(expectedExceptions=NullPointerException.class)
|
||||
@Test
|
||||
public void test_addTo_nullNonZero() {
|
||||
Period.ofDays(2).addTo(null);
|
||||
Assertions.assertThrows(NullPointerException.class, () -> Period.ofDays(2).addTo(null));
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
// subtractFrom()
|
||||
//-----------------------------------------------------------------------
|
||||
@DataProvider(name="subtractFrom")
|
||||
Object[][] data_subtractFrom() {
|
||||
return new Object[][] {
|
||||
{pymd(0, 0, 0), date(2012, 6, 30), date(2012, 6, 30)},
|
||||
@ -1109,24 +1159,26 @@ public class TCKPeriod extends AbstractTCKTest {
|
||||
};
|
||||
}
|
||||
|
||||
@Test(dataProvider="subtractFrom")
|
||||
@ParameterizedTest
|
||||
@MethodSource("data_subtractFrom")
|
||||
public void test_subtractFrom(Period period, LocalDate baseDate, LocalDate expected) {
|
||||
assertEquals(period.subtractFrom(baseDate), expected);
|
||||
assertEquals(expected, period.subtractFrom(baseDate));
|
||||
}
|
||||
|
||||
@Test(dataProvider="subtractFrom")
|
||||
@ParameterizedTest
|
||||
@MethodSource("data_subtractFrom")
|
||||
public void test_subtractFrom_usingLocalDateMinus(Period period, LocalDate baseDate, LocalDate expected) {
|
||||
assertEquals(baseDate.minus(period), expected);
|
||||
assertEquals(expected, baseDate.minus(period));
|
||||
}
|
||||
|
||||
@Test(expectedExceptions=NullPointerException.class)
|
||||
@Test
|
||||
public void test_subtractFrom_nullZero() {
|
||||
Period.ZERO.subtractFrom(null);
|
||||
Assertions.assertThrows(NullPointerException.class, () -> Period.ZERO.subtractFrom(null));
|
||||
}
|
||||
|
||||
@Test(expectedExceptions=NullPointerException.class)
|
||||
@Test
|
||||
public void test_subtractFrom_nullNonZero() {
|
||||
Period.ofDays(2).subtractFrom(null);
|
||||
Assertions.assertThrows(NullPointerException.class, () -> Period.ofDays(2).subtractFrom(null));
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
@ -1136,14 +1188,13 @@ public class TCKPeriod extends AbstractTCKTest {
|
||||
public void test_Period_getUnits() {
|
||||
Period period = Period.of(2012, 1, 1);
|
||||
List<TemporalUnit> units = period.getUnits();
|
||||
assertEquals(units.size(), 3, "Period.getUnits should return 3 units");
|
||||
assertEquals(units.get(0), ChronoUnit.YEARS, "Period.getUnits contains ChronoUnit.YEARS");
|
||||
assertEquals(units.get(1), ChronoUnit.MONTHS, "Period.getUnits contains ChronoUnit.MONTHS");
|
||||
assertEquals(units.get(2), ChronoUnit.DAYS, "Period.getUnits contains ChronoUnit.DAYS");
|
||||
assertEquals(3, units.size(), "Period.getUnits should return 3 units");
|
||||
assertEquals(ChronoUnit.YEARS, units.get(0), "Period.getUnits contains ChronoUnit.YEARS");
|
||||
assertEquals(ChronoUnit.MONTHS, units.get(1), "Period.getUnits contains ChronoUnit.MONTHS");
|
||||
assertEquals(ChronoUnit.DAYS, units.get(2), "Period.getUnits contains ChronoUnit.DAYS");
|
||||
}
|
||||
|
||||
|
||||
@DataProvider(name="GoodTemporalUnit")
|
||||
Object[][] data_goodTemporalUnit() {
|
||||
return new Object[][] {
|
||||
{2, ChronoUnit.DAYS},
|
||||
@ -1152,14 +1203,14 @@ public class TCKPeriod extends AbstractTCKTest {
|
||||
};
|
||||
}
|
||||
|
||||
@Test(dataProvider="GoodTemporalUnit")
|
||||
@ParameterizedTest
|
||||
@MethodSource("data_goodTemporalUnit")
|
||||
public void test_good_getUnit(long amount, TemporalUnit unit) {
|
||||
Period period = Period.of(2, 2, 2);
|
||||
long actual = period.get(unit);
|
||||
assertEquals(actual, amount, "Value of unit: " + unit);
|
||||
assertEquals(amount, actual, "Value of unit: " + unit);
|
||||
}
|
||||
|
||||
@DataProvider(name="BadTemporalUnit")
|
||||
Object[][] data_badTemporalUnit() {
|
||||
return new Object[][] {
|
||||
{ChronoUnit.MICROS},
|
||||
@ -1171,64 +1222,71 @@ public class TCKPeriod extends AbstractTCKTest {
|
||||
};
|
||||
}
|
||||
|
||||
@Test(dataProvider="BadTemporalUnit", expectedExceptions=DateTimeException.class)
|
||||
@ParameterizedTest
|
||||
@MethodSource("data_badTemporalUnit")
|
||||
public void test_bad_getUnit(TemporalUnit unit) {
|
||||
Period period = Period.of(2, 2, 2);
|
||||
period.get(unit);
|
||||
Assertions.assertThrows(DateTimeException.class, () -> {
|
||||
Period period = Period.of(2, 2, 2);
|
||||
period.get(unit);
|
||||
});
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
// equals() / hashCode()
|
||||
//-----------------------------------------------------------------------
|
||||
@Test
|
||||
public void test_equals() {
|
||||
assertEquals(Period.of(1, 0, 0).equals(Period.ofYears(1)), true);
|
||||
assertEquals(Period.of(0, 1, 0).equals(Period.ofMonths(1)), true);
|
||||
assertEquals(Period.of(0, 0, 1).equals(Period.ofDays(1)), true);
|
||||
assertEquals(Period.of(1, 2, 3).equals(Period.of(1, 2, 3)), true);
|
||||
assertEquals(true, Period.of(1, 0, 0).equals(Period.ofYears(1)));
|
||||
assertEquals(true, Period.of(0, 1, 0).equals(Period.ofMonths(1)));
|
||||
assertEquals(true, Period.of(0, 0, 1).equals(Period.ofDays(1)));
|
||||
assertEquals(true, Period.of(1, 2, 3).equals(Period.of(1, 2, 3)));
|
||||
|
||||
assertEquals(Period.ofYears(1).equals(Period.ofYears(1)), true);
|
||||
assertEquals(Period.ofYears(1).equals(Period.ofYears(2)), false);
|
||||
assertEquals(true, Period.ofYears(1).equals(Period.ofYears(1)));
|
||||
assertEquals(false, Period.ofYears(1).equals(Period.ofYears(2)));
|
||||
|
||||
assertEquals(Period.ofMonths(1).equals(Period.ofMonths(1)), true);
|
||||
assertEquals(Period.ofMonths(1).equals(Period.ofMonths(2)), false);
|
||||
assertEquals(true, Period.ofMonths(1).equals(Period.ofMonths(1)));
|
||||
assertEquals(false, Period.ofMonths(1).equals(Period.ofMonths(2)));
|
||||
|
||||
assertEquals(Period.ofDays(1).equals(Period.ofDays(1)), true);
|
||||
assertEquals(Period.ofDays(1).equals(Period.ofDays(2)), false);
|
||||
assertEquals(true, Period.ofDays(1).equals(Period.ofDays(1)));
|
||||
assertEquals(false, Period.ofDays(1).equals(Period.ofDays(2)));
|
||||
|
||||
assertEquals(Period.of(1, 2, 3).equals(Period.of(0, 2, 3)), false);
|
||||
assertEquals(Period.of(1, 2, 3).equals(Period.of(1, 0, 3)), false);
|
||||
assertEquals(Period.of(1, 2, 3).equals(Period.of(1, 2, 0)), false);
|
||||
assertEquals(false, Period.of(1, 2, 3).equals(Period.of(0, 2, 3)));
|
||||
assertEquals(false, Period.of(1, 2, 3).equals(Period.of(1, 0, 3)));
|
||||
assertEquals(false, Period.of(1, 2, 3).equals(Period.of(1, 2, 0)));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test_equals_self() {
|
||||
Period test = Period.of(1, 2, 3);
|
||||
assertEquals(test.equals(test), true);
|
||||
assertEquals(true, test.equals(test));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test_equals_null() {
|
||||
Period test = Period.of(1, 2, 3);
|
||||
assertEquals(test.equals(null), false);
|
||||
assertEquals(false, test.equals(null));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test_equals_otherClass() {
|
||||
Period test = Period.of(1, 2, 3);
|
||||
assertEquals(test.equals(""), false);
|
||||
assertEquals(false, test.equals(""));
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
@Test
|
||||
public void test_hashCode() {
|
||||
Period test5 = Period.ofDays(5);
|
||||
Period test6 = Period.ofDays(6);
|
||||
Period test5M = Period.ofMonths(5);
|
||||
Period test5Y = Period.ofYears(5);
|
||||
assertEquals(test5.hashCode() == test5.hashCode(), true);
|
||||
assertEquals(test5.hashCode() == test6.hashCode(), false);
|
||||
assertEquals(true, test5.hashCode() == test5.hashCode());
|
||||
assertEquals(false, test5.hashCode() == test6.hashCode());
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
// toString()
|
||||
//-----------------------------------------------------------------------
|
||||
@DataProvider(name="toStringAndParse")
|
||||
Object[][] data_toString() {
|
||||
return new Object[][] {
|
||||
{Period.ZERO, "P0D"},
|
||||
@ -1242,22 +1300,24 @@ public class TCKPeriod extends AbstractTCKTest {
|
||||
};
|
||||
}
|
||||
|
||||
@Test(dataProvider="toStringAndParse")
|
||||
@ParameterizedTest
|
||||
@MethodSource("data_toString")
|
||||
public void test_toString(Period input, String expected) {
|
||||
assertEquals(input.toString(), expected);
|
||||
assertEquals(expected, input.toString());
|
||||
}
|
||||
|
||||
@Test(dataProvider="toStringAndParse")
|
||||
@ParameterizedTest
|
||||
@MethodSource("data_toString")
|
||||
public void test_parse(Period test, String expected) {
|
||||
assertEquals(Period.parse(expected), test);
|
||||
assertEquals(test, Period.parse(expected));
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
private void assertPeriod(Period test, int y, int m, int d) {
|
||||
assertEquals(test.getYears(), y, "years");
|
||||
assertEquals(test.getMonths(), m, "months");
|
||||
assertEquals(test.getDays(), d, "days");
|
||||
assertEquals(test.toTotalMonths(), y * 12L + m, "totalMonths");
|
||||
assertEquals(y, test.getYears(), "years");
|
||||
assertEquals(m, test.getMonths(), "months");
|
||||
assertEquals(d, test.getDays(), "days");
|
||||
assertEquals(y * 12L + m, test.toTotalMonths(), "totalMonths");
|
||||
}
|
||||
|
||||
private static Period pymd(int y, int m, int d) {
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2012, 2024, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2012, 2025, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
@ -59,8 +59,8 @@
|
||||
*/
|
||||
package tck.java.time;
|
||||
|
||||
import static org.testng.Assert.assertEquals;
|
||||
import static org.testng.Assert.fail;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.fail;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
@ -84,13 +84,16 @@ import java.util.Locale;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import org.testng.annotations.DataProvider;
|
||||
import org.testng.annotations.Test;
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.TestInstance;
|
||||
import org.junit.jupiter.params.ParameterizedTest;
|
||||
import org.junit.jupiter.params.provider.MethodSource;
|
||||
|
||||
/**
|
||||
* Test ZoneId.
|
||||
*/
|
||||
@Test
|
||||
@TestInstance(TestInstance.Lifecycle.PER_CLASS)
|
||||
public class TCKZoneId extends AbstractTCKTest {
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
@ -99,40 +102,42 @@ public class TCKZoneId extends AbstractTCKTest {
|
||||
@Test
|
||||
public void test_constant_OLD_IDS_POST_2024b() {
|
||||
Map<String, String> ids = ZoneId.SHORT_IDS;
|
||||
assertEquals(ids.get("EST"), "America/Panama");
|
||||
assertEquals(ids.get("MST"), "America/Phoenix");
|
||||
assertEquals(ids.get("HST"), "Pacific/Honolulu");
|
||||
assertEquals(ids.get("ACT"), "Australia/Darwin");
|
||||
assertEquals(ids.get("AET"), "Australia/Sydney");
|
||||
assertEquals(ids.get("AGT"), "America/Argentina/Buenos_Aires");
|
||||
assertEquals(ids.get("ART"), "Africa/Cairo");
|
||||
assertEquals(ids.get("AST"), "America/Anchorage");
|
||||
assertEquals(ids.get("BET"), "America/Sao_Paulo");
|
||||
assertEquals(ids.get("BST"), "Asia/Dhaka");
|
||||
assertEquals(ids.get("CAT"), "Africa/Harare");
|
||||
assertEquals(ids.get("CNT"), "America/St_Johns");
|
||||
assertEquals(ids.get("CST"), "America/Chicago");
|
||||
assertEquals(ids.get("CTT"), "Asia/Shanghai");
|
||||
assertEquals(ids.get("EAT"), "Africa/Addis_Ababa");
|
||||
assertEquals(ids.get("ECT"), "Europe/Paris");
|
||||
assertEquals(ids.get("IET"), "America/Indiana/Indianapolis");
|
||||
assertEquals(ids.get("IST"), "Asia/Kolkata");
|
||||
assertEquals(ids.get("JST"), "Asia/Tokyo");
|
||||
assertEquals(ids.get("MIT"), "Pacific/Apia");
|
||||
assertEquals(ids.get("NET"), "Asia/Yerevan");
|
||||
assertEquals(ids.get("NST"), "Pacific/Auckland");
|
||||
assertEquals(ids.get("PLT"), "Asia/Karachi");
|
||||
assertEquals(ids.get("PNT"), "America/Phoenix");
|
||||
assertEquals(ids.get("PRT"), "America/Puerto_Rico");
|
||||
assertEquals(ids.get("PST"), "America/Los_Angeles");
|
||||
assertEquals(ids.get("SST"), "Pacific/Guadalcanal");
|
||||
assertEquals(ids.get("VST"), "Asia/Ho_Chi_Minh");
|
||||
assertEquals("America/Panama", ids.get("EST"));
|
||||
assertEquals("America/Phoenix", ids.get("MST"));
|
||||
assertEquals("Pacific/Honolulu", ids.get("HST"));
|
||||
assertEquals("Australia/Darwin", ids.get("ACT"));
|
||||
assertEquals("Australia/Sydney", ids.get("AET"));
|
||||
assertEquals("America/Argentina/Buenos_Aires", ids.get("AGT"));
|
||||
assertEquals("Africa/Cairo", ids.get("ART"));
|
||||
assertEquals("America/Anchorage", ids.get("AST"));
|
||||
assertEquals("America/Sao_Paulo", ids.get("BET"));
|
||||
assertEquals("Asia/Dhaka", ids.get("BST"));
|
||||
assertEquals("Africa/Harare", ids.get("CAT"));
|
||||
assertEquals("America/St_Johns", ids.get("CNT"));
|
||||
assertEquals("America/Chicago", ids.get("CST"));
|
||||
assertEquals("Asia/Shanghai", ids.get("CTT"));
|
||||
assertEquals("Africa/Addis_Ababa", ids.get("EAT"));
|
||||
assertEquals("Europe/Paris", ids.get("ECT"));
|
||||
assertEquals("America/Indiana/Indianapolis", ids.get("IET"));
|
||||
assertEquals("Asia/Kolkata", ids.get("IST"));
|
||||
assertEquals("Asia/Tokyo", ids.get("JST"));
|
||||
assertEquals("Pacific/Apia", ids.get("MIT"));
|
||||
assertEquals("Asia/Yerevan", ids.get("NET"));
|
||||
assertEquals("Pacific/Auckland", ids.get("NST"));
|
||||
assertEquals("Asia/Karachi", ids.get("PLT"));
|
||||
assertEquals("America/Phoenix", ids.get("PNT"));
|
||||
assertEquals("America/Puerto_Rico", ids.get("PRT"));
|
||||
assertEquals("America/Los_Angeles", ids.get("PST"));
|
||||
assertEquals("Pacific/Guadalcanal", ids.get("SST"));
|
||||
assertEquals("Asia/Ho_Chi_Minh", ids.get("VST"));
|
||||
}
|
||||
|
||||
@Test(expectedExceptions=UnsupportedOperationException.class)
|
||||
@Test
|
||||
public void test_constant_OLD_IDS_POST_2024b_immutable() {
|
||||
Map<String, String> ids = ZoneId.SHORT_IDS;
|
||||
ids.clear();
|
||||
Assertions.assertThrows(UnsupportedOperationException.class, () -> {
|
||||
Map<String, String> ids = ZoneId.SHORT_IDS;
|
||||
ids.clear();
|
||||
});
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
@ -141,11 +146,11 @@ public class TCKZoneId extends AbstractTCKTest {
|
||||
@Test
|
||||
public void test_getAvailableGroupIds() {
|
||||
Set<String> zoneIds = ZoneId.getAvailableZoneIds();
|
||||
assertEquals(zoneIds.contains("Europe/London"), true);
|
||||
assertEquals(true, zoneIds.contains("Europe/London"));
|
||||
zoneIds.clear();
|
||||
assertEquals(zoneIds.size(), 0);
|
||||
assertEquals(0, zoneIds.size());
|
||||
Set<String> zoneIds2 = ZoneId.getAvailableZoneIds();
|
||||
assertEquals(zoneIds2.contains("Europe/London"), true);
|
||||
assertEquals(true, zoneIds2.contains("Europe/London"));
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
@ -157,7 +162,7 @@ public class TCKZoneId extends AbstractTCKTest {
|
||||
map.put("LONDON", "Europe/London");
|
||||
map.put("PARIS", "Europe/Paris");
|
||||
ZoneId test = ZoneId.of("LONDON", map);
|
||||
assertEquals(test.getId(), "Europe/London");
|
||||
assertEquals("Europe/London", test.getId());
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -166,32 +171,35 @@ public class TCKZoneId extends AbstractTCKTest {
|
||||
map.put("LONDON", "Europe/London");
|
||||
map.put("PARIS", "Europe/Paris");
|
||||
ZoneId test = ZoneId.of("Europe/Madrid", map);
|
||||
assertEquals(test.getId(), "Europe/Madrid");
|
||||
assertEquals("Europe/Madrid", test.getId());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test_of_string_Map_emptyMap() {
|
||||
Map<String, String> map = new HashMap<>();
|
||||
ZoneId test = ZoneId.of("Europe/Madrid", map);
|
||||
assertEquals(test.getId(), "Europe/Madrid");
|
||||
assertEquals("Europe/Madrid", test.getId());
|
||||
}
|
||||
|
||||
@Test(expectedExceptions=DateTimeException.class)
|
||||
@Test
|
||||
public void test_of_string_Map_badFormat() {
|
||||
Map<String, String> map = new HashMap<>();
|
||||
ZoneId.of("Not known", map);
|
||||
Assertions.assertThrows(DateTimeException.class, () -> {
|
||||
Map<String, String> map = new HashMap<>();
|
||||
ZoneId.of("Not known", map);
|
||||
});
|
||||
}
|
||||
|
||||
@Test(expectedExceptions=ZoneRulesException.class)
|
||||
@Test
|
||||
public void test_of_string_Map_unknown() {
|
||||
Map<String, String> map = new HashMap<>();
|
||||
ZoneId.of("Unknown", map);
|
||||
Assertions.assertThrows(ZoneRulesException.class, () -> {
|
||||
Map<String, String> map = new HashMap<>();
|
||||
ZoneId.of("Unknown", map);
|
||||
});
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
// regular factory and .normalized()
|
||||
//-----------------------------------------------------------------------
|
||||
@DataProvider(name="offsetBasedValid")
|
||||
Object[][] data_offsetBasedValid() {
|
||||
return new Object[][] {
|
||||
{"Z", "Z"},
|
||||
@ -227,19 +235,19 @@ public class TCKZoneId extends AbstractTCKTest {
|
||||
};
|
||||
}
|
||||
|
||||
@Test(dataProvider="offsetBasedValid")
|
||||
@ParameterizedTest
|
||||
@MethodSource("data_offsetBasedValid")
|
||||
public void factory_of_String_offsetBasedValid_noPrefix(String input, String id) {
|
||||
ZoneId test = ZoneId.of(input);
|
||||
assertEquals(test.getId(), id);
|
||||
assertEquals(test, ZoneOffset.of(id));
|
||||
assertEquals(test.normalized(), ZoneOffset.of(id));
|
||||
assertEquals(test.getDisplayName(TextStyle.FULL, Locale.UK), id);
|
||||
assertEquals(test.getRules().isFixedOffset(), true);
|
||||
assertEquals(test.getRules().getOffset(Instant.EPOCH), ZoneOffset.of(id));
|
||||
assertEquals(id, test.getId());
|
||||
assertEquals(ZoneOffset.of(id), test);
|
||||
assertEquals(ZoneOffset.of(id), test.normalized());
|
||||
assertEquals(id, test.getDisplayName(TextStyle.FULL, Locale.UK));
|
||||
assertEquals(true, test.getRules().isFixedOffset());
|
||||
assertEquals(ZoneOffset.of(id), test.getRules().getOffset(Instant.EPOCH));
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
@DataProvider(name="offsetBasedValidPrefix")
|
||||
Object[][] data_offsetBasedValidPrefix() {
|
||||
return new Object[][] {
|
||||
{"", "", "Z"},
|
||||
@ -275,37 +283,40 @@ public class TCKZoneId extends AbstractTCKTest {
|
||||
};
|
||||
}
|
||||
|
||||
@Test(dataProvider="offsetBasedValidPrefix")
|
||||
@ParameterizedTest
|
||||
@MethodSource("data_offsetBasedValidPrefix")
|
||||
public void factory_of_String_offsetBasedValid_prefixUTC(String input, String id, String offsetId) {
|
||||
ZoneId test = ZoneId.of("UTC" + input);
|
||||
assertEquals(test.getId(), "UTC" + id);
|
||||
assertEquals(test.getRules(), ZoneOffset.of(offsetId).getRules());
|
||||
assertEquals(test.normalized(), ZoneOffset.of(offsetId));
|
||||
assertEquals(test.getDisplayName(TextStyle.FULL, Locale.UK), displayName("UTC" + id));
|
||||
assertEquals(test.getRules().isFixedOffset(), true);
|
||||
assertEquals(test.getRules().getOffset(Instant.EPOCH), ZoneOffset.of(offsetId));
|
||||
assertEquals("UTC" + id, test.getId());
|
||||
assertEquals(ZoneOffset.of(offsetId).getRules(), test.getRules());
|
||||
assertEquals(ZoneOffset.of(offsetId), test.normalized());
|
||||
assertEquals(displayName("UTC" + id), test.getDisplayName(TextStyle.FULL, Locale.UK));
|
||||
assertEquals(true, test.getRules().isFixedOffset());
|
||||
assertEquals(ZoneOffset.of(offsetId), test.getRules().getOffset(Instant.EPOCH));
|
||||
}
|
||||
|
||||
@Test(dataProvider="offsetBasedValidPrefix")
|
||||
@ParameterizedTest
|
||||
@MethodSource("data_offsetBasedValidPrefix")
|
||||
public void factory_of_String_offsetBasedValid_prefixGMT(String input, String id, String offsetId) {
|
||||
ZoneId test = ZoneId.of("GMT" + input);
|
||||
assertEquals(test.getId(), "GMT" + id);
|
||||
assertEquals(test.getRules(), ZoneOffset.of(offsetId).getRules());
|
||||
assertEquals(test.normalized(), ZoneOffset.of(offsetId));
|
||||
assertEquals(test.getDisplayName(TextStyle.FULL, Locale.UK), displayName("GMT" + id));
|
||||
assertEquals(test.getRules().isFixedOffset(), true);
|
||||
assertEquals(test.getRules().getOffset(Instant.EPOCH), ZoneOffset.of(offsetId));
|
||||
assertEquals("GMT" + id, test.getId());
|
||||
assertEquals(ZoneOffset.of(offsetId).getRules(), test.getRules());
|
||||
assertEquals(ZoneOffset.of(offsetId), test.normalized());
|
||||
assertEquals(displayName("GMT" + id), test.getDisplayName(TextStyle.FULL, Locale.UK));
|
||||
assertEquals(true, test.getRules().isFixedOffset());
|
||||
assertEquals(ZoneOffset.of(offsetId), test.getRules().getOffset(Instant.EPOCH));
|
||||
}
|
||||
|
||||
@Test(dataProvider="offsetBasedValidPrefix")
|
||||
@ParameterizedTest
|
||||
@MethodSource("data_offsetBasedValidPrefix")
|
||||
public void factory_of_String_offsetBasedValid_prefixUT(String input, String id, String offsetId) {
|
||||
ZoneId test = ZoneId.of("UT" + input);
|
||||
assertEquals(test.getId(), "UT" + id);
|
||||
assertEquals(test.getRules(), ZoneOffset.of(offsetId).getRules());
|
||||
assertEquals(test.normalized(), ZoneOffset.of(offsetId));
|
||||
assertEquals(test.getDisplayName(TextStyle.FULL, Locale.UK), displayName("UT" + id));
|
||||
assertEquals(test.getRules().isFixedOffset(), true);
|
||||
assertEquals(test.getRules().getOffset(Instant.EPOCH), ZoneOffset.of(offsetId));
|
||||
assertEquals("UT" + id, test.getId());
|
||||
assertEquals(ZoneOffset.of(offsetId).getRules(), test.getRules());
|
||||
assertEquals(ZoneOffset.of(offsetId), test.normalized());
|
||||
assertEquals(displayName("UT" + id), test.getDisplayName(TextStyle.FULL, Locale.UK));
|
||||
assertEquals(true, test.getRules().isFixedOffset());
|
||||
assertEquals(ZoneOffset.of(offsetId), test.getRules().getOffset(Instant.EPOCH));
|
||||
}
|
||||
|
||||
private String displayName(String id) {
|
||||
@ -322,7 +333,6 @@ public class TCKZoneId extends AbstractTCKTest {
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
@DataProvider(name="prefixValid")
|
||||
Object[][] data_prefixValid() {
|
||||
return new Object[][] {
|
||||
{"GMT", "+01:00"},
|
||||
@ -332,16 +342,16 @@ public class TCKZoneId extends AbstractTCKTest {
|
||||
};
|
||||
}
|
||||
|
||||
@Test(dataProvider="prefixValid")
|
||||
@ParameterizedTest
|
||||
@MethodSource("data_prefixValid")
|
||||
public void test_prefixOfOffset(String prefix, String offset) {
|
||||
ZoneOffset zoff = ZoneOffset.of(offset);
|
||||
ZoneId zoneId = ZoneId.ofOffset(prefix, zoff);
|
||||
assertEquals(zoneId.getId(), prefix + zoff.getId(), "in correct id for : " + prefix + ", zoff: " + zoff);
|
||||
assertEquals(prefix + zoff.getId(), zoneId.getId(), "in correct id for : " + prefix + ", zoff: " + zoff);
|
||||
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
@DataProvider(name="prefixInvalid")
|
||||
Object[][] data_prefixInvalid() {
|
||||
return new Object[][] {
|
||||
{"GM", "+01:00"},
|
||||
@ -351,25 +361,27 @@ public class TCKZoneId extends AbstractTCKTest {
|
||||
};
|
||||
}
|
||||
|
||||
@Test(dataProvider="prefixInvalid", expectedExceptions=java.lang.IllegalArgumentException.class)
|
||||
@ParameterizedTest
|
||||
@MethodSource("data_prefixInvalid")
|
||||
public void test_invalidPrefixOfOffset(String prefix, String offset) {
|
||||
ZoneOffset zoff = ZoneOffset.of(offset);
|
||||
ZoneId zoneId = ZoneId.ofOffset(prefix, zoff);
|
||||
fail("should have thrown an exception for prefix: " + prefix);
|
||||
Assertions.assertThrows(IllegalArgumentException.class, () -> {
|
||||
ZoneOffset zoff = ZoneOffset.of(offset);
|
||||
ZoneId zoneId = ZoneId.ofOffset(prefix, zoff);
|
||||
fail("should have thrown an exception for prefix: " + prefix);
|
||||
});
|
||||
}
|
||||
|
||||
@Test(expectedExceptions=java.lang.NullPointerException.class)
|
||||
@Test
|
||||
public void test_nullPrefixOfOffset() {
|
||||
ZoneId.ofOffset(null, ZoneOffset.ofTotalSeconds(1));
|
||||
Assertions.assertThrows(NullPointerException.class, () -> ZoneId.ofOffset(null, ZoneOffset.ofTotalSeconds(1)));
|
||||
}
|
||||
|
||||
@Test(expectedExceptions=java.lang.NullPointerException.class)
|
||||
@Test
|
||||
public void test_nullOffsetOfOffset() {
|
||||
ZoneId.ofOffset("GMT", null);
|
||||
Assertions.assertThrows(NullPointerException.class, () -> ZoneId.ofOffset("GMT", null));
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
@DataProvider(name="offsetBasedValidOther")
|
||||
Object[][] data_offsetBasedValidOther() {
|
||||
return new Object[][] {
|
||||
{"GMT", "Z"},
|
||||
@ -393,16 +405,16 @@ public class TCKZoneId extends AbstractTCKTest {
|
||||
};
|
||||
}
|
||||
|
||||
@Test(dataProvider="offsetBasedValidOther")
|
||||
@ParameterizedTest
|
||||
@MethodSource("data_offsetBasedValidOther")
|
||||
public void factory_of_String_offsetBasedValidOther(String input, String offsetId) {
|
||||
ZoneId test = ZoneId.of(input);
|
||||
assertEquals(test.getId(), input);
|
||||
assertEquals(test.getRules(), ZoneOffset.of(offsetId).getRules());
|
||||
assertEquals(test.normalized(), ZoneOffset.of(offsetId));
|
||||
assertEquals(input, test.getId());
|
||||
assertEquals(ZoneOffset.of(offsetId).getRules(), test.getRules());
|
||||
assertEquals(ZoneOffset.of(offsetId), test.normalized());
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
@DataProvider(name="offsetBasedInvalid")
|
||||
Object[][] data_offsetBasedInvalid() {
|
||||
return new Object[][] {
|
||||
{"A"}, {"B"}, {"C"}, {"D"}, {"E"}, {"F"}, {"G"}, {"H"}, {"I"}, {"J"}, {"K"}, {"L"}, {"M"},
|
||||
@ -427,37 +439,46 @@ public class TCKZoneId extends AbstractTCKTest {
|
||||
};
|
||||
}
|
||||
|
||||
@Test(dataProvider="offsetBasedInvalid", expectedExceptions=DateTimeException.class)
|
||||
@ParameterizedTest
|
||||
@MethodSource("data_offsetBasedInvalid")
|
||||
public void factory_of_String_offsetBasedInvalid_noPrefix(String id) {
|
||||
if (id.equals("Z")) {
|
||||
throw new DateTimeException("Fake exception: Z alone is valid, not invalid");
|
||||
}
|
||||
ZoneId.of(id);
|
||||
Assertions.assertThrows(DateTimeException.class, () -> {
|
||||
if (id.equals("Z")) {
|
||||
throw new DateTimeException("Fake exception: Z alone is valid, not invalid");
|
||||
}
|
||||
ZoneId.of(id);
|
||||
});
|
||||
}
|
||||
|
||||
@Test(dataProvider="offsetBasedInvalid", expectedExceptions=DateTimeException.class)
|
||||
@ParameterizedTest
|
||||
@MethodSource("data_offsetBasedInvalid")
|
||||
public void factory_of_String_offsetBasedInvalid_prefixUTC(String id) {
|
||||
ZoneId.of("UTC" + id);
|
||||
Assertions.assertThrows(DateTimeException.class, () -> ZoneId.of("UTC" + id));
|
||||
}
|
||||
|
||||
@Test(dataProvider="offsetBasedInvalid", expectedExceptions=DateTimeException.class)
|
||||
@ParameterizedTest
|
||||
@MethodSource("data_offsetBasedInvalid")
|
||||
public void factory_of_String_offsetBasedInvalid_prefixGMT(String id) {
|
||||
if (id.equals("0")) {
|
||||
throw new DateTimeException("Fake exception: GMT0 is valid, not invalid");
|
||||
}
|
||||
ZoneId.of("GMT" + id);
|
||||
Assertions.assertThrows(DateTimeException.class, () -> {
|
||||
if (id.equals("0")) {
|
||||
throw new DateTimeException("Fake exception: GMT0 is valid, not invalid");
|
||||
}
|
||||
ZoneId.of("GMT" + id);
|
||||
});
|
||||
}
|
||||
|
||||
@Test(dataProvider="offsetBasedInvalid", expectedExceptions=DateTimeException.class)
|
||||
@ParameterizedTest
|
||||
@MethodSource("data_offsetBasedInvalid")
|
||||
public void factory_of_String_offsetBasedInvalid_prefixUT(String id) {
|
||||
if (id.equals("C")) {
|
||||
throw new DateTimeException("Fake exception: UT + C = UTC, thus it is valid, not invalid");
|
||||
}
|
||||
ZoneId.of("UT" + id);
|
||||
Assertions.assertThrows(DateTimeException.class, () -> {
|
||||
if (id.equals("C")) {
|
||||
throw new DateTimeException("Fake exception: UT + C = UTC, thus it is valid, not invalid");
|
||||
}
|
||||
ZoneId.of("UT" + id);
|
||||
});
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
@DataProvider(name="regionBasedInvalid")
|
||||
Object[][] data_regionBasedInvalid() {
|
||||
// \u00ef is a random unicode character
|
||||
return new Object[][] {
|
||||
@ -473,34 +494,35 @@ public class TCKZoneId extends AbstractTCKTest {
|
||||
};
|
||||
}
|
||||
|
||||
@Test(dataProvider="regionBasedInvalid", expectedExceptions=DateTimeException.class)
|
||||
@ParameterizedTest
|
||||
@MethodSource("data_regionBasedInvalid")
|
||||
public void factory_of_String_regionBasedInvalid(String id) {
|
||||
ZoneId.of(id);
|
||||
Assertions.assertThrows(DateTimeException.class, () -> ZoneId.of(id));
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
@Test
|
||||
public void factory_of_String_region_EuropeLondon() {
|
||||
ZoneId test = ZoneId.of("Europe/London");
|
||||
assertEquals(test.getId(), "Europe/London");
|
||||
assertEquals(test.getRules().isFixedOffset(), false);
|
||||
assertEquals(test.normalized(), test);
|
||||
assertEquals("Europe/London", test.getId());
|
||||
assertEquals(false, test.getRules().isFixedOffset());
|
||||
assertEquals(test, test.normalized());
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
@Test(expectedExceptions=NullPointerException.class)
|
||||
@Test
|
||||
public void factory_of_String_null() {
|
||||
ZoneId.of(null);
|
||||
Assertions.assertThrows(NullPointerException.class, () -> ZoneId.of(null));
|
||||
}
|
||||
|
||||
@Test(expectedExceptions=DateTimeException.class)
|
||||
@Test
|
||||
public void factory_of_String_badFormat() {
|
||||
ZoneId.of("Unknown rule");
|
||||
Assertions.assertThrows(DateTimeException.class, () -> ZoneId.of("Unknown rule"));
|
||||
}
|
||||
|
||||
@Test(expectedExceptions=ZoneRulesException.class)
|
||||
@Test
|
||||
public void factory_of_String_unknown() {
|
||||
ZoneId.of("Unknown");
|
||||
Assertions.assertThrows(ZoneRulesException.class, () -> ZoneId.of("Unknown"));
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
@ -526,23 +548,23 @@ public class TCKZoneId extends AbstractTCKTest {
|
||||
return TemporalAccessor.super.query(query);
|
||||
}
|
||||
};
|
||||
assertEquals(ZoneId.from(mock), ZoneId.of("Europe/Paris"));
|
||||
assertEquals(ZoneId.of("Europe/Paris"), ZoneId.from(mock));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void factory_from_TemporalAccessor_offset() {
|
||||
ZoneOffset offset = ZoneOffset.ofHours(1);
|
||||
assertEquals(ZoneId.from(offset), offset);
|
||||
assertEquals(offset, ZoneId.from(offset));
|
||||
}
|
||||
|
||||
@Test(expectedExceptions=DateTimeException.class)
|
||||
@Test
|
||||
public void factory_from_TemporalAccessor_invalid_noDerive() {
|
||||
ZoneId.from(LocalTime.of(12, 30));
|
||||
Assertions.assertThrows(DateTimeException.class, () -> ZoneId.from(LocalTime.of(12, 30)));
|
||||
}
|
||||
|
||||
@Test(expectedExceptions=NullPointerException.class)
|
||||
@Test
|
||||
public void factory_from_TemporalAccessor_null() {
|
||||
ZoneId.from(null);
|
||||
Assertions.assertThrows(NullPointerException.class, () -> ZoneId.from(null));
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
@ -553,32 +575,31 @@ public class TCKZoneId extends AbstractTCKTest {
|
||||
ZoneId test1 = ZoneId.of("Europe/London");
|
||||
ZoneId test2 = ZoneId.of("Europe/Paris");
|
||||
ZoneId test2b = ZoneId.of("Europe/Paris");
|
||||
assertEquals(test1.equals(test2), false);
|
||||
assertEquals(test2.equals(test1), false);
|
||||
assertEquals(false, test1.equals(test2));
|
||||
assertEquals(false, test2.equals(test1));
|
||||
|
||||
assertEquals(test1.equals(test1), true);
|
||||
assertEquals(test2.equals(test2), true);
|
||||
assertEquals(test2.equals(test2b), true);
|
||||
assertEquals(true, test1.equals(test1));
|
||||
assertEquals(true, test2.equals(test2));
|
||||
assertEquals(true, test2.equals(test2b));
|
||||
|
||||
assertEquals(test1.hashCode() == test1.hashCode(), true);
|
||||
assertEquals(test2.hashCode() == test2.hashCode(), true);
|
||||
assertEquals(test2.hashCode() == test2b.hashCode(), true);
|
||||
assertEquals(true, test1.hashCode() == test1.hashCode());
|
||||
assertEquals(true, test2.hashCode() == test2.hashCode());
|
||||
assertEquals(true, test2.hashCode() == test2b.hashCode());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test_equals_null() {
|
||||
assertEquals(ZoneId.of("Europe/London").equals(null), false);
|
||||
assertEquals(false, ZoneId.of("Europe/London").equals(null));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test_equals_notEqualWrongType() {
|
||||
assertEquals(ZoneId.of("Europe/London").equals("Europe/London"), false);
|
||||
assertEquals(false, ZoneId.of("Europe/London").equals("Europe/London"));
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
// toString()
|
||||
//-----------------------------------------------------------------------
|
||||
@DataProvider(name="toString")
|
||||
Object[][] data_toString() {
|
||||
return new Object[][] {
|
||||
{"Europe/London", "Europe/London"},
|
||||
@ -591,10 +612,11 @@ public class TCKZoneId extends AbstractTCKTest {
|
||||
};
|
||||
}
|
||||
|
||||
@Test(dataProvider="toString")
|
||||
@ParameterizedTest
|
||||
@MethodSource("data_toString")
|
||||
public void test_toString(String id, String expected) {
|
||||
ZoneId test = ZoneId.of(id);
|
||||
assertEquals(test.toString(), expected);
|
||||
assertEquals(expected, test.toString());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2012, 2016, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2012, 2025, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
@ -60,10 +60,11 @@
|
||||
package tck.java.time;
|
||||
|
||||
import static java.time.temporal.ChronoField.OFFSET_SECONDS;
|
||||
import static org.testng.Assert.assertEquals;
|
||||
import static org.testng.Assert.assertSame;
|
||||
import static org.testng.Assert.assertTrue;
|
||||
import static org.testng.Assert.fail;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertSame;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
import static org.junit.jupiter.api.Assertions.fail;
|
||||
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.DataOutputStream;
|
||||
@ -87,13 +88,16 @@ import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import org.testng.annotations.DataProvider;
|
||||
import org.testng.annotations.Test;
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.TestInstance;
|
||||
import org.junit.jupiter.params.ParameterizedTest;
|
||||
import org.junit.jupiter.params.provider.MethodSource;
|
||||
|
||||
/**
|
||||
* Test ZoneOffset.
|
||||
*/
|
||||
@Test
|
||||
@TestInstance(TestInstance.Lifecycle.PER_CLASS)
|
||||
public class TCKZoneOffset extends AbstractDateTimeTest {
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
@ -185,9 +189,9 @@ public class TCKZoneOffset extends AbstractDateTimeTest {
|
||||
}
|
||||
}
|
||||
|
||||
@Test(expectedExceptions=NullPointerException.class)
|
||||
@Test
|
||||
public void test_factory_string_null() {
|
||||
ZoneOffset.of((String) null);
|
||||
Assertions.assertThrows(NullPointerException.class, () -> ZoneOffset.of((String) null));
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
@ -302,14 +306,14 @@ public class TCKZoneOffset extends AbstractDateTimeTest {
|
||||
}
|
||||
}
|
||||
|
||||
@Test(expectedExceptions=DateTimeException.class)
|
||||
@Test
|
||||
public void test_factory_int_hours_tooBig() {
|
||||
ZoneOffset.ofHours(19);
|
||||
Assertions.assertThrows(DateTimeException.class, () -> ZoneOffset.ofHours(19));
|
||||
}
|
||||
|
||||
@Test(expectedExceptions=DateTimeException.class)
|
||||
@Test
|
||||
public void test_factory_int_hours_tooSmall() {
|
||||
ZoneOffset.ofHours(-19);
|
||||
Assertions.assertThrows(DateTimeException.class, () -> ZoneOffset.ofHours(-19));
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
@ -329,14 +333,14 @@ public class TCKZoneOffset extends AbstractDateTimeTest {
|
||||
doTestOffset(test2, 18, 0, 0);
|
||||
}
|
||||
|
||||
@Test(expectedExceptions=DateTimeException.class)
|
||||
@Test
|
||||
public void test_factory_int_hours_minutes_tooBig() {
|
||||
ZoneOffset.ofHoursMinutes(19, 0);
|
||||
Assertions.assertThrows(DateTimeException.class, () -> ZoneOffset.ofHoursMinutes(19, 0));
|
||||
}
|
||||
|
||||
@Test(expectedExceptions=DateTimeException.class)
|
||||
@Test
|
||||
public void test_factory_int_hours_minutes_tooSmall() {
|
||||
ZoneOffset.ofHoursMinutes(-19, 0);
|
||||
Assertions.assertThrows(DateTimeException.class, () -> ZoneOffset.ofHoursMinutes(-19, 0));
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
@ -359,102 +363,102 @@ public class TCKZoneOffset extends AbstractDateTimeTest {
|
||||
doTestOffset(test2, 18, 0, 0);
|
||||
}
|
||||
|
||||
@Test(expectedExceptions=DateTimeException.class)
|
||||
@Test
|
||||
public void test_factory_int_hours_minutes_seconds_plusHoursMinusMinutes() {
|
||||
ZoneOffset.ofHoursMinutesSeconds(1, -1, 0);
|
||||
Assertions.assertThrows(DateTimeException.class, () -> ZoneOffset.ofHoursMinutesSeconds(1, -1, 0));
|
||||
}
|
||||
|
||||
@Test(expectedExceptions=DateTimeException.class)
|
||||
@Test
|
||||
public void test_factory_int_hours_minutes_seconds_plusHoursMinusSeconds() {
|
||||
ZoneOffset.ofHoursMinutesSeconds(1, 0, -1);
|
||||
Assertions.assertThrows(DateTimeException.class, () -> ZoneOffset.ofHoursMinutesSeconds(1, 0, -1));
|
||||
}
|
||||
|
||||
@Test(expectedExceptions=DateTimeException.class)
|
||||
@Test
|
||||
public void test_factory_int_hours_minutes_seconds_minusHoursPlusMinutes() {
|
||||
ZoneOffset.ofHoursMinutesSeconds(-1, 1, 0);
|
||||
Assertions.assertThrows(DateTimeException.class, () -> ZoneOffset.ofHoursMinutesSeconds(-1, 1, 0));
|
||||
}
|
||||
|
||||
@Test(expectedExceptions=DateTimeException.class)
|
||||
@Test
|
||||
public void test_factory_int_hours_minutes_seconds_minusHoursPlusSeconds() {
|
||||
ZoneOffset.ofHoursMinutesSeconds(-1, 0, 1);
|
||||
Assertions.assertThrows(DateTimeException.class, () -> ZoneOffset.ofHoursMinutesSeconds(-1, 0, 1));
|
||||
}
|
||||
|
||||
@Test(expectedExceptions=DateTimeException.class)
|
||||
@Test
|
||||
public void test_factory_int_hours_minutes_seconds_zeroHoursMinusMinutesPlusSeconds() {
|
||||
ZoneOffset.ofHoursMinutesSeconds(0, -1, 1);
|
||||
Assertions.assertThrows(DateTimeException.class, () -> ZoneOffset.ofHoursMinutesSeconds(0, -1, 1));
|
||||
}
|
||||
|
||||
@Test(expectedExceptions=DateTimeException.class)
|
||||
@Test
|
||||
public void test_factory_int_hours_minutes_seconds_zeroHoursPlusMinutesMinusSeconds() {
|
||||
ZoneOffset.ofHoursMinutesSeconds(0, 1, -1);
|
||||
Assertions.assertThrows(DateTimeException.class, () -> ZoneOffset.ofHoursMinutesSeconds(0, 1, -1));
|
||||
}
|
||||
|
||||
@Test(expectedExceptions=DateTimeException.class)
|
||||
@Test
|
||||
public void test_factory_int_hours_minutes_seconds_minutesTooLarge() {
|
||||
ZoneOffset.ofHoursMinutesSeconds(0, 60, 0);
|
||||
Assertions.assertThrows(DateTimeException.class, () -> ZoneOffset.ofHoursMinutesSeconds(0, 60, 0));
|
||||
}
|
||||
|
||||
@Test(expectedExceptions=DateTimeException.class)
|
||||
@Test
|
||||
public void test_factory_int_hours_minutes_seconds_minutesTooSmall() {
|
||||
ZoneOffset.ofHoursMinutesSeconds(0, -60, 0);
|
||||
Assertions.assertThrows(DateTimeException.class, () -> ZoneOffset.ofHoursMinutesSeconds(0, -60, 0));
|
||||
}
|
||||
|
||||
@Test(expectedExceptions=DateTimeException.class)
|
||||
@Test
|
||||
public void test_factory_int_hours_minutes_seconds_secondsTooLarge() {
|
||||
ZoneOffset.ofHoursMinutesSeconds(0, 0, 60);
|
||||
Assertions.assertThrows(DateTimeException.class, () -> ZoneOffset.ofHoursMinutesSeconds(0, 0, 60));
|
||||
}
|
||||
|
||||
@Test(expectedExceptions=DateTimeException.class)
|
||||
@Test
|
||||
public void test_factory_int_hours_minutes_seconds_secondsTooSmall() {
|
||||
ZoneOffset.ofHoursMinutesSeconds(0, 0, 60);
|
||||
Assertions.assertThrows(DateTimeException.class, () -> ZoneOffset.ofHoursMinutesSeconds(0, 0, 60));
|
||||
}
|
||||
|
||||
@Test(expectedExceptions=DateTimeException.class)
|
||||
@Test
|
||||
public void test_factory_int_hours_minutes_seconds_hoursTooBig() {
|
||||
ZoneOffset.ofHoursMinutesSeconds(19, 0, 0);
|
||||
Assertions.assertThrows(DateTimeException.class, () -> ZoneOffset.ofHoursMinutesSeconds(19, 0, 0));
|
||||
}
|
||||
|
||||
@Test(expectedExceptions=DateTimeException.class)
|
||||
@Test
|
||||
public void test_factory_int_hours_minutes_seconds_hoursTooSmall() {
|
||||
ZoneOffset.ofHoursMinutesSeconds(-19, 0, 0);
|
||||
Assertions.assertThrows(DateTimeException.class, () -> ZoneOffset.ofHoursMinutesSeconds(-19, 0, 0));
|
||||
}
|
||||
|
||||
@Test(expectedExceptions=DateTimeException.class)
|
||||
@Test
|
||||
public void test_factory_int_hours_minutes_seconds_minutesMinValue() {
|
||||
ZoneOffset.ofHoursMinutesSeconds(0, Integer.MIN_VALUE, -1);
|
||||
Assertions.assertThrows(DateTimeException.class, () -> ZoneOffset.ofHoursMinutesSeconds(0, Integer.MIN_VALUE, -1));
|
||||
}
|
||||
|
||||
@Test(expectedExceptions=DateTimeException.class)
|
||||
@Test
|
||||
public void test_factory_int_hours_minutes_seconds_secondsMinValue() {
|
||||
ZoneOffset.ofHoursMinutesSeconds(0, 0, Integer.MIN_VALUE);
|
||||
Assertions.assertThrows(DateTimeException.class, () -> ZoneOffset.ofHoursMinutesSeconds(0, 0, Integer.MIN_VALUE));
|
||||
}
|
||||
|
||||
@Test(expectedExceptions=DateTimeException.class)
|
||||
@Test
|
||||
public void test_factory_int_hours_minutes_seconds_minutesAndSecondsMinValue() {
|
||||
ZoneOffset.ofHoursMinutesSeconds(0, Integer.MIN_VALUE, Integer.MIN_VALUE);
|
||||
Assertions.assertThrows(DateTimeException.class, () -> ZoneOffset.ofHoursMinutesSeconds(0, Integer.MIN_VALUE, Integer.MIN_VALUE));
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
@Test
|
||||
public void test_factory_ofTotalSeconds() {
|
||||
assertEquals(ZoneOffset.ofTotalSeconds(60 * 60 + 1), ZoneOffset.ofHoursMinutesSeconds(1, 0, 1));
|
||||
assertEquals(ZoneOffset.ofTotalSeconds(18 * 60 * 60), ZoneOffset.ofHours(18));
|
||||
assertEquals(ZoneOffset.ofTotalSeconds(-18 * 60 * 60), ZoneOffset.ofHours(-18));
|
||||
assertEquals(ZoneOffset.ofHoursMinutesSeconds(1, 0, 1), ZoneOffset.ofTotalSeconds(60 * 60 + 1));
|
||||
assertEquals(ZoneOffset.ofHours(18), ZoneOffset.ofTotalSeconds(18 * 60 * 60));
|
||||
assertEquals(ZoneOffset.ofHours(-18), ZoneOffset.ofTotalSeconds(-18 * 60 * 60));
|
||||
}
|
||||
|
||||
@Test(expectedExceptions=DateTimeException.class)
|
||||
@Test
|
||||
public void test_factory_ofTotalSeconds_tooLarge() {
|
||||
ZoneOffset.ofTotalSeconds(18 * 60 * 60 + 1);
|
||||
Assertions.assertThrows(DateTimeException.class, () -> ZoneOffset.ofTotalSeconds(18 * 60 * 60 + 1));
|
||||
}
|
||||
|
||||
@Test(expectedExceptions=DateTimeException.class)
|
||||
@Test
|
||||
public void test_factory_ofTotalSeconds_tooSmall() {
|
||||
ZoneOffset.ofTotalSeconds(-18 * 60 * 60 - 1);
|
||||
Assertions.assertThrows(DateTimeException.class, () -> ZoneOffset.ofTotalSeconds(-18 * 60 * 60 - 1));
|
||||
}
|
||||
|
||||
@Test(expectedExceptions=DateTimeException.class)
|
||||
@Test
|
||||
public void test_factory_ofTotalSeconds_minValue() {
|
||||
ZoneOffset.ofTotalSeconds(Integer.MIN_VALUE);
|
||||
Assertions.assertThrows(DateTimeException.class, () -> ZoneOffset.ofTotalSeconds(Integer.MIN_VALUE));
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
@ -462,18 +466,18 @@ public class TCKZoneOffset extends AbstractDateTimeTest {
|
||||
//-----------------------------------------------------------------------
|
||||
@Test
|
||||
public void test_factory_CalendricalObject() {
|
||||
assertEquals(ZoneOffset.from(ZonedDateTime.of(LocalDateTime.of(LocalDate.of(2007, 7, 15),
|
||||
LocalTime.of(17, 30)), ZoneOffset.ofHours(2))), ZoneOffset.ofHours(2));
|
||||
assertEquals(ZoneOffset.ofHours(2), ZoneOffset.from(ZonedDateTime.of(LocalDateTime.of(LocalDate.of(2007, 7, 15),
|
||||
LocalTime.of(17, 30)), ZoneOffset.ofHours(2))));
|
||||
}
|
||||
|
||||
@Test(expectedExceptions=DateTimeException.class)
|
||||
@Test
|
||||
public void test_factory_CalendricalObject_invalid_noDerive() {
|
||||
ZoneOffset.from(LocalTime.of(12, 30));
|
||||
Assertions.assertThrows(DateTimeException.class, () -> ZoneOffset.from(LocalTime.of(12, 30)));
|
||||
}
|
||||
|
||||
@Test(expectedExceptions=NullPointerException.class)
|
||||
@Test
|
||||
public void test_factory_CalendricalObject_null() {
|
||||
ZoneOffset.from((TemporalAccessor) null);
|
||||
Assertions.assertThrows(NullPointerException.class, () -> ZoneOffset.from((TemporalAccessor) null));
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
@ -482,7 +486,7 @@ public class TCKZoneOffset extends AbstractDateTimeTest {
|
||||
@Test
|
||||
public void test_getTotalSeconds() {
|
||||
ZoneOffset offset = ZoneOffset.ofTotalSeconds(60 * 60 + 1);
|
||||
assertEquals(offset.getTotalSeconds(), 60 * 60 + 1);
|
||||
assertEquals(60 * 60 + 1, offset.getTotalSeconds());
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
@ -491,11 +495,11 @@ public class TCKZoneOffset extends AbstractDateTimeTest {
|
||||
@Test
|
||||
public void test_getId() {
|
||||
ZoneOffset offset = ZoneOffset.ofHoursMinutesSeconds(1, 0, 0);
|
||||
assertEquals(offset.getId(), "+01:00");
|
||||
assertEquals("+01:00", offset.getId());
|
||||
offset = ZoneOffset.ofHoursMinutesSeconds(1, 2, 3);
|
||||
assertEquals(offset.getId(), "+01:02:03");
|
||||
assertEquals("+01:02:03", offset.getId());
|
||||
offset = ZoneOffset.UTC;
|
||||
assertEquals(offset.getId(), "Z");
|
||||
assertEquals("Z", offset.getId());
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
@ -504,21 +508,21 @@ public class TCKZoneOffset extends AbstractDateTimeTest {
|
||||
@Test
|
||||
public void test_getRules() {
|
||||
ZoneOffset offset = ZoneOffset.ofHoursMinutesSeconds(1, 2, 3);
|
||||
assertEquals(offset.getRules().isFixedOffset(), true);
|
||||
assertEquals(offset.getRules().getOffset((Instant) null), offset);
|
||||
assertEquals(offset.getRules().getDaylightSavings((Instant) null), Duration.ZERO);
|
||||
assertEquals(offset.getRules().getStandardOffset((Instant) null), offset);
|
||||
assertEquals(offset.getRules().nextTransition((Instant) null), null);
|
||||
assertEquals(offset.getRules().previousTransition((Instant) null), null);
|
||||
assertEquals(true, offset.getRules().isFixedOffset());
|
||||
assertEquals(offset, offset.getRules().getOffset((Instant) null));
|
||||
assertEquals(Duration.ZERO, offset.getRules().getDaylightSavings((Instant) null));
|
||||
assertEquals(offset, offset.getRules().getStandardOffset((Instant) null));
|
||||
assertEquals(null, offset.getRules().nextTransition((Instant) null));
|
||||
assertEquals(null, offset.getRules().previousTransition((Instant) null));
|
||||
|
||||
assertEquals(offset.getRules().isValidOffset((LocalDateTime) null, offset), true);
|
||||
assertEquals(offset.getRules().isValidOffset((LocalDateTime) null, ZoneOffset.UTC), false);
|
||||
assertEquals(offset.getRules().isValidOffset((LocalDateTime) null, null), false);
|
||||
assertEquals(offset.getRules().getOffset((LocalDateTime) null), offset);
|
||||
assertEquals(offset.getRules().getValidOffsets((LocalDateTime) null), Arrays.asList(offset));
|
||||
assertEquals(offset.getRules().getTransition((LocalDateTime) null), null);
|
||||
assertEquals(offset.getRules().getTransitions().size(), 0);
|
||||
assertEquals(offset.getRules().getTransitionRules().size(), 0);
|
||||
assertEquals(true, offset.getRules().isValidOffset((LocalDateTime) null, offset));
|
||||
assertEquals(false, offset.getRules().isValidOffset((LocalDateTime) null, ZoneOffset.UTC));
|
||||
assertEquals(false, offset.getRules().isValidOffset((LocalDateTime) null, null));
|
||||
assertEquals(offset, offset.getRules().getOffset((LocalDateTime) null));
|
||||
assertEquals(Arrays.asList(offset), offset.getRules().getValidOffsets((LocalDateTime) null));
|
||||
assertEquals(null, offset.getRules().getTransition((LocalDateTime) null));
|
||||
assertEquals(0, offset.getRules().getTransitions().size());
|
||||
assertEquals(0, offset.getRules().getTransitionRules().size());
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
@ -526,22 +530,21 @@ public class TCKZoneOffset extends AbstractDateTimeTest {
|
||||
//-----------------------------------------------------------------------
|
||||
@Test
|
||||
public void test_get_TemporalField() {
|
||||
assertEquals(ZoneOffset.UTC.get(OFFSET_SECONDS), 0);
|
||||
assertEquals(ZoneOffset.ofHours(-2).get(OFFSET_SECONDS), -7200);
|
||||
assertEquals(ZoneOffset.ofHoursMinutesSeconds(0, 1, 5).get(OFFSET_SECONDS), 65);
|
||||
assertEquals(0, ZoneOffset.UTC.get(OFFSET_SECONDS));
|
||||
assertEquals(-7200, ZoneOffset.ofHours(-2).get(OFFSET_SECONDS));
|
||||
assertEquals(65, ZoneOffset.ofHoursMinutesSeconds(0, 1, 5).get(OFFSET_SECONDS));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test_getLong_TemporalField() {
|
||||
assertEquals(ZoneOffset.UTC.getLong(OFFSET_SECONDS), 0);
|
||||
assertEquals(ZoneOffset.ofHours(-2).getLong(OFFSET_SECONDS), -7200);
|
||||
assertEquals(ZoneOffset.ofHoursMinutesSeconds(0, 1, 5).getLong(OFFSET_SECONDS), 65);
|
||||
assertEquals(0, ZoneOffset.UTC.getLong(OFFSET_SECONDS));
|
||||
assertEquals(-7200, ZoneOffset.ofHours(-2).getLong(OFFSET_SECONDS));
|
||||
assertEquals(65, ZoneOffset.ofHoursMinutesSeconds(0, 1, 5).getLong(OFFSET_SECONDS));
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
// query(TemporalQuery)
|
||||
//-----------------------------------------------------------------------
|
||||
@DataProvider(name="query")
|
||||
Object[][] data_query() {
|
||||
return new Object[][] {
|
||||
{ZoneOffset.UTC, TemporalQueries.chronology(), null},
|
||||
@ -554,19 +557,21 @@ public class TCKZoneOffset extends AbstractDateTimeTest {
|
||||
};
|
||||
}
|
||||
|
||||
@Test(dataProvider="query")
|
||||
@ParameterizedTest
|
||||
@MethodSource("data_query")
|
||||
public <T> void test_query(TemporalAccessor temporal, TemporalQuery<T> query, T expected) {
|
||||
assertEquals(temporal.query(query), expected);
|
||||
assertEquals(expected, temporal.query(query));
|
||||
}
|
||||
|
||||
@Test(dataProvider="query")
|
||||
@ParameterizedTest
|
||||
@MethodSource("data_query")
|
||||
public <T> void test_queryFrom(TemporalAccessor temporal, TemporalQuery<T> query, T expected) {
|
||||
assertEquals(query.queryFrom(temporal), expected);
|
||||
assertEquals(expected, query.queryFrom(temporal));
|
||||
}
|
||||
|
||||
@Test(expectedExceptions=NullPointerException.class)
|
||||
@Test
|
||||
public void test_query_null() {
|
||||
ZoneOffset.UTC.query(null);
|
||||
Assertions.assertThrows(NullPointerException.class, () -> ZoneOffset.UTC.query(null));
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
@ -590,16 +595,16 @@ public class TCKZoneOffset extends AbstractDateTimeTest {
|
||||
ZoneOffset offset1 = ZoneOffset.ofHoursMinutesSeconds(1, 2, 3);
|
||||
ZoneOffset offset2 = ZoneOffset.ofHoursMinutesSeconds(2, 3, 4);
|
||||
ZoneOffset offset2b = ZoneOffset.ofHoursMinutesSeconds(2, 3, 4);
|
||||
assertEquals(offset1.equals(offset2), false);
|
||||
assertEquals(offset2.equals(offset1), false);
|
||||
assertEquals(false, offset1.equals(offset2));
|
||||
assertEquals(false, offset2.equals(offset1));
|
||||
|
||||
assertEquals(offset1.equals(offset1), true);
|
||||
assertEquals(offset2.equals(offset2), true);
|
||||
assertEquals(offset2.equals(offset2b), true);
|
||||
assertEquals(true, offset1.equals(offset1));
|
||||
assertEquals(true, offset2.equals(offset2));
|
||||
assertEquals(true, offset2.equals(offset2b));
|
||||
|
||||
assertEquals(offset1.hashCode() == offset1.hashCode(), true);
|
||||
assertEquals(offset2.hashCode() == offset2.hashCode(), true);
|
||||
assertEquals(offset2.hashCode() == offset2b.hashCode(), true);
|
||||
assertEquals(true, offset1.hashCode() == offset1.hashCode());
|
||||
assertEquals(true, offset2.hashCode() == offset2.hashCode());
|
||||
assertEquals(true, offset2.hashCode() == offset2b.hashCode());
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
@ -612,11 +617,11 @@ public class TCKZoneOffset extends AbstractDateTimeTest {
|
||||
//Do not change offset of ZonedDateTime after adjustInto()
|
||||
ZonedDateTime zonedDateTime_target = ZonedDateTime.of(LocalDate.of(1909, 2, 2), LocalTime.of(10, 10, 10), ZoneId.of(zoneId));
|
||||
ZonedDateTime zonedDateTime_result = (ZonedDateTime)(base.adjustInto(zonedDateTime_target));
|
||||
assertEquals(zonedDateTime_target.getOffset(), zonedDateTime_result.getOffset());
|
||||
assertEquals(zonedDateTime_result.getOffset(), zonedDateTime_target.getOffset());
|
||||
|
||||
OffsetDateTime offsetDateTime_target = zonedDateTime_target.toOffsetDateTime();
|
||||
OffsetDateTime offsetDateTime_result = (OffsetDateTime)(base.adjustInto(offsetDateTime_target));
|
||||
assertEquals(base, offsetDateTime_result.getOffset());
|
||||
assertEquals(offsetDateTime_result.getOffset(), base);
|
||||
}
|
||||
}
|
||||
|
||||
@ -626,19 +631,21 @@ public class TCKZoneOffset extends AbstractDateTimeTest {
|
||||
for (int i=-18; i<=18; i++) {
|
||||
OffsetDateTime offsetDateTime_target = OffsetDateTime.of(LocalDate.of(1909, 2, 2), LocalTime.of(10, 10, 10), ZoneOffset.ofHours(i));
|
||||
OffsetDateTime offsetDateTime_result = (OffsetDateTime)base.adjustInto(offsetDateTime_target);
|
||||
assertEquals(base, offsetDateTime_result.getOffset());
|
||||
assertEquals(offsetDateTime_result.getOffset(), base);
|
||||
|
||||
//Do not change offset of ZonedDateTime after adjustInto()
|
||||
ZonedDateTime zonedDateTime_target = offsetDateTime_target.toZonedDateTime();
|
||||
ZonedDateTime zonedDateTime_result = (ZonedDateTime)(base.adjustInto(zonedDateTime_target));
|
||||
assertEquals(zonedDateTime_target.getOffset(), zonedDateTime_result.getOffset());
|
||||
assertEquals(zonedDateTime_result.getOffset(), zonedDateTime_target.getOffset());
|
||||
}
|
||||
}
|
||||
|
||||
@Test(expectedExceptions=DateTimeException.class)
|
||||
@Test
|
||||
public void test_adjustInto_dateOnly() {
|
||||
ZoneOffset base = ZoneOffset.ofHoursMinutesSeconds(1, 1, 1);
|
||||
base.adjustInto((LocalDate.of(1909, 2, 2)));
|
||||
Assertions.assertThrows(DateTimeException.class, () -> {
|
||||
ZoneOffset base = ZoneOffset.ofHoursMinutesSeconds(1, 1, 1);
|
||||
base.adjustInto((LocalDate.of(1909, 2, 2)));
|
||||
});
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
@ -647,18 +654,18 @@ public class TCKZoneOffset extends AbstractDateTimeTest {
|
||||
@Test
|
||||
public void test_toString() {
|
||||
ZoneOffset offset = ZoneOffset.ofHoursMinutesSeconds(1, 0, 0);
|
||||
assertEquals(offset.toString(), "+01:00");
|
||||
assertEquals("+01:00", offset.toString());
|
||||
offset = ZoneOffset.ofHoursMinutesSeconds(1, 2, 3);
|
||||
assertEquals(offset.toString(), "+01:02:03");
|
||||
assertEquals("+01:02:03", offset.toString());
|
||||
offset = ZoneOffset.UTC;
|
||||
assertEquals(offset.toString(), "Z");
|
||||
assertEquals("Z", offset.toString());
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------
|
||||
private void doTestOffset(ZoneOffset offset, int hours, int minutes, int seconds) {
|
||||
assertEquals(offset.getTotalSeconds(), hours * 60 * 60 + minutes * 60 + seconds);
|
||||
assertEquals(hours * 60 * 60 + minutes * 60 + seconds, offset.getTotalSeconds());
|
||||
final String id;
|
||||
if (hours == 0 && minutes == 0 && seconds == 0) {
|
||||
id = "Z";
|
||||
@ -673,16 +680,16 @@ public class TCKZoneOffset extends AbstractDateTimeTest {
|
||||
}
|
||||
id = str;
|
||||
}
|
||||
assertEquals(offset.getId(), id);
|
||||
assertEquals(offset, ZoneOffset.ofHoursMinutesSeconds(hours, minutes, seconds));
|
||||
assertEquals(id, offset.getId());
|
||||
assertEquals(ZoneOffset.ofHoursMinutesSeconds(hours, minutes, seconds), offset);
|
||||
if (seconds == 0) {
|
||||
assertEquals(offset, ZoneOffset.ofHoursMinutes(hours, minutes));
|
||||
assertEquals(ZoneOffset.ofHoursMinutes(hours, minutes), offset);
|
||||
if (minutes == 0) {
|
||||
assertEquals(offset, ZoneOffset.ofHours(hours));
|
||||
assertEquals(ZoneOffset.ofHours(hours), offset);
|
||||
}
|
||||
}
|
||||
assertEquals(ZoneOffset.of(id), offset);
|
||||
assertEquals(offset.toString(), id);
|
||||
assertEquals(offset, ZoneOffset.of(id));
|
||||
assertEquals(id, offset.toString());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2012, 2013, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2012, 2025, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
@ -64,10 +64,11 @@ import static java.time.chrono.IsoEra.CE;
|
||||
import static java.time.temporal.ChronoField.ERA;
|
||||
import static java.time.temporal.ChronoField.YEAR;
|
||||
import static java.time.temporal.ChronoField.YEAR_OF_ERA;
|
||||
import static org.testng.Assert.assertEquals;
|
||||
import static org.testng.Assert.assertFalse;
|
||||
import static org.testng.Assert.assertNotNull;
|
||||
import static org.testng.Assert.assertTrue;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
import java.time.DateTimeException;
|
||||
import java.time.LocalDate;
|
||||
@ -82,14 +83,16 @@ import java.time.chrono.IsoEra;
|
||||
import java.time.temporal.ChronoField;
|
||||
import java.time.temporal.TemporalAdjusters;
|
||||
|
||||
import org.testng.Assert;
|
||||
import org.testng.annotations.DataProvider;
|
||||
import org.testng.annotations.Test;
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.TestInstance;
|
||||
import org.junit.jupiter.params.ParameterizedTest;
|
||||
import org.junit.jupiter.params.provider.MethodSource;
|
||||
|
||||
/**
|
||||
* Test.
|
||||
*/
|
||||
@Test
|
||||
@TestInstance(TestInstance.Lifecycle.PER_CLASS)
|
||||
public class TestIsoChronology {
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
@ -99,10 +102,10 @@ public class TestIsoChronology {
|
||||
public void test_chrono_byName() {
|
||||
Chronology c = IsoChronology.INSTANCE;
|
||||
Chronology test = Chronology.of("ISO");
|
||||
Assert.assertNotNull(test, "The ISO calendar could not be found byName");
|
||||
Assert.assertEquals(test.getId(), "ISO", "ID mismatch");
|
||||
Assert.assertEquals(test.getCalendarType(), "iso8601", "Type mismatch");
|
||||
Assert.assertEquals(test, c);
|
||||
assertNotNull(test, "The ISO calendar could not be found byName");
|
||||
assertEquals("ISO", test.getId(), "ID mismatch");
|
||||
assertEquals("iso8601", test.getCalendarType(), "Type mismatch");
|
||||
assertEquals(c, test);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
@ -118,14 +121,13 @@ public class TestIsoChronology {
|
||||
//-----------------------------------------------------------------------
|
||||
@Test
|
||||
public void test_eraOf() {
|
||||
assertEquals(IsoChronology.INSTANCE.eraOf(0), BCE);
|
||||
assertEquals(IsoChronology.INSTANCE.eraOf(1), CE);
|
||||
assertEquals(BCE, IsoChronology.INSTANCE.eraOf(0));
|
||||
assertEquals(CE, IsoChronology.INSTANCE.eraOf(1));
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
// creation, toLocalDate()
|
||||
//-----------------------------------------------------------------------
|
||||
@DataProvider(name="samples")
|
||||
Object[][] data_samples() {
|
||||
return new Object[][] {
|
||||
{IsoChronology.INSTANCE.date(1, 7, 8), LocalDate.of(1, 7, 8)},
|
||||
@ -145,17 +147,18 @@ public class TestIsoChronology {
|
||||
};
|
||||
}
|
||||
|
||||
@Test(dataProvider="samples")
|
||||
@ParameterizedTest
|
||||
@MethodSource("data_samples")
|
||||
public void test_toLocalDate(LocalDate isoDate, LocalDate iso) {
|
||||
assertEquals(LocalDate.from(isoDate), iso);
|
||||
assertEquals(iso, LocalDate.from(isoDate));
|
||||
}
|
||||
|
||||
@Test(dataProvider="samples")
|
||||
@ParameterizedTest
|
||||
@MethodSource("data_samples")
|
||||
public void test_fromCalendrical(LocalDate isoDate, LocalDate iso) {
|
||||
assertEquals(IsoChronology.INSTANCE.date(iso), isoDate);
|
||||
assertEquals(isoDate, IsoChronology.INSTANCE.date(iso));
|
||||
}
|
||||
|
||||
@DataProvider(name="badDates")
|
||||
Object[][] data_badDates() {
|
||||
return new Object[][] {
|
||||
{2012, 0, 0},
|
||||
@ -175,9 +178,10 @@ public class TestIsoChronology {
|
||||
};
|
||||
}
|
||||
|
||||
@Test(dataProvider="badDates", expectedExceptions=DateTimeException.class)
|
||||
@ParameterizedTest
|
||||
@MethodSource("data_badDates")
|
||||
public void test_badDates(int year, int month, int dom) {
|
||||
IsoChronology.INSTANCE.date(year, month, dom);
|
||||
Assertions.assertThrows(DateTimeException.class, () -> IsoChronology.INSTANCE.date(year, month, dom));
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -186,20 +190,20 @@ public class TestIsoChronology {
|
||||
int month = 5;
|
||||
int dayOfMonth = 5;
|
||||
LocalDate test = IsoChronology.INSTANCE.date(IsoEra.BCE, year, month, dayOfMonth);
|
||||
assertEquals(test.getEra(), IsoEra.BCE);
|
||||
assertEquals(test.get(ChronoField.YEAR_OF_ERA), year);
|
||||
assertEquals(test.get(ChronoField.MONTH_OF_YEAR), month);
|
||||
assertEquals(test.get(ChronoField.DAY_OF_MONTH), dayOfMonth);
|
||||
assertEquals(IsoEra.BCE, test.getEra());
|
||||
assertEquals(year, test.get(ChronoField.YEAR_OF_ERA));
|
||||
assertEquals(month, test.get(ChronoField.MONTH_OF_YEAR));
|
||||
assertEquals(dayOfMonth, test.get(ChronoField.DAY_OF_MONTH));
|
||||
|
||||
assertEquals(test.get(YEAR), 1 + (-1 * year));
|
||||
assertEquals(test.get(ERA), 0);
|
||||
assertEquals(test.get(YEAR_OF_ERA), year);
|
||||
assertEquals(1 + (-1 * year), test.get(YEAR));
|
||||
assertEquals(0, test.get(ERA));
|
||||
assertEquals(year, test.get(YEAR_OF_ERA));
|
||||
}
|
||||
|
||||
@SuppressWarnings({ "unchecked", "rawtypes" })
|
||||
@Test(expectedExceptions=ClassCastException.class)
|
||||
@Test
|
||||
public void test_date_withEra_withWrongEra() {
|
||||
IsoChronology.INSTANCE.date((Era) HijrahEra.AH, 1, 1, 1);
|
||||
Assertions.assertThrows(ClassCastException.class, () -> IsoChronology.INSTANCE.date((Era) HijrahEra.AH, 1, 1, 1));
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
@ -209,14 +213,14 @@ public class TestIsoChronology {
|
||||
public void test_adjust1() {
|
||||
LocalDate base = IsoChronology.INSTANCE.date(1728, 10, 28);
|
||||
LocalDate test = base.with(TemporalAdjusters.lastDayOfMonth());
|
||||
assertEquals(test, IsoChronology.INSTANCE.date(1728, 10, 31));
|
||||
assertEquals(IsoChronology.INSTANCE.date(1728, 10, 31), test);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test_adjust2() {
|
||||
LocalDate base = IsoChronology.INSTANCE.date(1728, 12, 2);
|
||||
LocalDate test = base.with(TemporalAdjusters.lastDayOfMonth());
|
||||
assertEquals(test, IsoChronology.INSTANCE.date(1728, 12, 31));
|
||||
assertEquals(IsoChronology.INSTANCE.date(1728, 12, 31), test);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
@ -226,13 +230,13 @@ public class TestIsoChronology {
|
||||
public void test_adjust_toLocalDate() {
|
||||
LocalDate isoDate = IsoChronology.INSTANCE.date(1726, 1, 4);
|
||||
LocalDate test = isoDate.with(LocalDate.of(2012, 7, 6));
|
||||
assertEquals(test, IsoChronology.INSTANCE.date(2012, 7, 6));
|
||||
assertEquals(IsoChronology.INSTANCE.date(2012, 7, 6), test);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test_adjust_toMonth() {
|
||||
LocalDate isoDate = IsoChronology.INSTANCE.date(1726, 1, 4);
|
||||
assertEquals(IsoChronology.INSTANCE.date(1726, 4, 4), isoDate.with(Month.APRIL));
|
||||
assertEquals(isoDate.with(Month.APRIL), IsoChronology.INSTANCE.date(1726, 4, 4));
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
@ -242,20 +246,19 @@ public class TestIsoChronology {
|
||||
public void test_LocalDate_adjustToISODate() {
|
||||
LocalDate isoDate = IsoChronology.INSTANCE.date(1728, 10, 29);
|
||||
LocalDate test = LocalDate.MIN.with(isoDate);
|
||||
assertEquals(test, LocalDate.of(1728, 10, 29));
|
||||
assertEquals(LocalDate.of(1728, 10, 29), test);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test_LocalDateTime_adjustToISODate() {
|
||||
LocalDate isoDate = IsoChronology.INSTANCE.date(1728, 10, 29);
|
||||
LocalDateTime test = LocalDateTime.MIN.with(isoDate);
|
||||
assertEquals(test, LocalDateTime.of(1728, 10, 29, 0, 0));
|
||||
assertEquals(LocalDateTime.of(1728, 10, 29, 0, 0), test);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
// isLeapYear()
|
||||
//-----------------------------------------------------------------------
|
||||
@DataProvider(name="leapYears")
|
||||
Object[][] leapYearInformation() {
|
||||
return new Object[][] {
|
||||
{2000, true},
|
||||
@ -267,9 +270,10 @@ public class TestIsoChronology {
|
||||
};
|
||||
}
|
||||
|
||||
@Test(dataProvider="leapYears")
|
||||
@ParameterizedTest
|
||||
@MethodSource("leapYearInformation")
|
||||
public void test_isLeapYear(int year, boolean isLeapYear) {
|
||||
assertEquals(IsoChronology.INSTANCE.isLeapYear(year), isLeapYear);
|
||||
assertEquals(isLeapYear, IsoChronology.INSTANCE.isLeapYear(year));
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
@ -277,13 +281,12 @@ public class TestIsoChronology {
|
||||
//-----------------------------------------------------------------------
|
||||
@Test
|
||||
public void test_now() {
|
||||
assertEquals(LocalDate.from(IsoChronology.INSTANCE.dateNow()), LocalDate.now());
|
||||
assertEquals(LocalDate.now(), LocalDate.from(IsoChronology.INSTANCE.dateNow()));
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
// toString()
|
||||
//-----------------------------------------------------------------------
|
||||
@DataProvider(name="toString")
|
||||
Object[][] data_toString() {
|
||||
return new Object[][] {
|
||||
{IsoChronology.INSTANCE.date(1, 1, 1), "0001-01-01"},
|
||||
@ -294,9 +297,10 @@ public class TestIsoChronology {
|
||||
};
|
||||
}
|
||||
|
||||
@Test(dataProvider="toString")
|
||||
@ParameterizedTest
|
||||
@MethodSource("data_toString")
|
||||
public void test_toString(LocalDate isoDate, String expected) {
|
||||
assertEquals(isoDate.toString(), expected);
|
||||
assertEquals(expected, isoDate.toString());
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2012, 2013, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2012, 2025, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
@ -54,8 +54,8 @@
|
||||
*/
|
||||
package tck.java.time.chrono;
|
||||
|
||||
import static org.testng.Assert.assertEquals;
|
||||
import static org.testng.Assert.assertTrue;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
@ -85,20 +85,21 @@ import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import org.testng.Assert;
|
||||
import org.testng.annotations.DataProvider;
|
||||
import org.testng.annotations.Test;
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.TestInstance;
|
||||
import org.junit.jupiter.params.ParameterizedTest;
|
||||
import org.junit.jupiter.params.provider.MethodSource;
|
||||
|
||||
/**
|
||||
* Test assertions that must be true for all built-in chronologies.
|
||||
*/
|
||||
@Test
|
||||
@TestInstance(TestInstance.Lifecycle.PER_CLASS)
|
||||
public class TCKChronoLocalDate {
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
// regular data factory for names and descriptions of available calendars
|
||||
//-----------------------------------------------------------------------
|
||||
@DataProvider(name = "calendars")
|
||||
Chronology[][] data_of_calendars() {
|
||||
return new Chronology[][]{
|
||||
{HijrahChronology.INSTANCE},
|
||||
@ -108,7 +109,8 @@ public class TCKChronoLocalDate {
|
||||
{ThaiBuddhistChronology.INSTANCE}};
|
||||
}
|
||||
|
||||
@Test(dataProvider="calendars")
|
||||
@ParameterizedTest
|
||||
@MethodSource("data_of_calendars")
|
||||
public void test_badWithAdjusterChrono(Chronology chrono) {
|
||||
LocalDate refDate = LocalDate.of(2013, 1, 1);
|
||||
ChronoLocalDate date = chrono.date(refDate);
|
||||
@ -119,19 +121,20 @@ public class TCKChronoLocalDate {
|
||||
if (chrono != chrono2) {
|
||||
try {
|
||||
date.with(adjuster);
|
||||
Assert.fail("WithAdjuster should have thrown a ClassCastException");
|
||||
Assertions.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");
|
||||
assertEquals(date2, result, "WithAdjuster failed to replace date");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Test(dataProvider="calendars")
|
||||
@ParameterizedTest
|
||||
@MethodSource("data_of_calendars")
|
||||
public void test_badPlusAdjusterChrono(Chronology chrono) {
|
||||
LocalDate refDate = LocalDate.of(2013, 1, 1);
|
||||
ChronoLocalDate date = chrono.date(refDate);
|
||||
@ -142,19 +145,20 @@ public class TCKChronoLocalDate {
|
||||
if (chrono != chrono2) {
|
||||
try {
|
||||
date.plus(adjuster);
|
||||
Assert.fail("WithAdjuster should have thrown a ClassCastException");
|
||||
Assertions.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");
|
||||
assertEquals(date2, result, "WithAdjuster failed to replace date");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Test(dataProvider="calendars")
|
||||
@ParameterizedTest
|
||||
@MethodSource("data_of_calendars")
|
||||
public void test_badMinusAdjusterChrono(Chronology chrono) {
|
||||
LocalDate refDate = LocalDate.of(2013, 1, 1);
|
||||
ChronoLocalDate date = chrono.date(refDate);
|
||||
@ -165,19 +169,20 @@ public class TCKChronoLocalDate {
|
||||
if (chrono != chrono2) {
|
||||
try {
|
||||
date.minus(adjuster);
|
||||
Assert.fail("WithAdjuster should have thrown a ClassCastException");
|
||||
Assertions.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");
|
||||
assertEquals(date2, result, "WithAdjuster failed to replace date");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Test(dataProvider="calendars")
|
||||
@ParameterizedTest
|
||||
@MethodSource("data_of_calendars")
|
||||
public void test_badPlusTemporalUnitChrono(Chronology chrono) {
|
||||
LocalDate refDate = LocalDate.of(2013, 1, 1);
|
||||
ChronoLocalDate date = chrono.date(refDate);
|
||||
@ -188,7 +193,7 @@ public class TCKChronoLocalDate {
|
||||
if (chrono != chrono2) {
|
||||
try {
|
||||
date.plus(1, adjuster);
|
||||
Assert.fail("TemporalUnit.doAdd plus should have thrown a ClassCastException" + date.getClass()
|
||||
Assertions.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
|
||||
@ -196,12 +201,13 @@ public class TCKChronoLocalDate {
|
||||
} else {
|
||||
// Same chronology,
|
||||
ChronoLocalDate result = date.plus(1, adjuster);
|
||||
assertEquals(result, date2, "WithAdjuster failed to replace date");
|
||||
assertEquals(date2, result, "WithAdjuster failed to replace date");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Test(dataProvider="calendars")
|
||||
@ParameterizedTest
|
||||
@MethodSource("data_of_calendars")
|
||||
public void test_badMinusTemporalUnitChrono(Chronology chrono) {
|
||||
LocalDate refDate = LocalDate.of(2013, 1, 1);
|
||||
ChronoLocalDate date = chrono.date(refDate);
|
||||
@ -212,7 +218,7 @@ public class TCKChronoLocalDate {
|
||||
if (chrono != chrono2) {
|
||||
try {
|
||||
date.minus(1, adjuster);
|
||||
Assert.fail("TemporalUnit.doAdd minus should have thrown a ClassCastException" + date.getClass()
|
||||
Assertions.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
|
||||
@ -220,12 +226,13 @@ public class TCKChronoLocalDate {
|
||||
} else {
|
||||
// Same chronology,
|
||||
ChronoLocalDate result = date.minus(1, adjuster);
|
||||
assertEquals(result, date2, "WithAdjuster failed to replace date");
|
||||
assertEquals(date2, result, "WithAdjuster failed to replace date");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Test(dataProvider="calendars")
|
||||
@ParameterizedTest
|
||||
@MethodSource("data_of_calendars")
|
||||
public void test_badTemporalFieldChrono(Chronology chrono) {
|
||||
LocalDate refDate = LocalDate.of(2013, 1, 1);
|
||||
ChronoLocalDate date = chrono.date(refDate);
|
||||
@ -236,7 +243,7 @@ public class TCKChronoLocalDate {
|
||||
if (chrono != chrono2) {
|
||||
try {
|
||||
date.with(adjuster, 1);
|
||||
Assert.fail("TemporalField doSet should have thrown a ClassCastException" + date.getClass()
|
||||
Assertions.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
|
||||
@ -244,7 +251,7 @@ public class TCKChronoLocalDate {
|
||||
} else {
|
||||
// Same chronology,
|
||||
ChronoLocalDate result = date.with(adjuster, 1);
|
||||
assertEquals(result, date2, "TemporalField doSet failed to replace date");
|
||||
assertEquals(date2, result, "TemporalField doSet failed to replace date");
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -252,7 +259,8 @@ public class TCKChronoLocalDate {
|
||||
//-----------------------------------------------------------------------
|
||||
// isBefore, isAfter, isEqual, DATE_COMPARATOR
|
||||
//-----------------------------------------------------------------------
|
||||
@Test(dataProvider="calendars")
|
||||
@ParameterizedTest
|
||||
@MethodSource("data_of_calendars")
|
||||
public void test_date_comparisons(Chronology chrono) {
|
||||
List<ChronoLocalDate> dates = new ArrayList<>();
|
||||
|
||||
@ -285,19 +293,19 @@ public class TCKChronoLocalDate {
|
||||
int cmp = ChronoLocalDate.timeLineOrder().compare(a, b);
|
||||
if (i < j) {
|
||||
assertTrue(cmp < 0, a + " compare " + b);
|
||||
assertEquals(a.isBefore(b), true, a + " isBefore " + b);
|
||||
assertEquals(a.isAfter(b), false, a + " isAfter " + b);
|
||||
assertEquals(a.isEqual(b), false, a + " isEqual " + b);
|
||||
assertEquals(true, a.isBefore(b), a + " isBefore " + b);
|
||||
assertEquals(false, a.isAfter(b), a + " isAfter " + b);
|
||||
assertEquals(false, a.isEqual(b), a + " isEqual " + b);
|
||||
} else if (i > j) {
|
||||
assertTrue(cmp > 0, a + " compare " + b);
|
||||
assertEquals(a.isBefore(b), false, a + " isBefore " + b);
|
||||
assertEquals(a.isAfter(b), true, a + " isAfter " + b);
|
||||
assertEquals(a.isEqual(b), false, a + " isEqual " + b);
|
||||
assertEquals(false, a.isBefore(b), a + " isBefore " + b);
|
||||
assertEquals(true, a.isAfter(b), a + " isAfter " + b);
|
||||
assertEquals(false, a.isEqual(b), a + " isEqual " + b);
|
||||
} else {
|
||||
assertTrue(cmp == 0, a + " compare " + b);
|
||||
assertEquals(a.isBefore(b), false, a + " isBefore " + b);
|
||||
assertEquals(a.isAfter(b), false, a + " isAfter " + b);
|
||||
assertEquals(a.isEqual(b), true, a + " isEqual " + b);
|
||||
assertEquals(false, a.isBefore(b), a + " isBefore " + b);
|
||||
assertEquals(false, a.isAfter(b), a + " isAfter " + b);
|
||||
assertEquals(true, a.isEqual(b), a + " isEqual " + b);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -306,26 +314,27 @@ public class TCKChronoLocalDate {
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
@Test(dataProvider="calendars")
|
||||
@ParameterizedTest
|
||||
@MethodSource("data_of_calendars")
|
||||
public void test_from_TemporalAccessor(Chronology chrono) {
|
||||
LocalDate refDate = LocalDate.of(2013, 1, 1);
|
||||
ChronoLocalDate date = chrono.date(refDate);
|
||||
ChronoLocalDate test1 = ChronoLocalDate.from(date);
|
||||
assertEquals(test1, date);
|
||||
assertEquals(date, test1);
|
||||
ChronoLocalDate test2 = ChronoLocalDate.from(date.atTime(LocalTime.of(12, 30)));
|
||||
assertEquals(test2, date);
|
||||
assertEquals(date, test2);
|
||||
ChronoLocalDate test3 = ChronoLocalDate.from(date.atTime(LocalTime.of(12, 30)).atZone(ZoneOffset.UTC));
|
||||
assertEquals(test3, date);
|
||||
assertEquals(date, test3);
|
||||
}
|
||||
|
||||
@Test(expectedExceptions = DateTimeException.class)
|
||||
@Test
|
||||
public void test_from_TemporalAccessor_timeOnly() {
|
||||
ChronoLocalDate.from(LocalTime.of(12, 30));
|
||||
Assertions.assertThrows(DateTimeException.class, () -> ChronoLocalDate.from(LocalTime.of(12, 30)));
|
||||
}
|
||||
|
||||
@Test(expectedExceptions = NullPointerException.class)
|
||||
@Test
|
||||
public void test_from_TemporalAccessor_null() {
|
||||
ChronoLocalDate.from(null);
|
||||
Assertions.assertThrows(NullPointerException.class, () -> ChronoLocalDate.from(null));
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2012, 2013, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2012, 2025, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
@ -54,8 +54,8 @@
|
||||
*/
|
||||
package tck.java.time.chrono;
|
||||
|
||||
import static org.testng.Assert.assertEquals;
|
||||
import static org.testng.Assert.assertTrue;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
@ -85,20 +85,21 @@ import java.time.temporal.ValueRange;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.testng.Assert;
|
||||
import org.testng.annotations.DataProvider;
|
||||
import org.testng.annotations.Test;
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.TestInstance;
|
||||
import org.junit.jupiter.params.ParameterizedTest;
|
||||
import org.junit.jupiter.params.provider.MethodSource;
|
||||
|
||||
/**
|
||||
* Test assertions that must be true for all built-in chronologies.
|
||||
*/
|
||||
@Test
|
||||
@TestInstance(TestInstance.Lifecycle.PER_CLASS)
|
||||
public class TCKChronoLocalDateTime {
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
// regular data factory for names and descriptions of available calendars
|
||||
//-----------------------------------------------------------------------
|
||||
@DataProvider(name = "calendars")
|
||||
Chronology[][] data_of_calendars() {
|
||||
return new Chronology[][]{
|
||||
{HijrahChronology.INSTANCE},
|
||||
@ -108,7 +109,8 @@ public class TCKChronoLocalDateTime {
|
||||
{ThaiBuddhistChronology.INSTANCE}};
|
||||
}
|
||||
|
||||
@Test(dataProvider="calendars")
|
||||
@ParameterizedTest
|
||||
@MethodSource("data_of_calendars")
|
||||
public void test_badWithAdjusterChrono(Chronology chrono) {
|
||||
LocalDate refDate = LocalDate.of(2013, 1, 1);
|
||||
ChronoLocalDateTime<?> cdt = chrono.date(refDate).atTime(LocalTime.NOON);
|
||||
@ -119,7 +121,7 @@ public class TCKChronoLocalDateTime {
|
||||
if (chrono != chrono2) {
|
||||
try {
|
||||
cdt.with(adjuster);
|
||||
Assert.fail("WithAdjuster should have thrown a ClassCastException, "
|
||||
Assertions.fail("WithAdjuster should have thrown a ClassCastException, "
|
||||
+ "required: " + cdt + ", supplied: " + cdt2);
|
||||
} catch (ClassCastException cce) {
|
||||
// Expected exception; not an error
|
||||
@ -127,12 +129,13 @@ public class TCKChronoLocalDateTime {
|
||||
} else {
|
||||
// Same chronology,
|
||||
ChronoLocalDateTime<?> result = cdt.with(adjuster);
|
||||
assertEquals(result, cdt2, "WithAdjuster failed to replace date");
|
||||
assertEquals(cdt2, result, "WithAdjuster failed to replace date");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Test(dataProvider="calendars")
|
||||
@ParameterizedTest
|
||||
@MethodSource("data_of_calendars")
|
||||
public void test_badPlusAdjusterChrono(Chronology chrono) {
|
||||
LocalDate refDate = LocalDate.of(2013, 1, 1);
|
||||
ChronoLocalDateTime<?> cdt = chrono.date(refDate).atTime(LocalTime.NOON);
|
||||
@ -143,7 +146,7 @@ public class TCKChronoLocalDateTime {
|
||||
if (chrono != chrono2) {
|
||||
try {
|
||||
cdt.plus(adjuster);
|
||||
Assert.fail("WithAdjuster should have thrown a ClassCastException, "
|
||||
Assertions.fail("WithAdjuster should have thrown a ClassCastException, "
|
||||
+ "required: " + cdt + ", supplied: " + cdt2);
|
||||
} catch (ClassCastException cce) {
|
||||
// Expected exception; not an error
|
||||
@ -151,12 +154,13 @@ public class TCKChronoLocalDateTime {
|
||||
} else {
|
||||
// Same chronology,
|
||||
ChronoLocalDateTime<?> result = cdt.plus(adjuster);
|
||||
assertEquals(result, cdt2, "WithAdjuster failed to replace date time");
|
||||
assertEquals(cdt2, result, "WithAdjuster failed to replace date time");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Test(dataProvider="calendars")
|
||||
@ParameterizedTest
|
||||
@MethodSource("data_of_calendars")
|
||||
public void test_badMinusAdjusterChrono(Chronology chrono) {
|
||||
LocalDate refDate = LocalDate.of(2013, 1, 1);
|
||||
ChronoLocalDateTime<?> cdt = chrono.date(refDate).atTime(LocalTime.NOON);
|
||||
@ -167,7 +171,7 @@ public class TCKChronoLocalDateTime {
|
||||
if (chrono != chrono2) {
|
||||
try {
|
||||
cdt.minus(adjuster);
|
||||
Assert.fail("WithAdjuster should have thrown a ClassCastException, "
|
||||
Assertions.fail("WithAdjuster should have thrown a ClassCastException, "
|
||||
+ "required: " + cdt + ", supplied: " + cdt2);
|
||||
} catch (ClassCastException cce) {
|
||||
// Expected exception; not an error
|
||||
@ -175,12 +179,13 @@ public class TCKChronoLocalDateTime {
|
||||
} else {
|
||||
// Same chronology,
|
||||
ChronoLocalDateTime<?> result = cdt.minus(adjuster);
|
||||
assertEquals(result, cdt2, "WithAdjuster failed to replace date");
|
||||
assertEquals(cdt2, result, "WithAdjuster failed to replace date");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Test(dataProvider="calendars")
|
||||
@ParameterizedTest
|
||||
@MethodSource("data_of_calendars")
|
||||
public void test_badPlusTemporalUnitChrono(Chronology chrono) {
|
||||
LocalDate refDate = LocalDate.of(2013, 1, 1);
|
||||
ChronoLocalDateTime<?> cdt = chrono.date(refDate).atTime(LocalTime.NOON);
|
||||
@ -191,7 +196,7 @@ public class TCKChronoLocalDateTime {
|
||||
if (chrono != chrono2) {
|
||||
try {
|
||||
cdt.plus(1, adjuster);
|
||||
Assert.fail("TemporalUnit.doPlus plus should have thrown a ClassCastException" + cdt
|
||||
Assertions.fail("TemporalUnit.doPlus plus should have thrown a ClassCastException" + cdt
|
||||
+ ", can not be cast to " + cdt2);
|
||||
} catch (ClassCastException cce) {
|
||||
// Expected exception; not an error
|
||||
@ -199,12 +204,13 @@ public class TCKChronoLocalDateTime {
|
||||
} else {
|
||||
// Same chronology,
|
||||
ChronoLocalDateTime<?> result = cdt.plus(1, adjuster);
|
||||
assertEquals(result, cdt2, "WithAdjuster failed to replace date");
|
||||
assertEquals(cdt2, result, "WithAdjuster failed to replace date");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Test(dataProvider="calendars")
|
||||
@ParameterizedTest
|
||||
@MethodSource("data_of_calendars")
|
||||
public void test_badMinusTemporalUnitChrono(Chronology chrono) {
|
||||
LocalDate refDate = LocalDate.of(2013, 1, 1);
|
||||
ChronoLocalDateTime<?> cdt = chrono.date(refDate).atTime(LocalTime.NOON);
|
||||
@ -215,7 +221,7 @@ public class TCKChronoLocalDateTime {
|
||||
if (chrono != chrono2) {
|
||||
try {
|
||||
cdt.minus(1, adjuster);
|
||||
Assert.fail("TemporalUnit.doPlus minus should have thrown a ClassCastException" + cdt.getClass()
|
||||
Assertions.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
|
||||
@ -223,12 +229,13 @@ public class TCKChronoLocalDateTime {
|
||||
} else {
|
||||
// Same chronology,
|
||||
ChronoLocalDateTime<?> result = cdt.minus(1, adjuster);
|
||||
assertEquals(result, cdt2, "WithAdjuster failed to replace date");
|
||||
assertEquals(cdt2, result, "WithAdjuster failed to replace date");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Test(dataProvider="calendars")
|
||||
@ParameterizedTest
|
||||
@MethodSource("data_of_calendars")
|
||||
public void test_badTemporalFieldChrono(Chronology chrono) {
|
||||
LocalDate refDate = LocalDate.of(2013, 1, 1);
|
||||
ChronoLocalDateTime<?> cdt = chrono.date(refDate).atTime(LocalTime.NOON);
|
||||
@ -239,7 +246,7 @@ public class TCKChronoLocalDateTime {
|
||||
if (chrono != chrono2) {
|
||||
try {
|
||||
cdt.with(adjuster, 1);
|
||||
Assert.fail("TemporalField doWith() should have thrown a ClassCastException" + cdt.getClass()
|
||||
Assertions.fail("TemporalField doWith() should have thrown a ClassCastException" + cdt.getClass()
|
||||
+ ", can not be cast to " + cdt2.getClass());
|
||||
} catch (ClassCastException cce) {
|
||||
// Expected exception; not an error
|
||||
@ -247,7 +254,7 @@ public class TCKChronoLocalDateTime {
|
||||
} else {
|
||||
// Same chronology,
|
||||
ChronoLocalDateTime<?> result = cdt.with(adjuster, 1);
|
||||
assertEquals(result, cdt2, "TemporalField doWith() failed to replace date");
|
||||
assertEquals(cdt2, result, "TemporalField doWith() failed to replace date");
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -255,7 +262,8 @@ public class TCKChronoLocalDateTime {
|
||||
//-----------------------------------------------------------------------
|
||||
// isBefore, isAfter, isEqual
|
||||
//-----------------------------------------------------------------------
|
||||
@Test(dataProvider="calendars")
|
||||
@ParameterizedTest
|
||||
@MethodSource("data_of_calendars")
|
||||
public void test_datetime_comparisons(Chronology chrono) {
|
||||
List<ChronoLocalDateTime<?>> dates = new ArrayList<>();
|
||||
|
||||
@ -296,19 +304,19 @@ public class TCKChronoLocalDateTime {
|
||||
int cmp = ChronoLocalDateTime.timeLineOrder().compare(a, b);
|
||||
if (i < j) {
|
||||
assertTrue(cmp < 0, a + " compare " + b);
|
||||
assertEquals(a.isBefore(b), true, a + " isBefore " + b);
|
||||
assertEquals(a.isAfter(b), false, a + " isAfter " + b);
|
||||
assertEquals(a.isEqual(b), false, a + " isEqual " + b);
|
||||
assertEquals(true, a.isBefore(b), a + " isBefore " + b);
|
||||
assertEquals(false, a.isAfter(b), a + " isAfter " + b);
|
||||
assertEquals(false, a.isEqual(b), a + " isEqual " + b);
|
||||
} else if (i > j) {
|
||||
assertTrue(cmp > 0, a + " compare " + b);
|
||||
assertEquals(a.isBefore(b), false, a + " isBefore " + b);
|
||||
assertEquals(a.isAfter(b), true, a + " isAfter " + b);
|
||||
assertEquals(a.isEqual(b), false, a + " isEqual " + b);
|
||||
assertEquals(false, a.isBefore(b), a + " isBefore " + b);
|
||||
assertEquals(true, a.isAfter(b), a + " isAfter " + b);
|
||||
assertEquals(false, a.isEqual(b), a + " isEqual " + b);
|
||||
} else {
|
||||
assertTrue(cmp == 0, a + " compare " + b);
|
||||
assertEquals(a.isBefore(b), false, a + " isBefore " + b);
|
||||
assertEquals(a.isAfter(b), false, a + " isAfter " + b);
|
||||
assertEquals(a.isEqual(b), true, a + " isEqual " + b);
|
||||
assertEquals(false, a.isBefore(b), a + " isBefore " + b);
|
||||
assertEquals(false, a.isAfter(b), a + " isAfter " + b);
|
||||
assertEquals(true, a.isEqual(b), a + " isEqual " + b);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -316,36 +324,38 @@ public class TCKChronoLocalDateTime {
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
@Test(dataProvider="calendars")
|
||||
@ParameterizedTest
|
||||
@MethodSource("data_of_calendars")
|
||||
public void test_from_TemporalAccessor(Chronology chrono) {
|
||||
LocalDateTime refDateTime = LocalDateTime.of(2013, 1, 1, 12, 30);
|
||||
ChronoLocalDateTime<?> dateTime = chrono.localDateTime(refDateTime);
|
||||
ChronoLocalDateTime<?> test1 = ChronoLocalDateTime.from(dateTime);
|
||||
assertEquals(test1, dateTime);
|
||||
assertEquals(dateTime, test1);
|
||||
ChronoLocalDateTime<?> test2 = ChronoLocalDateTime.from(dateTime.atZone(ZoneOffset.UTC));
|
||||
assertEquals(test2, dateTime);
|
||||
assertEquals(dateTime, test2);
|
||||
}
|
||||
|
||||
@Test(expectedExceptions = DateTimeException.class)
|
||||
@Test
|
||||
public void test_from_TemporalAccessor_dateOnly() {
|
||||
ChronoLocalDateTime.from(LocalDate.of(2013, 1, 1));
|
||||
Assertions.assertThrows(DateTimeException.class, () -> ChronoLocalDateTime.from(LocalDate.of(2013, 1, 1)));
|
||||
}
|
||||
|
||||
@Test(expectedExceptions = DateTimeException.class)
|
||||
@Test
|
||||
public void test_from_TemporalAccessor_timeOnly() {
|
||||
ChronoLocalDateTime.from(LocalTime.of(12, 30));
|
||||
Assertions.assertThrows(DateTimeException.class, () -> ChronoLocalDateTime.from(LocalTime.of(12, 30)));
|
||||
}
|
||||
|
||||
@Test(expectedExceptions = NullPointerException.class)
|
||||
@Test
|
||||
public void test_from_TemporalAccessor_null() {
|
||||
ChronoLocalDateTime.from(null);
|
||||
Assertions.assertThrows(NullPointerException.class, () -> ChronoLocalDateTime.from(null));
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
@Test(dataProvider="calendars")
|
||||
@ParameterizedTest
|
||||
@MethodSource("data_of_calendars")
|
||||
public void test_getChronology(Chronology chrono) {
|
||||
ChronoLocalDateTime<?> test = chrono.localDateTime(LocalDateTime.of(2010, 6, 30, 11, 30));
|
||||
assertEquals(test.getChronology(), chrono);
|
||||
assertEquals(chrono, test.getChronology());
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2013, 2014, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2013, 2025, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
@ -58,7 +58,8 @@ import static java.time.temporal.ChronoUnit.DAYS;
|
||||
import static java.time.temporal.ChronoUnit.HOURS;
|
||||
import static java.time.temporal.ChronoUnit.MONTHS;
|
||||
import static java.time.temporal.ChronoUnit.YEARS;
|
||||
import static org.testng.Assert.assertEquals;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
@ -78,16 +79,17 @@ import java.time.chrono.ThaiBuddhistChronology;
|
||||
import java.time.temporal.Temporal;
|
||||
import java.time.temporal.UnsupportedTemporalTypeException;
|
||||
|
||||
import org.testng.annotations.DataProvider;
|
||||
import org.testng.annotations.Test;
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.TestInstance;
|
||||
import org.junit.jupiter.params.ParameterizedTest;
|
||||
import org.junit.jupiter.params.provider.MethodSource;
|
||||
|
||||
@Test
|
||||
@TestInstance(TestInstance.Lifecycle.PER_CLASS)
|
||||
public class TCKChronoPeriod {
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
// regular data factory for names and descriptions of available calendars
|
||||
//-----------------------------------------------------------------------
|
||||
@DataProvider(name = "calendars")
|
||||
Chronology[][] data_of_calendars() {
|
||||
return new Chronology[][]{
|
||||
{HijrahChronology.INSTANCE},
|
||||
@ -100,7 +102,8 @@ public class TCKChronoPeriod {
|
||||
//-----------------------------------------------------------------------
|
||||
// Test Serialization of Calendars
|
||||
//-----------------------------------------------------------------------
|
||||
@Test(dataProvider="calendars")
|
||||
@ParameterizedTest
|
||||
@MethodSource("data_of_calendars")
|
||||
public void test_serialization(Chronology chrono) throws Exception {
|
||||
ChronoPeriod period = chrono.period(1, 2, 3);
|
||||
ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
||||
@ -111,167 +114,195 @@ public class TCKChronoPeriod {
|
||||
|
||||
ObjectInputStream in = new ObjectInputStream(bais);
|
||||
ChronoPeriod ser = (ChronoPeriod) in.readObject();
|
||||
assertEquals(ser, period, "deserialized ChronoPeriod is wrong");
|
||||
assertEquals(period, ser, "deserialized ChronoPeriod is wrong");
|
||||
}
|
||||
|
||||
@Test(dataProvider="calendars")
|
||||
@ParameterizedTest
|
||||
@MethodSource("data_of_calendars")
|
||||
public void test_get(Chronology chrono) {
|
||||
ChronoPeriod period = chrono.period(1, 2, 3);
|
||||
assertEquals(period.get(YEARS), 1);
|
||||
assertEquals(period.get(MONTHS), 2);
|
||||
assertEquals(period.get(DAYS), 3);
|
||||
assertEquals(1, period.get(YEARS));
|
||||
assertEquals(2, period.get(MONTHS));
|
||||
assertEquals(3, period.get(DAYS));
|
||||
}
|
||||
|
||||
@Test(dataProvider="calendars", expectedExceptions=UnsupportedTemporalTypeException.class)
|
||||
@ParameterizedTest
|
||||
@MethodSource("data_of_calendars")
|
||||
public void test_get_unsupported(Chronology chrono) {
|
||||
ChronoPeriod period = chrono.period(1, 2, 3);
|
||||
period.get(HOURS);
|
||||
Assertions.assertThrows(UnsupportedTemporalTypeException.class, () -> {
|
||||
ChronoPeriod period = chrono.period(1, 2, 3);
|
||||
period.get(HOURS);
|
||||
});
|
||||
}
|
||||
|
||||
@Test(dataProvider="calendars")
|
||||
@ParameterizedTest
|
||||
@MethodSource("data_of_calendars")
|
||||
public void test_getUnits(Chronology chrono) {
|
||||
ChronoPeriod period = chrono.period(1, 2, 3);
|
||||
assertEquals(period.getUnits().size(), 3);
|
||||
assertEquals(period.getUnits().get(0), YEARS);
|
||||
assertEquals(period.getUnits().get(1), MONTHS);
|
||||
assertEquals(period.getUnits().get(2), DAYS);
|
||||
assertEquals(3, period.getUnits().size());
|
||||
assertEquals(YEARS, period.getUnits().get(0));
|
||||
assertEquals(MONTHS, period.getUnits().get(1));
|
||||
assertEquals(DAYS, period.getUnits().get(2));
|
||||
}
|
||||
|
||||
@Test(dataProvider="calendars")
|
||||
@ParameterizedTest
|
||||
@MethodSource("data_of_calendars")
|
||||
public void test_getChronology(Chronology chrono) {
|
||||
ChronoPeriod period = chrono.period(1, 2, 3);
|
||||
assertEquals(period.getChronology(), chrono);
|
||||
assertEquals(chrono, period.getChronology());
|
||||
}
|
||||
|
||||
@Test(dataProvider="calendars")
|
||||
@ParameterizedTest
|
||||
@MethodSource("data_of_calendars")
|
||||
public void test_isZero_isNegative(Chronology chrono) {
|
||||
ChronoPeriod periodPositive = chrono.period(1, 2, 3);
|
||||
assertEquals(periodPositive.isZero(), false);
|
||||
assertEquals(periodPositive.isNegative(), false);
|
||||
assertEquals(false, periodPositive.isZero());
|
||||
assertEquals(false, periodPositive.isNegative());
|
||||
|
||||
ChronoPeriod periodZero = chrono.period(0, 0, 0);
|
||||
assertEquals(periodZero.isZero(), true);
|
||||
assertEquals(periodZero.isNegative(), false);
|
||||
assertEquals(true, periodZero.isZero());
|
||||
assertEquals(false, periodZero.isNegative());
|
||||
|
||||
ChronoPeriod periodNegative = chrono.period(-1, 0, 0);
|
||||
assertEquals(periodNegative.isZero(), false);
|
||||
assertEquals(periodNegative.isNegative(), true);
|
||||
assertEquals(false, periodNegative.isZero());
|
||||
assertEquals(true, periodNegative.isNegative());
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
@Test(dataProvider="calendars")
|
||||
@ParameterizedTest
|
||||
@MethodSource("data_of_calendars")
|
||||
public void test_plus(Chronology chrono) {
|
||||
ChronoPeriod period = chrono.period(1, 2, 3);
|
||||
ChronoPeriod period2 = chrono.period(2, 3, 4);
|
||||
ChronoPeriod result = period.plus(period2);
|
||||
assertEquals(result, chrono.period(3, 5, 7));
|
||||
assertEquals(chrono.period(3, 5, 7), result);
|
||||
}
|
||||
|
||||
@Test(dataProvider="calendars", expectedExceptions=DateTimeException.class)
|
||||
@ParameterizedTest
|
||||
@MethodSource("data_of_calendars")
|
||||
public void test_plus_wrongChrono(Chronology chrono) {
|
||||
ChronoPeriod period = chrono.period(1, 2, 3);
|
||||
ChronoPeriod isoPeriod = Period.of(2, 3, 4);
|
||||
ChronoPeriod thaiPeriod = ThaiBuddhistChronology.INSTANCE.period(2, 3, 4);
|
||||
// one of these two will fail
|
||||
period.plus(isoPeriod);
|
||||
period.plus(thaiPeriod);
|
||||
Assertions.assertThrows(DateTimeException.class, () -> {
|
||||
ChronoPeriod period = chrono.period(1, 2, 3);
|
||||
ChronoPeriod isoPeriod = Period.of(2, 3, 4);
|
||||
ChronoPeriod thaiPeriod = ThaiBuddhistChronology.INSTANCE.period(2, 3, 4);
|
||||
// one of these two will fail
|
||||
period.plus(isoPeriod);
|
||||
period.plus(thaiPeriod);
|
||||
});
|
||||
}
|
||||
|
||||
@Test(dataProvider="calendars")
|
||||
@ParameterizedTest
|
||||
@MethodSource("data_of_calendars")
|
||||
public void test_minus(Chronology chrono) {
|
||||
ChronoPeriod period = chrono.period(1, 2, 3);
|
||||
ChronoPeriod period2 = chrono.period(2, 3, 4);
|
||||
ChronoPeriod result = period.minus(period2);
|
||||
assertEquals(result, chrono.period(-1, -1, -1));
|
||||
assertEquals(chrono.period(-1, -1, -1), result);
|
||||
}
|
||||
|
||||
@Test(dataProvider="calendars", expectedExceptions=DateTimeException.class)
|
||||
@ParameterizedTest
|
||||
@MethodSource("data_of_calendars")
|
||||
public void test_minus_wrongChrono(Chronology chrono) {
|
||||
ChronoPeriod period = chrono.period(1, 2, 3);
|
||||
ChronoPeriod isoPeriod = Period.of(2, 3, 4);
|
||||
ChronoPeriod thaiPeriod = ThaiBuddhistChronology.INSTANCE.period(2, 3, 4);
|
||||
// one of these two will fail
|
||||
period.minus(isoPeriod);
|
||||
period.minus(thaiPeriod);
|
||||
Assertions.assertThrows(DateTimeException.class, () -> {
|
||||
ChronoPeriod period = chrono.period(1, 2, 3);
|
||||
ChronoPeriod isoPeriod = Period.of(2, 3, 4);
|
||||
ChronoPeriod thaiPeriod = ThaiBuddhistChronology.INSTANCE.period(2, 3, 4);
|
||||
// one of these two will fail
|
||||
period.minus(isoPeriod);
|
||||
period.minus(thaiPeriod);
|
||||
});
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
@Test(dataProvider="calendars")
|
||||
@ParameterizedTest
|
||||
@MethodSource("data_of_calendars")
|
||||
public void test_addTo(Chronology chrono) {
|
||||
ChronoPeriod period = chrono.period(1, 2, 3);
|
||||
ChronoLocalDate date = chrono.dateNow();
|
||||
Temporal result = period.addTo(date);
|
||||
assertEquals(result, date.plus(14, MONTHS).plus(3, DAYS));
|
||||
assertEquals(date.plus(14, MONTHS).plus(3, DAYS), result);
|
||||
}
|
||||
|
||||
@Test(dataProvider="calendars", expectedExceptions=DateTimeException.class)
|
||||
@ParameterizedTest
|
||||
@MethodSource("data_of_calendars")
|
||||
public void test_addTo_wrongChrono(Chronology chrono) {
|
||||
ChronoPeriod period = chrono.period(1, 2, 3);
|
||||
ChronoLocalDate isoDate = LocalDate.of(2000, 1, 1);
|
||||
ChronoLocalDate thaiDate = ThaiBuddhistChronology.INSTANCE.date(2000, 1, 1);
|
||||
// one of these two will fail
|
||||
period.addTo(isoDate);
|
||||
period.addTo(thaiDate);
|
||||
Assertions.assertThrows(DateTimeException.class, () -> {
|
||||
ChronoPeriod period = chrono.period(1, 2, 3);
|
||||
ChronoLocalDate isoDate = LocalDate.of(2000, 1, 1);
|
||||
ChronoLocalDate thaiDate = ThaiBuddhistChronology.INSTANCE.date(2000, 1, 1);
|
||||
// one of these two will fail
|
||||
period.addTo(isoDate);
|
||||
period.addTo(thaiDate);
|
||||
});
|
||||
}
|
||||
|
||||
@Test(dataProvider="calendars")
|
||||
@ParameterizedTest
|
||||
@MethodSource("data_of_calendars")
|
||||
public void test_subtractFrom(Chronology chrono) {
|
||||
ChronoPeriod period = chrono.period(1, 2, 3);
|
||||
ChronoLocalDate date = chrono.dateNow();
|
||||
Temporal result = period.subtractFrom(date);
|
||||
assertEquals(result, date.minus(14, MONTHS).minus(3, DAYS));
|
||||
assertEquals(date.minus(14, MONTHS).minus(3, DAYS), result);
|
||||
}
|
||||
|
||||
@Test(dataProvider="calendars", expectedExceptions=DateTimeException.class)
|
||||
@ParameterizedTest
|
||||
@MethodSource("data_of_calendars")
|
||||
public void test_subtractFrom_wrongChrono(Chronology chrono) {
|
||||
ChronoPeriod period = chrono.period(1, 2, 3);
|
||||
ChronoLocalDate isoDate = LocalDate.of(2000, 1, 1);
|
||||
ChronoLocalDate thaiDate = ThaiBuddhistChronology.INSTANCE.date(2000, 1, 1);
|
||||
// one of these two will fail
|
||||
period.subtractFrom(isoDate);
|
||||
period.subtractFrom(thaiDate);
|
||||
Assertions.assertThrows(DateTimeException.class, () -> {
|
||||
ChronoPeriod period = chrono.period(1, 2, 3);
|
||||
ChronoLocalDate isoDate = LocalDate.of(2000, 1, 1);
|
||||
ChronoLocalDate thaiDate = ThaiBuddhistChronology.INSTANCE.date(2000, 1, 1);
|
||||
// one of these two will fail
|
||||
period.subtractFrom(isoDate);
|
||||
period.subtractFrom(thaiDate);
|
||||
});
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
@Test(dataProvider="calendars")
|
||||
@ParameterizedTest
|
||||
@MethodSource("data_of_calendars")
|
||||
public void test_negated(Chronology chrono) {
|
||||
ChronoPeriod period = chrono.period(1, 2, 3);
|
||||
assertEquals(period.negated(), chrono.period(-1, -2, -3));
|
||||
assertEquals(chrono.period(-1, -2, -3), period.negated());
|
||||
}
|
||||
|
||||
@Test(dataProvider="calendars")
|
||||
@ParameterizedTest
|
||||
@MethodSource("data_of_calendars")
|
||||
public void test_multipliedBy(Chronology chrono) {
|
||||
ChronoPeriod period = chrono.period(1, 2, 3);
|
||||
assertEquals(period.multipliedBy(3), chrono.period(3, 6, 9));
|
||||
assertEquals(chrono.period(3, 6, 9), period.multipliedBy(3));
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
@Test(dataProvider="calendars")
|
||||
@ParameterizedTest
|
||||
@MethodSource("data_of_calendars")
|
||||
public void test_equals_equal(Chronology chrono) {
|
||||
ChronoPeriod a1 = chrono.period(1, 2, 3);
|
||||
ChronoPeriod a2 = chrono.period(1, 2, 3);
|
||||
assertEquals(a1, a1);
|
||||
assertEquals(a1, a2);
|
||||
assertEquals(a2, a1);
|
||||
assertEquals(a1, a2);
|
||||
assertEquals(a2, a2);
|
||||
assertEquals(a1.hashCode(), a2.hashCode());
|
||||
assertEquals(a2.hashCode(), a1.hashCode());
|
||||
}
|
||||
|
||||
@Test(dataProvider="calendars")
|
||||
@ParameterizedTest
|
||||
@MethodSource("data_of_calendars")
|
||||
public void test_equals_notEqual(Chronology chrono) {
|
||||
ChronoPeriod a = chrono.period(1, 2, 3);
|
||||
ChronoPeriod b = chrono.period(2, 2, 3);
|
||||
assertEquals(a.equals(b), false);
|
||||
assertEquals(b.equals(a), false);
|
||||
assertEquals(a.equals(""), false);
|
||||
assertEquals(a.equals(null), false);
|
||||
assertEquals(false, a.equals(b));
|
||||
assertEquals(false, b.equals(a));
|
||||
assertEquals(false, a.equals(""));
|
||||
assertEquals(false, a.equals(null));
|
||||
}
|
||||
|
||||
@Test(dataProvider="calendars")
|
||||
@ParameterizedTest
|
||||
@MethodSource("data_of_calendars")
|
||||
public void test_toString(Chronology chrono) {
|
||||
ChronoPeriod period = chrono.period(1, 2, 3);
|
||||
if (period instanceof Period == false) {
|
||||
assertEquals(period.toString(), chrono.getId() + " P1Y2M3D");
|
||||
assertEquals(chrono.getId() + " P1Y2M3D", period.toString());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2012, 2013, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2012, 2025, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
@ -54,8 +54,8 @@
|
||||
*/
|
||||
package tck.java.time.chrono;
|
||||
|
||||
import static org.testng.Assert.assertEquals;
|
||||
import static org.testng.Assert.assertTrue;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
@ -86,20 +86,21 @@ import java.time.temporal.ValueRange;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.testng.Assert;
|
||||
import org.testng.annotations.DataProvider;
|
||||
import org.testng.annotations.Test;
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.TestInstance;
|
||||
import org.junit.jupiter.params.ParameterizedTest;
|
||||
import org.junit.jupiter.params.provider.MethodSource;
|
||||
|
||||
/**
|
||||
* Test assertions that must be true for all built-in chronologies.
|
||||
*/
|
||||
@Test
|
||||
@TestInstance(TestInstance.Lifecycle.PER_CLASS)
|
||||
public class TCKChronoZonedDateTime {
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
// regular data factory for names and descriptions of available calendars
|
||||
//-----------------------------------------------------------------------
|
||||
@DataProvider(name = "calendars")
|
||||
Chronology[][] data_of_calendars() {
|
||||
return new Chronology[][]{
|
||||
{HijrahChronology.INSTANCE},
|
||||
@ -110,7 +111,8 @@ public class TCKChronoZonedDateTime {
|
||||
};
|
||||
}
|
||||
|
||||
@Test(dataProvider="calendars")
|
||||
@ParameterizedTest
|
||||
@MethodSource("data_of_calendars")
|
||||
public void test_badWithAdjusterChrono(Chronology chrono) {
|
||||
LocalDate refDate = LocalDate.of(2013, 1, 1);
|
||||
ChronoZonedDateTime<?> czdt = chrono.date(refDate).atTime(LocalTime.NOON).atZone(ZoneOffset.UTC);
|
||||
@ -121,19 +123,20 @@ public class TCKChronoZonedDateTime {
|
||||
if (chrono != chrono2) {
|
||||
try {
|
||||
czdt.with(adjuster);
|
||||
Assert.fail("WithAdjuster should have thrown a ClassCastException, "
|
||||
Assertions.fail("WithAdjuster should have thrown a ClassCastException, "
|
||||
+ "required: " + czdt + ", supplied: " + czdt2);
|
||||
} catch (ClassCastException cce) {
|
||||
// Expected exception; not an error
|
||||
}
|
||||
} else {
|
||||
ChronoZonedDateTime<?> result = czdt.with(adjuster);
|
||||
assertEquals(result, czdt2, "WithAdjuster failed to replace date");
|
||||
assertEquals(czdt2, result, "WithAdjuster failed to replace date");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Test(dataProvider="calendars")
|
||||
@ParameterizedTest
|
||||
@MethodSource("data_of_calendars")
|
||||
public void test_badPlusAdjusterChrono(Chronology chrono) {
|
||||
LocalDate refDate = LocalDate.of(2013, 1, 1);
|
||||
ChronoZonedDateTime<?> czdt = chrono.date(refDate).atTime(LocalTime.NOON).atZone(ZoneOffset.UTC);
|
||||
@ -144,7 +147,7 @@ public class TCKChronoZonedDateTime {
|
||||
if (chrono != chrono2) {
|
||||
try {
|
||||
czdt.plus(adjuster);
|
||||
Assert.fail("WithAdjuster should have thrown a ClassCastException, "
|
||||
Assertions.fail("WithAdjuster should have thrown a ClassCastException, "
|
||||
+ "required: " + czdt + ", supplied: " + czdt2);
|
||||
} catch (ClassCastException cce) {
|
||||
// Expected exception; not an error
|
||||
@ -152,12 +155,13 @@ public class TCKChronoZonedDateTime {
|
||||
} else {
|
||||
// Same chronology,
|
||||
ChronoZonedDateTime<?> result = czdt.plus(adjuster);
|
||||
assertEquals(result, czdt2, "WithAdjuster failed to replace date time");
|
||||
assertEquals(czdt2, result, "WithAdjuster failed to replace date time");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Test(dataProvider="calendars")
|
||||
@ParameterizedTest
|
||||
@MethodSource("data_of_calendars")
|
||||
public void test_badMinusAdjusterChrono(Chronology chrono) {
|
||||
LocalDate refDate = LocalDate.of(2013, 1, 1);
|
||||
ChronoZonedDateTime<?> czdt = chrono.date(refDate).atTime(LocalTime.NOON).atZone(ZoneOffset.UTC);
|
||||
@ -168,7 +172,7 @@ public class TCKChronoZonedDateTime {
|
||||
if (chrono != chrono2) {
|
||||
try {
|
||||
czdt.minus(adjuster);
|
||||
Assert.fail("WithAdjuster should have thrown a ClassCastException, "
|
||||
Assertions.fail("WithAdjuster should have thrown a ClassCastException, "
|
||||
+ "required: " + czdt + ", supplied: " + czdt2);
|
||||
} catch (ClassCastException cce) {
|
||||
// Expected exception; not an error
|
||||
@ -176,12 +180,13 @@ public class TCKChronoZonedDateTime {
|
||||
} else {
|
||||
// Same chronology,
|
||||
ChronoZonedDateTime<?> result = czdt.minus(adjuster);
|
||||
assertEquals(result, czdt2, "WithAdjuster failed to replace date");
|
||||
assertEquals(czdt2, result, "WithAdjuster failed to replace date");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Test(dataProvider="calendars")
|
||||
@ParameterizedTest
|
||||
@MethodSource("data_of_calendars")
|
||||
public void test_badPlusTemporalUnitChrono(Chronology chrono) {
|
||||
LocalDate refDate = LocalDate.of(2013, 1, 1);
|
||||
ChronoZonedDateTime<?> czdt = chrono.date(refDate).atTime(LocalTime.NOON).atZone(ZoneOffset.UTC);
|
||||
@ -192,7 +197,7 @@ public class TCKChronoZonedDateTime {
|
||||
if (chrono != chrono2) {
|
||||
try {
|
||||
czdt.plus(1, adjuster);
|
||||
Assert.fail("TemporalUnit.doPlus plus should have thrown a ClassCastException, " + czdt
|
||||
Assertions.fail("TemporalUnit.doPlus plus should have thrown a ClassCastException, " + czdt
|
||||
+ " can not be cast to " + czdt2);
|
||||
} catch (ClassCastException cce) {
|
||||
// Expected exception; not an error
|
||||
@ -200,12 +205,13 @@ public class TCKChronoZonedDateTime {
|
||||
} else {
|
||||
// Same chronology,
|
||||
ChronoZonedDateTime<?> result = czdt.plus(1, adjuster);
|
||||
assertEquals(result, czdt2, "WithAdjuster failed to replace date");
|
||||
assertEquals(czdt2, result, "WithAdjuster failed to replace date");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Test(dataProvider="calendars")
|
||||
@ParameterizedTest
|
||||
@MethodSource("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);
|
||||
@ -216,7 +222,7 @@ public class TCKChronoZonedDateTime {
|
||||
if (chrono != chrono2) {
|
||||
try {
|
||||
czdt.minus(1, adjuster);
|
||||
Assert.fail("TemporalUnit.doPlus minus should have thrown a ClassCastException, " + czdt.getClass()
|
||||
Assertions.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
|
||||
@ -224,12 +230,13 @@ public class TCKChronoZonedDateTime {
|
||||
} else {
|
||||
// Same chronology,
|
||||
ChronoZonedDateTime<?> result = czdt.minus(1, adjuster);
|
||||
assertEquals(result, czdt2, "WithAdjuster failed to replace date");
|
||||
assertEquals(czdt2, result, "WithAdjuster failed to replace date");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Test(dataProvider="calendars")
|
||||
@ParameterizedTest
|
||||
@MethodSource("data_of_calendars")
|
||||
public void test_badTemporalFieldChrono(Chronology chrono) {
|
||||
LocalDate refDate = LocalDate.of(2013, 1, 1);
|
||||
ChronoZonedDateTime<?> czdt = chrono.date(refDate).atTime(LocalTime.NOON).atZone(ZoneOffset.UTC);
|
||||
@ -240,7 +247,7 @@ public class TCKChronoZonedDateTime {
|
||||
if (chrono != chrono2) {
|
||||
try {
|
||||
czdt.with(adjuster, 1);
|
||||
Assert.fail("TemporalField doWith() should have thrown a ClassCastException, " + czdt.getClass()
|
||||
Assertions.fail("TemporalField doWith() should have thrown a ClassCastException, " + czdt.getClass()
|
||||
+ " can not be cast to " + czdt2.getClass());
|
||||
} catch (ClassCastException cce) {
|
||||
// Expected exception; not an error
|
||||
@ -248,7 +255,7 @@ public class TCKChronoZonedDateTime {
|
||||
} else {
|
||||
// Same chronology,
|
||||
ChronoZonedDateTime<?> result = czdt.with(adjuster, 1);
|
||||
assertEquals(result, czdt2, "TemporalField doWith() failed to replace date");
|
||||
assertEquals(czdt2, result, "TemporalField doWith() failed to replace date");
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -256,7 +263,8 @@ public class TCKChronoZonedDateTime {
|
||||
//-----------------------------------------------------------------------
|
||||
// isBefore, isAfter, isEqual, timeLineOrder() test a Chronology against the other Chronos
|
||||
//-----------------------------------------------------------------------
|
||||
@Test(dataProvider="calendars")
|
||||
@ParameterizedTest
|
||||
@MethodSource("data_of_calendars")
|
||||
public void test_zonedDateTime_comparisons(Chronology chrono) {
|
||||
List<ChronoZonedDateTime<?>> dates = new ArrayList<>();
|
||||
|
||||
@ -299,19 +307,19 @@ public class TCKChronoZonedDateTime {
|
||||
int cmp = ChronoZonedDateTime.timeLineOrder().compare(a, b);
|
||||
if (i < j) {
|
||||
assertTrue(cmp < 0, a + " compare " + b);
|
||||
assertEquals(a.isBefore(b), true, a + " isBefore " + b);
|
||||
assertEquals(a.isAfter(b), false, a + " ifAfter " + b);
|
||||
assertEquals(a.isEqual(b), false, a + " isEqual " + b);
|
||||
assertEquals(true, a.isBefore(b), a + " isBefore " + b);
|
||||
assertEquals(false, a.isAfter(b), a + " ifAfter " + b);
|
||||
assertEquals(false, a.isEqual(b), a + " isEqual " + b);
|
||||
} else if (i > j) {
|
||||
assertTrue(cmp > 0, a + " compare " + b);
|
||||
assertEquals(a.isBefore(b), false, a + " isBefore " + b);
|
||||
assertEquals(a.isAfter(b), true, a + " ifAfter " + b);
|
||||
assertEquals(a.isEqual(b), false, a + " isEqual " + b);
|
||||
assertEquals(false, a.isBefore(b), a + " isBefore " + b);
|
||||
assertEquals(true, a.isAfter(b), a + " ifAfter " + b);
|
||||
assertEquals(false, a.isEqual(b), a + " isEqual " + b);
|
||||
} else {
|
||||
assertTrue(cmp == 0, a + " compare " + b);
|
||||
assertEquals(a.isBefore(b), false, a + " isBefore " + b);
|
||||
assertEquals(a.isAfter(b), false, a + " ifAfter " + b);
|
||||
assertEquals(a.isEqual(b), true, a + " isEqual " + b);
|
||||
assertEquals(false, a.isBefore(b), a + " isBefore " + b);
|
||||
assertEquals(false, a.isAfter(b), a + " ifAfter " + b);
|
||||
assertEquals(true, a.isEqual(b), a + " isEqual " + b);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -319,34 +327,36 @@ public class TCKChronoZonedDateTime {
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
@Test(dataProvider="calendars")
|
||||
@ParameterizedTest
|
||||
@MethodSource("data_of_calendars")
|
||||
public void test_from_TemporalAccessor(Chronology chrono) {
|
||||
ZonedDateTime refDateTime = ZonedDateTime.of(2013, 1, 1, 12, 30, 0, 0, ZoneId.of("Europe/Paris"));
|
||||
ChronoZonedDateTime<?> dateTime = chrono.zonedDateTime(refDateTime);
|
||||
ChronoZonedDateTime<?> test1 = ChronoZonedDateTime.from(dateTime);
|
||||
assertEquals(test1, dateTime);
|
||||
assertEquals(dateTime, test1);
|
||||
}
|
||||
|
||||
@Test(expectedExceptions = DateTimeException.class)
|
||||
@Test
|
||||
public void test_from_TemporalAccessor_dateOnly() {
|
||||
ChronoZonedDateTime.from(LocalDate.of(2013, 1, 1));
|
||||
Assertions.assertThrows(DateTimeException.class, () -> ChronoZonedDateTime.from(LocalDate.of(2013, 1, 1)));
|
||||
}
|
||||
|
||||
@Test(expectedExceptions = DateTimeException.class)
|
||||
@Test
|
||||
public void test_from_TemporalAccessor_timeOnly() {
|
||||
ChronoZonedDateTime.from(LocalTime.of(12, 30));
|
||||
Assertions.assertThrows(DateTimeException.class, () -> ChronoZonedDateTime.from(LocalTime.of(12, 30)));
|
||||
}
|
||||
|
||||
@Test(expectedExceptions = NullPointerException.class)
|
||||
@Test
|
||||
public void test_from_TemporalAccessor_null() {
|
||||
ChronoZonedDateTime.from(null);
|
||||
Assertions.assertThrows(NullPointerException.class, () -> ChronoZonedDateTime.from(null));
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
@Test(dataProvider="calendars")
|
||||
@ParameterizedTest
|
||||
@MethodSource("data_of_calendars")
|
||||
public void test_getChronology(Chronology chrono) {
|
||||
ChronoZonedDateTime<?> test = chrono.zonedDateTime(ZonedDateTime.of(2010, 6, 30, 11, 30, 0, 0, ZoneOffset.UTC));
|
||||
assertEquals(test.getChronology(), chrono);
|
||||
assertEquals(chrono, test.getChronology());
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2012, 2023, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2012, 2025, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
@ -59,10 +59,9 @@
|
||||
*/
|
||||
package tck.java.time.chrono;
|
||||
|
||||
import static org.testng.Assert.assertEquals;
|
||||
import static org.testng.Assert.assertNotNull;
|
||||
import static org.testng.Assert.assertSame;
|
||||
import static org.testng.Assert.assertTrue;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
import java.time.Clock;
|
||||
import java.time.DateTimeException;
|
||||
@ -89,13 +88,16 @@ import java.time.temporal.ChronoField;
|
||||
import java.util.Locale;
|
||||
import java.util.Set;
|
||||
|
||||
import org.testng.annotations.DataProvider;
|
||||
import org.testng.annotations.Test;
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.TestInstance;
|
||||
import org.junit.jupiter.params.ParameterizedTest;
|
||||
import org.junit.jupiter.params.provider.MethodSource;
|
||||
|
||||
/**
|
||||
* Test Chronology class.
|
||||
*/
|
||||
@Test
|
||||
@TestInstance(TestInstance.Lifecycle.PER_CLASS)
|
||||
public class TCKChronology {
|
||||
|
||||
private static final ZoneOffset OFFSET_P0100 = ZoneOffset.ofHours(1);
|
||||
@ -109,7 +111,6 @@ public class TCKChronology {
|
||||
//-----------------------------------------------------------------------
|
||||
// regular data factory for ID and calendarType of available calendars
|
||||
//-----------------------------------------------------------------------
|
||||
@DataProvider(name = "calendarNameAndType")
|
||||
Object[][] data_of_calendars() {
|
||||
return new Object[][] {
|
||||
{"Hijrah-umalqura", "islamic-umalqura"},
|
||||
@ -120,15 +121,17 @@ public class TCKChronology {
|
||||
};
|
||||
}
|
||||
|
||||
@Test(dataProvider = "calendarNameAndType")
|
||||
@ParameterizedTest
|
||||
@MethodSource("data_of_calendars")
|
||||
public void test_getters(String chronoId, String calendarSystemType) {
|
||||
Chronology chrono = Chronology.of(chronoId);
|
||||
assertNotNull(chrono, "Required calendar not found by ID: " + chronoId);
|
||||
assertEquals(chrono.getId(), chronoId);
|
||||
assertEquals(chrono.getCalendarType(), calendarSystemType);
|
||||
assertEquals(chronoId, chrono.getId());
|
||||
assertEquals(calendarSystemType, chrono.getCalendarType());
|
||||
}
|
||||
|
||||
@Test(dataProvider = "calendarNameAndType")
|
||||
@ParameterizedTest
|
||||
@MethodSource("data_of_calendars")
|
||||
public void test_required_calendars(String chronoId, String calendarSystemType) {
|
||||
Chronology chrono = Chronology.of(chronoId);
|
||||
assertNotNull(chrono, "Required calendar not found by ID: " + chronoId);
|
||||
@ -146,14 +149,13 @@ public class TCKChronology {
|
||||
Chronology lookup = Chronology.of(chrono.getId());
|
||||
assertNotNull(lookup, "Required calendar not found: " + chrono);
|
||||
}
|
||||
assertEquals(chronos.size() >= data_of_calendars().length, true, "Chronology.getAvailableChronologies().size = " + chronos.size()
|
||||
assertEquals(true, chronos.size() >= data_of_calendars().length, "Chronology.getAvailableChronologies().size = " + chronos.size()
|
||||
+ ", expected >= " + data_of_calendars().length);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
// getDisplayName()
|
||||
//-----------------------------------------------------------------------
|
||||
@DataProvider(name = "calendarDisplayName")
|
||||
Object[][] data_of_calendarDisplayNames() {
|
||||
return new Object[][] {
|
||||
{"Hijrah", "Hijri Calendar (Umm al-Qura)"},
|
||||
@ -164,39 +166,41 @@ public class TCKChronology {
|
||||
};
|
||||
}
|
||||
|
||||
@Test(dataProvider = "calendarDisplayName")
|
||||
@ParameterizedTest
|
||||
@MethodSource("data_of_calendarDisplayNames")
|
||||
public void test_getDisplayName(String chronoId, String calendarDisplayName) {
|
||||
Chronology chrono = Chronology.of(chronoId);
|
||||
assertEquals(chrono.getDisplayName(TextStyle.FULL, Locale.ENGLISH), calendarDisplayName);
|
||||
assertEquals(calendarDisplayName, chrono.getDisplayName(TextStyle.FULL, Locale.ENGLISH));
|
||||
}
|
||||
|
||||
/**
|
||||
* Compute the number of days from the Epoch and compute the date from the number of days.
|
||||
*/
|
||||
@Test(dataProvider = "calendarNameAndType")
|
||||
@ParameterizedTest
|
||||
@MethodSource("data_of_calendars")
|
||||
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);
|
||||
assertEquals(date2, date1, "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);
|
||||
assertEquals(epoch2, epoch1, "Epoch day not the same: " + epoch1 + " != " + epoch2);
|
||||
}
|
||||
|
||||
@Test(dataProvider = "calendarNameAndType")
|
||||
@ParameterizedTest
|
||||
@MethodSource("data_of_calendars")
|
||||
public void test_dateEpochDay(String name, String alias) {
|
||||
Chronology chrono = Chronology.of(name);
|
||||
ChronoLocalDate date = chrono.dateNow();
|
||||
long epochDay = date.getLong(ChronoField.EPOCH_DAY);
|
||||
ChronoLocalDate test = chrono.dateEpochDay(epochDay);
|
||||
assertEquals(test, date);
|
||||
assertEquals(date, test);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
// locale based lookup
|
||||
//-----------------------------------------------------------------------
|
||||
@DataProvider(name = "calendarsystemtype")
|
||||
Object[][] data_CalendarType() {
|
||||
return new Object[][] {
|
||||
{HijrahChronology.INSTANCE, "islamic-umalqura"},
|
||||
@ -207,18 +211,20 @@ public class TCKChronology {
|
||||
};
|
||||
}
|
||||
|
||||
@Test(dataProvider = "calendarsystemtype")
|
||||
@ParameterizedTest
|
||||
@MethodSource("data_CalendarType")
|
||||
public void test_getCalendarType(Chronology chrono, String calendarType) {
|
||||
String type = calendarType;
|
||||
assertEquals(chrono.getCalendarType(), type);
|
||||
assertEquals(type, chrono.getCalendarType());
|
||||
}
|
||||
|
||||
@Test(dataProvider = "calendarsystemtype")
|
||||
@ParameterizedTest
|
||||
@MethodSource("data_CalendarType")
|
||||
public void test_lookupLocale(Chronology chrono, String calendarType) {
|
||||
Locale.Builder builder = new Locale.Builder().setLanguage("en").setRegion("CA");
|
||||
builder.setUnicodeLocaleKeyword("ca", calendarType);
|
||||
Locale locale = builder.build();
|
||||
assertEquals(Chronology.ofLocale(locale), chrono);
|
||||
assertEquals(chrono, Chronology.ofLocale(locale));
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
@ -230,9 +236,9 @@ public class TCKChronology {
|
||||
Clock clock = Clock.system(zoneId_paris);
|
||||
|
||||
Chronology chrono = Chronology.of("Minguo");
|
||||
assertEquals(chrono.dateNow(), MinguoChronology.INSTANCE.dateNow());
|
||||
assertEquals(chrono.dateNow(zoneId_paris), MinguoChronology.INSTANCE.dateNow(zoneId_paris));
|
||||
assertEquals(chrono.dateNow(clock), MinguoChronology.INSTANCE.dateNow(clock));
|
||||
assertEquals(MinguoChronology.INSTANCE.dateNow(), chrono.dateNow());
|
||||
assertEquals(MinguoChronology.INSTANCE.dateNow(zoneId_paris), chrono.dateNow(zoneId_paris));
|
||||
assertEquals(MinguoChronology.INSTANCE.dateNow(clock), chrono.dateNow(clock));
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -241,9 +247,9 @@ public class TCKChronology {
|
||||
Clock clock = Clock.system(zoneId_paris);
|
||||
|
||||
Chronology chrono = Chronology.of("ISO");
|
||||
assertEquals(chrono.dateNow(), IsoChronology.INSTANCE.dateNow());
|
||||
assertEquals(chrono.dateNow(zoneId_paris), IsoChronology.INSTANCE.dateNow(zoneId_paris));
|
||||
assertEquals(chrono.dateNow(clock), IsoChronology.INSTANCE.dateNow(clock));
|
||||
assertEquals(IsoChronology.INSTANCE.dateNow(), chrono.dateNow());
|
||||
assertEquals(IsoChronology.INSTANCE.dateNow(zoneId_paris), chrono.dateNow(zoneId_paris));
|
||||
assertEquals(IsoChronology.INSTANCE.dateNow(clock), chrono.dateNow(clock));
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -252,9 +258,9 @@ public class TCKChronology {
|
||||
Clock clock = Clock.system(zoneId_paris);
|
||||
|
||||
Chronology chrono = Chronology.of("Japanese");
|
||||
assertEquals(chrono.dateNow(), JapaneseChronology.INSTANCE.dateNow());
|
||||
assertEquals(chrono.dateNow(zoneId_paris), JapaneseChronology.INSTANCE.dateNow(zoneId_paris));
|
||||
assertEquals(chrono.dateNow(clock), JapaneseChronology.INSTANCE.dateNow(clock));
|
||||
assertEquals(JapaneseChronology.INSTANCE.dateNow(), chrono.dateNow());
|
||||
assertEquals(JapaneseChronology.INSTANCE.dateNow(zoneId_paris), chrono.dateNow(zoneId_paris));
|
||||
assertEquals(JapaneseChronology.INSTANCE.dateNow(clock), chrono.dateNow(clock));
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -263,9 +269,9 @@ public class TCKChronology {
|
||||
Clock clock = Clock.system(zoneId_paris);
|
||||
|
||||
Chronology chrono = Chronology.of("ThaiBuddhist");
|
||||
assertEquals(chrono.dateNow(), ThaiBuddhistChronology.INSTANCE.dateNow());
|
||||
assertEquals(chrono.dateNow(zoneId_paris), ThaiBuddhistChronology.INSTANCE.dateNow(zoneId_paris));
|
||||
assertEquals(chrono.dateNow(clock), ThaiBuddhistChronology.INSTANCE.dateNow(clock));
|
||||
assertEquals(ThaiBuddhistChronology.INSTANCE.dateNow(), chrono.dateNow());
|
||||
assertEquals(ThaiBuddhistChronology.INSTANCE.dateNow(zoneId_paris), chrono.dateNow(zoneId_paris));
|
||||
assertEquals(ThaiBuddhistChronology.INSTANCE.dateNow(clock), chrono.dateNow(clock));
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
@ -276,8 +282,8 @@ public class TCKChronology {
|
||||
Chronology chrono = Chronology.of("Hijrah");
|
||||
ChronoLocalDate date1 = chrono.dateYearDay(HijrahEra.AH, 1434, 178);
|
||||
ChronoLocalDate date2 = chrono.date(HijrahEra.AH, 1434, 7, 1);
|
||||
assertEquals(date1, HijrahChronology.INSTANCE.dateYearDay(HijrahEra.AH, 1434, 178));
|
||||
assertEquals(date2, HijrahChronology.INSTANCE.dateYearDay(HijrahEra.AH, 1434, 178));
|
||||
assertEquals(HijrahChronology.INSTANCE.dateYearDay(HijrahEra.AH, 1434, 178), date1);
|
||||
assertEquals(HijrahChronology.INSTANCE.dateYearDay(HijrahEra.AH, 1434, 178), date2);
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -285,8 +291,8 @@ public class TCKChronology {
|
||||
Chronology chrono = Chronology.of("Minguo");
|
||||
ChronoLocalDate date1 = chrono.dateYearDay(MinguoEra.ROC, 5, 60);
|
||||
ChronoLocalDate date2 = chrono.date(MinguoEra.ROC, 5, 2, 29);
|
||||
assertEquals(date1, MinguoChronology.INSTANCE.dateYearDay(MinguoEra.ROC, 5, 60));
|
||||
assertEquals(date2, MinguoChronology.INSTANCE.dateYearDay(MinguoEra.ROC, 5, 60));
|
||||
assertEquals(MinguoChronology.INSTANCE.dateYearDay(MinguoEra.ROC, 5, 60), date1);
|
||||
assertEquals(MinguoChronology.INSTANCE.dateYearDay(MinguoEra.ROC, 5, 60), date2);
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -294,8 +300,8 @@ public class TCKChronology {
|
||||
Chronology chrono = Chronology.of("ISO");
|
||||
ChronoLocalDate date1 = chrono.dateYearDay(IsoEra.CE, 5, 60);
|
||||
ChronoLocalDate date2 = chrono.date(IsoEra.CE, 5, 3, 1);
|
||||
assertEquals(date1, IsoChronology.INSTANCE.dateYearDay(IsoEra.CE, 5, 60));
|
||||
assertEquals(date2, IsoChronology.INSTANCE.dateYearDay(IsoEra.CE, 5, 60));
|
||||
assertEquals(IsoChronology.INSTANCE.dateYearDay(IsoEra.CE, 5, 60), date1);
|
||||
assertEquals(IsoChronology.INSTANCE.dateYearDay(IsoEra.CE, 5, 60), date2);
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -303,8 +309,8 @@ public class TCKChronology {
|
||||
Chronology chrono = Chronology.of("Japanese");
|
||||
ChronoLocalDate date1 = chrono.dateYearDay(JapaneseEra.HEISEI, 8, 60);
|
||||
ChronoLocalDate date2 = chrono.date(JapaneseEra.HEISEI, 8, 2, 29);
|
||||
assertEquals(date1, JapaneseChronology.INSTANCE.dateYearDay(JapaneseEra.HEISEI, 8, 60));
|
||||
assertEquals(date2, JapaneseChronology.INSTANCE.dateYearDay(JapaneseEra.HEISEI, 8, 60));
|
||||
assertEquals(JapaneseChronology.INSTANCE.dateYearDay(JapaneseEra.HEISEI, 8, 60), date1);
|
||||
assertEquals(JapaneseChronology.INSTANCE.dateYearDay(JapaneseEra.HEISEI, 8, 60), date2);
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -312,8 +318,8 @@ public class TCKChronology {
|
||||
Chronology chrono = Chronology.of("ThaiBuddhist");
|
||||
ChronoLocalDate date1 = chrono.dateYearDay(ThaiBuddhistEra.BE, 2459, 60);
|
||||
ChronoLocalDate date2 = chrono.date(ThaiBuddhistEra.BE, 2459, 2, 29);
|
||||
assertEquals(date1, ThaiBuddhistChronology.INSTANCE.dateYearDay(ThaiBuddhistEra.BE, 2459, 60));
|
||||
assertEquals(date2, ThaiBuddhistChronology.INSTANCE.dateYearDay(ThaiBuddhistEra.BE, 2459, 60));
|
||||
assertEquals(ThaiBuddhistChronology.INSTANCE.dateYearDay(ThaiBuddhistEra.BE, 2459, 60), date1);
|
||||
assertEquals(ThaiBuddhistChronology.INSTANCE.dateYearDay(ThaiBuddhistEra.BE, 2459, 60), date2);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -328,25 +334,28 @@ public class TCKChronology {
|
||||
Locale.Builder builder = new Locale.Builder().setLanguage("en").setRegion("CA");
|
||||
builder.setUnicodeLocaleKeyword("ca", chrono.getCalendarType());
|
||||
Locale locale = builder.build();
|
||||
assertEquals(Chronology.ofLocale(locale), chrono, "Lookup by type");
|
||||
assertEquals(chrono, Chronology.ofLocale(locale), "Lookup by type");
|
||||
}
|
||||
}
|
||||
|
||||
@Test(expectedExceptions = DateTimeException.class)
|
||||
@Test
|
||||
public void test_lookupLocale() {
|
||||
Locale.Builder builder = new Locale.Builder().setLanguage("en").setRegion("CA");
|
||||
builder.setUnicodeLocaleKeyword("ca", "xxx");
|
||||
Assertions.assertThrows(DateTimeException.class, () -> {
|
||||
Locale.Builder builder = new Locale.Builder().setLanguage("en").setRegion("CA");
|
||||
builder.setUnicodeLocaleKeyword("ca", "xxx");
|
||||
|
||||
Locale locale = builder.build();
|
||||
Chronology.ofLocale(locale);
|
||||
Locale locale = builder.build();
|
||||
Chronology.ofLocale(locale);
|
||||
});
|
||||
}
|
||||
|
||||
@Test(expectedExceptions = DateTimeException.class)
|
||||
@Test
|
||||
public void test_noChrono() {
|
||||
Chronology chrono = Chronology.of("FooFoo");
|
||||
Assertions.assertThrows(DateTimeException.class, () -> {
|
||||
Chronology chrono = Chronology.of("FooFoo");
|
||||
});
|
||||
}
|
||||
|
||||
@DataProvider(name = "epochSecond_dataProvider")
|
||||
Object[][] data_epochSecond() {
|
||||
return new Object[][] {
|
||||
{JapaneseChronology.INSTANCE, 1873, 9, 7, 1, 2, 2, OFFSET_P0100},
|
||||
@ -366,15 +375,14 @@ public class TCKChronology {
|
||||
};
|
||||
}
|
||||
|
||||
@Test(dataProvider = "epochSecond_dataProvider")
|
||||
@ParameterizedTest
|
||||
@MethodSource("data_epochSecond")
|
||||
public void test_epochSecond(Chronology chrono, int y, int m, int d, int h, int min, int s, ZoneOffset offset) {
|
||||
ChronoLocalDate chronoLd = chrono.date(y, m, d);
|
||||
assertEquals(chrono.epochSecond(y, m, d, h, min, s, offset),
|
||||
OffsetDateTime.of(LocalDate.from(chronoLd), LocalTime.of(h, min, s), offset)
|
||||
.toEpochSecond());
|
||||
assertEquals(OffsetDateTime.of(LocalDate.from(chronoLd), LocalTime.of(h, min, s), offset)
|
||||
.toEpochSecond(), chrono.epochSecond(y, m, d, h, min, s, offset));
|
||||
}
|
||||
|
||||
@DataProvider(name = "era_epochSecond_dataProvider")
|
||||
Object[][] data_era_epochSecond() {
|
||||
return new Object[][] {
|
||||
{JapaneseChronology.INSTANCE, JapaneseEra.MEIJI, 1873 - YDIFF_MEIJI, 9, 7, 1, 2, 2, OFFSET_P0100},
|
||||
@ -394,15 +402,14 @@ public class TCKChronology {
|
||||
};
|
||||
}
|
||||
|
||||
@Test(dataProvider = "era_epochSecond_dataProvider")
|
||||
@ParameterizedTest
|
||||
@MethodSource("data_era_epochSecond")
|
||||
public void test_epochSecond(Chronology chrono, Era era, int y, int m, int d, int h, int min, int s, ZoneOffset offset) {
|
||||
ChronoLocalDate chronoLd = chrono.date(era, y, m, d);
|
||||
assertEquals(chrono.epochSecond(era, y, m, d, h, min, s, offset),
|
||||
OffsetDateTime.of(LocalDate.from(chronoLd), LocalTime.of(h, min, s), offset)
|
||||
.toEpochSecond());
|
||||
assertEquals(OffsetDateTime.of(LocalDate.from(chronoLd), LocalTime.of(h, min, s), offset)
|
||||
.toEpochSecond(), chrono.epochSecond(era, y, m, d, h, min, s, offset));
|
||||
}
|
||||
|
||||
@DataProvider(name = "bad_epochSecond_dataProvider")
|
||||
Object[][] bad_data_epochSecond() {
|
||||
return new Object[][] {
|
||||
{JapaneseChronology.INSTANCE, 1873, 13, 7, 1, 2, 2, OFFSET_P0100},
|
||||
@ -415,12 +422,12 @@ public class TCKChronology {
|
||||
};
|
||||
}
|
||||
|
||||
@Test(dataProvider = "bad_epochSecond_dataProvider", expectedExceptions = DateTimeException.class)
|
||||
@ParameterizedTest
|
||||
@MethodSource("bad_data_epochSecond")
|
||||
public void test_bad_epochSecond(Chronology chrono, int y, int m, int d, int h, int min, int s, ZoneOffset offset) {
|
||||
chrono.epochSecond(y, m, d, h, min, s, offset);
|
||||
Assertions.assertThrows(DateTimeException.class, () -> chrono.epochSecond(y, m, d, h, min, s, offset));
|
||||
}
|
||||
|
||||
@DataProvider
|
||||
Object[][] data_isIsoBased() {
|
||||
return new Object[][] {
|
||||
{IsoChronology.INSTANCE, true},
|
||||
@ -434,8 +441,9 @@ public class TCKChronology {
|
||||
//-----------------------------------------------------------------------
|
||||
// isIsoBased()
|
||||
//-----------------------------------------------------------------------
|
||||
@Test(dataProvider = "data_isIsoBased")
|
||||
@ParameterizedTest
|
||||
@MethodSource("data_isIsoBased")
|
||||
public void test_isIsoBased(Chronology chrono, boolean expected) {
|
||||
assertEquals(chrono.isIsoBased(), expected);
|
||||
assertEquals(expected, chrono.isIsoBased());
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2012, 2013, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2012, 2025, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
@ -55,10 +55,11 @@
|
||||
package tck.java.time.chrono;
|
||||
|
||||
import java.time.Clock;
|
||||
import static org.testng.Assert.assertEquals;
|
||||
import static org.testng.Assert.assertFalse;
|
||||
import static org.testng.Assert.assertTrue;
|
||||
import static org.testng.Assert.fail;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
import static org.junit.jupiter.api.Assertions.fail;
|
||||
|
||||
import java.time.DateTimeException;
|
||||
import java.time.ZoneId;
|
||||
@ -77,14 +78,16 @@ import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.testng.Assert;
|
||||
import org.testng.annotations.DataProvider;
|
||||
import org.testng.annotations.Test;
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.TestInstance;
|
||||
import org.junit.jupiter.params.ParameterizedTest;
|
||||
import org.junit.jupiter.params.provider.MethodSource;
|
||||
|
||||
/**
|
||||
* Test.
|
||||
*/
|
||||
@Test
|
||||
@TestInstance(TestInstance.Lifecycle.PER_CLASS)
|
||||
public class TCKHijrahChronology {
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
@ -94,35 +97,34 @@ public class TCKHijrahChronology {
|
||||
public void test_chrono_byName() {
|
||||
Chronology c = HijrahChronology.INSTANCE;
|
||||
Chronology test = Chronology.of("Hijrah-umalqura");
|
||||
Assert.assertNotNull(test, "The Hijrah-umalqura calendar could not be found by name");
|
||||
Assert.assertEquals(test.getId(), "Hijrah-umalqura", "ID mismatch");
|
||||
Assert.assertEquals(test.getCalendarType(), "islamic-umalqura", "Type mismatch");
|
||||
Assert.assertEquals(test, c);
|
||||
Assertions.assertNotNull(test, "The Hijrah-umalqura calendar could not be found by name");
|
||||
assertEquals("Hijrah-umalqura", test.getId(), "ID mismatch");
|
||||
assertEquals("islamic-umalqura", test.getCalendarType(), "Type mismatch");
|
||||
assertEquals(c, test);
|
||||
}
|
||||
|
||||
// Tests for dateNow() method
|
||||
@Test
|
||||
public void test_dateNow(){
|
||||
assertEquals(HijrahChronology.INSTANCE.dateNow(), HijrahDate.now()) ;
|
||||
assertEquals(HijrahChronology.INSTANCE.dateNow(), HijrahDate.now(ZoneId.systemDefault())) ;
|
||||
assertEquals(HijrahChronology.INSTANCE.dateNow(), HijrahDate.now(Clock.systemDefaultZone())) ;
|
||||
assertEquals(HijrahChronology.INSTANCE.dateNow(), HijrahDate.now(Clock.systemDefaultZone().getZone())) ;
|
||||
assertEquals(HijrahDate.now(), HijrahChronology.INSTANCE.dateNow()) ;
|
||||
assertEquals(HijrahDate.now(ZoneId.systemDefault()), HijrahChronology.INSTANCE.dateNow()) ;
|
||||
assertEquals(HijrahDate.now(Clock.systemDefaultZone()), HijrahChronology.INSTANCE.dateNow()) ;
|
||||
assertEquals(HijrahDate.now(Clock.systemDefaultZone().getZone()), HijrahChronology.INSTANCE.dateNow()) ;
|
||||
|
||||
assertEquals(HijrahChronology.INSTANCE.dateNow(), HijrahChronology.INSTANCE.dateNow(ZoneId.systemDefault())) ;
|
||||
assertEquals(HijrahChronology.INSTANCE.dateNow(), HijrahChronology.INSTANCE.dateNow(Clock.systemDefaultZone())) ;
|
||||
assertEquals(HijrahChronology.INSTANCE.dateNow(), HijrahChronology.INSTANCE.dateNow(Clock.systemDefaultZone().getZone())) ;
|
||||
assertEquals(HijrahChronology.INSTANCE.dateNow(ZoneId.systemDefault()), HijrahChronology.INSTANCE.dateNow()) ;
|
||||
assertEquals(HijrahChronology.INSTANCE.dateNow(Clock.systemDefaultZone()), HijrahChronology.INSTANCE.dateNow()) ;
|
||||
assertEquals(HijrahChronology.INSTANCE.dateNow(Clock.systemDefaultZone().getZone()), HijrahChronology.INSTANCE.dateNow()) ;
|
||||
|
||||
ZoneId zoneId = ZoneId.of("Europe/Paris");
|
||||
assertEquals(HijrahChronology.INSTANCE.dateNow(zoneId), HijrahChronology.INSTANCE.dateNow(Clock.system(zoneId))) ;
|
||||
assertEquals(HijrahChronology.INSTANCE.dateNow(zoneId), HijrahChronology.INSTANCE.dateNow(Clock.system(zoneId).getZone())) ;
|
||||
assertEquals(HijrahChronology.INSTANCE.dateNow(zoneId), HijrahDate.now(Clock.system(zoneId))) ;
|
||||
assertEquals(HijrahChronology.INSTANCE.dateNow(zoneId), HijrahDate.now(Clock.system(zoneId).getZone())) ;
|
||||
assertEquals(HijrahChronology.INSTANCE.dateNow(Clock.system(zoneId)), HijrahChronology.INSTANCE.dateNow(zoneId)) ;
|
||||
assertEquals(HijrahChronology.INSTANCE.dateNow(Clock.system(zoneId).getZone()), HijrahChronology.INSTANCE.dateNow(zoneId)) ;
|
||||
assertEquals(HijrahDate.now(Clock.system(zoneId)), HijrahChronology.INSTANCE.dateNow(zoneId)) ;
|
||||
assertEquals(HijrahDate.now(Clock.system(zoneId).getZone()), HijrahChronology.INSTANCE.dateNow(zoneId)) ;
|
||||
|
||||
assertEquals(HijrahChronology.INSTANCE.dateNow(ZoneId.of(ZoneOffset.UTC.getId())), HijrahChronology.INSTANCE.dateNow(Clock.systemUTC())) ;
|
||||
assertEquals(HijrahChronology.INSTANCE.dateNow(Clock.systemUTC()), HijrahChronology.INSTANCE.dateNow(ZoneId.of(ZoneOffset.UTC.getId()))) ;
|
||||
}
|
||||
|
||||
// Sample invalid dates
|
||||
@DataProvider(name="badDates")
|
||||
Object[][] data_badDates() {
|
||||
return new Object[][] {
|
||||
{1299, 12, 29},
|
||||
@ -143,17 +145,20 @@ public class TCKHijrahChronology {
|
||||
}
|
||||
|
||||
// This is a negative test to verify if the API throws exception if an invalid date is provided
|
||||
@Test(dataProvider="badDates", expectedExceptions=DateTimeException.class)
|
||||
@ParameterizedTest
|
||||
@MethodSource("data_badDates")
|
||||
public void test_badDates(int year, int month, int dom) {
|
||||
HijrahChronology.INSTANCE.date(year, month, dom);
|
||||
Assertions.assertThrows(DateTimeException.class, () -> HijrahChronology.INSTANCE.date(year, month, dom));
|
||||
}
|
||||
|
||||
// Negative test or dateYearDay with day too large
|
||||
@Test(expectedExceptions=java.time.DateTimeException.class)
|
||||
@Test
|
||||
public void test_ofYearDayTooLarge() {
|
||||
int year = 1435;
|
||||
int lengthOfYear = HijrahChronology.INSTANCE.dateYearDay(year, 1).lengthOfYear();
|
||||
HijrahDate hd = HijrahChronology.INSTANCE.dateYearDay(year, lengthOfYear + 1);
|
||||
Assertions.assertThrows(DateTimeException.class, () -> {
|
||||
int year = 1435;
|
||||
int lengthOfYear = HijrahChronology.INSTANCE.dateYearDay(year, 1).lengthOfYear();
|
||||
HijrahDate hd = HijrahChronology.INSTANCE.dateYearDay(year, lengthOfYear + 1);
|
||||
});
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
@ -198,7 +203,6 @@ public class TCKHijrahChronology {
|
||||
//-----------------------------------------------------------------------
|
||||
// Tests for HijrahChronology resolve
|
||||
//-----------------------------------------------------------------------
|
||||
@DataProvider(name = "resolve_styleByEra")
|
||||
Object[][] data_resolve_styleByEra() {
|
||||
Object[][] result = new Object[ResolverStyle.values().length * HijrahEra.values().length][];
|
||||
int i = 0;
|
||||
@ -210,42 +214,44 @@ public class TCKHijrahChronology {
|
||||
return result;
|
||||
}
|
||||
|
||||
@Test(dataProvider = "resolve_styleByEra")
|
||||
@ParameterizedTest
|
||||
@MethodSource("data_resolve_styleByEra")
|
||||
public void test_resolve_yearOfEra_eraOnly_valid(ResolverStyle style, HijrahEra era) {
|
||||
Map<TemporalField, Long> fieldValues = new HashMap<>();
|
||||
fieldValues.put(ChronoField.ERA, (long) era.getValue());
|
||||
HijrahDate date = HijrahChronology.INSTANCE.resolveDate(fieldValues, style);
|
||||
assertEquals(date, null);
|
||||
assertEquals(fieldValues.get(ChronoField.ERA), (Long) (long) era.getValue());
|
||||
assertEquals(fieldValues.size(), 1);
|
||||
assertEquals(null, date);
|
||||
assertEquals((Long) (long) era.getValue(), fieldValues.get(ChronoField.ERA));
|
||||
assertEquals(1, fieldValues.size());
|
||||
}
|
||||
|
||||
@Test(dataProvider = "resolve_styleByEra")
|
||||
@ParameterizedTest
|
||||
@MethodSource("data_resolve_styleByEra")
|
||||
public void test_resolve_yearOfEra_eraAndYearOfEraOnly_valid(ResolverStyle style, HijrahEra era) {
|
||||
Map<TemporalField, Long> fieldValues = new HashMap<>();
|
||||
fieldValues.put(ChronoField.ERA, (long) era.getValue());
|
||||
fieldValues.put(ChronoField.YEAR_OF_ERA, 1343L);
|
||||
HijrahDate date = HijrahChronology.INSTANCE.resolveDate(fieldValues, style);
|
||||
assertEquals(date, null);
|
||||
assertEquals(fieldValues.get(ChronoField.ERA), null);
|
||||
assertEquals(fieldValues.get(ChronoField.YEAR_OF_ERA), null);
|
||||
assertEquals(fieldValues.get(ChronoField.YEAR), (Long) 1343L);
|
||||
assertEquals(fieldValues.size(), 1);
|
||||
assertEquals(null, date);
|
||||
assertEquals(null, fieldValues.get(ChronoField.ERA));
|
||||
assertEquals(null, fieldValues.get(ChronoField.YEAR_OF_ERA));
|
||||
assertEquals((Long) 1343L, fieldValues.get(ChronoField.YEAR));
|
||||
assertEquals(1, fieldValues.size());
|
||||
}
|
||||
|
||||
@Test(dataProvider = "resolve_styleByEra")
|
||||
@ParameterizedTest
|
||||
@MethodSource("data_resolve_styleByEra")
|
||||
public void test_resolve_yearOfEra_eraAndYearOnly_valid(ResolverStyle style, HijrahEra era) {
|
||||
Map<TemporalField, Long> fieldValues = new HashMap<>();
|
||||
fieldValues.put(ChronoField.ERA, (long) era.getValue());
|
||||
fieldValues.put(ChronoField.YEAR, 1343L);
|
||||
HijrahDate date = HijrahChronology.INSTANCE.resolveDate(fieldValues, style);
|
||||
assertEquals(date, null);
|
||||
assertEquals(fieldValues.get(ChronoField.ERA), (Long) (long) era.getValue());
|
||||
assertEquals(fieldValues.get(ChronoField.YEAR), (Long) 1343L);
|
||||
assertEquals(fieldValues.size(), 2);
|
||||
assertEquals(null, date);
|
||||
assertEquals((Long) (long) era.getValue(), fieldValues.get(ChronoField.ERA));
|
||||
assertEquals((Long) 1343L, fieldValues.get(ChronoField.YEAR));
|
||||
assertEquals(2, fieldValues.size());
|
||||
}
|
||||
|
||||
@DataProvider(name = "resolve_styles")
|
||||
Object[][] data_resolve_styles() {
|
||||
Object[][] result = new Object[ResolverStyle.values().length][];
|
||||
int i = 0;
|
||||
@ -255,27 +261,29 @@ public class TCKHijrahChronology {
|
||||
return result;
|
||||
}
|
||||
|
||||
@Test(dataProvider = "resolve_styles")
|
||||
@ParameterizedTest
|
||||
@MethodSource("data_resolve_styles")
|
||||
public void test_resolve_yearOfEra_yearOfEraOnly_valid(ResolverStyle style) {
|
||||
Map<TemporalField, Long> fieldValues = new HashMap<>();
|
||||
fieldValues.put(ChronoField.YEAR_OF_ERA, 1343L);
|
||||
HijrahDate date = HijrahChronology.INSTANCE.resolveDate(fieldValues, style);
|
||||
assertEquals(date, null);
|
||||
assertEquals(fieldValues.get(ChronoField.YEAR_OF_ERA), (style != ResolverStyle.STRICT) ? null : (Long) 1343L);
|
||||
assertEquals(fieldValues.get(ChronoField.YEAR), (style == ResolverStyle.STRICT) ? null : (Long) 1343L);
|
||||
assertEquals(fieldValues.size(), 1);
|
||||
assertEquals(null, date);
|
||||
assertEquals((style != ResolverStyle.STRICT) ? null : (Long) 1343L, fieldValues.get(ChronoField.YEAR_OF_ERA));
|
||||
assertEquals((style == ResolverStyle.STRICT) ? null : (Long) 1343L, fieldValues.get(ChronoField.YEAR));
|
||||
assertEquals(1, fieldValues.size());
|
||||
}
|
||||
|
||||
@Test(dataProvider = "resolve_styles")
|
||||
@ParameterizedTest
|
||||
@MethodSource("data_resolve_styles")
|
||||
public void test_resolve_yearOfEra_yearOfEraAndYearOnly_valid(ResolverStyle style) {
|
||||
Map<TemporalField, Long> fieldValues = new HashMap<>();
|
||||
fieldValues.put(ChronoField.YEAR_OF_ERA, 1343L);
|
||||
fieldValues.put(ChronoField.YEAR, 1343L);
|
||||
HijrahDate date = HijrahChronology.INSTANCE.resolveDate(fieldValues, style);
|
||||
assertEquals(date, null);
|
||||
assertEquals(fieldValues.get(ChronoField.YEAR_OF_ERA), null);
|
||||
assertEquals(fieldValues.get(ChronoField.YEAR), (Long) 1343L);
|
||||
assertEquals(fieldValues.size(), 1);
|
||||
assertEquals(null, date);
|
||||
assertEquals(null, fieldValues.get(ChronoField.YEAR_OF_ERA));
|
||||
assertEquals((Long) 1343L, fieldValues.get(ChronoField.YEAR));
|
||||
assertEquals(1, fieldValues.size());
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
@ -285,7 +293,6 @@ public class TCKHijrahChronology {
|
||||
// 1434=29 30 29 30 29 30 30 29 30 30 29 29 total = 354
|
||||
// 1435=30 29 30 29 30 29 30 29 30 30 29 30 total = 355
|
||||
//-----------------------------------------------------------------------
|
||||
@DataProvider(name = "resolve_ymd")
|
||||
Object[][] data_resolve_ymd() {
|
||||
// Compute the number of days in various month and years so that test cases
|
||||
// are not dependent on specific calendar data
|
||||
@ -364,7 +371,8 @@ public class TCKHijrahChronology {
|
||||
};
|
||||
}
|
||||
|
||||
@Test(dataProvider = "resolve_ymd")
|
||||
@ParameterizedTest
|
||||
@MethodSource("data_resolve_ymd")
|
||||
public void test_resolve_ymd_lenient(int y, int m, int d, HijrahDate expected, Object smart, boolean strict) {
|
||||
Map<TemporalField, Long> fieldValues = new HashMap<>();
|
||||
fieldValues.put(ChronoField.YEAR, (long) y);
|
||||
@ -373,8 +381,8 @@ public class TCKHijrahChronology {
|
||||
|
||||
if (expected != null) {
|
||||
HijrahDate date = HijrahChronology.INSTANCE.resolveDate(fieldValues, ResolverStyle.LENIENT);
|
||||
assertEquals(date, expected);
|
||||
assertEquals(fieldValues.size(), 0);
|
||||
assertEquals(expected, date);
|
||||
assertEquals(0, fieldValues.size());
|
||||
} else {
|
||||
try {
|
||||
HijrahDate date = HijrahChronology.INSTANCE.resolveDate(fieldValues, ResolverStyle.LENIENT);
|
||||
@ -385,7 +393,8 @@ public class TCKHijrahChronology {
|
||||
}
|
||||
}
|
||||
|
||||
@Test(dataProvider = "resolve_ymd")
|
||||
@ParameterizedTest
|
||||
@MethodSource("data_resolve_ymd")
|
||||
public void test_resolve_ymd_smart(int y, int m, int d, HijrahDate expected, Object smart, boolean strict) {
|
||||
Map<TemporalField, Long> fieldValues = new HashMap<>();
|
||||
fieldValues.put(ChronoField.YEAR, (long) y);
|
||||
@ -393,11 +402,11 @@ public class TCKHijrahChronology {
|
||||
fieldValues.put(ChronoField.DAY_OF_MONTH, (long) d);
|
||||
if (Boolean.TRUE.equals(smart)) {
|
||||
HijrahDate date = HijrahChronology.INSTANCE.resolveDate(fieldValues, ResolverStyle.SMART);
|
||||
assertEquals(date, expected);
|
||||
assertEquals(fieldValues.size(), 0);
|
||||
assertEquals(expected, date);
|
||||
assertEquals(0, fieldValues.size());
|
||||
} else if (smart instanceof HijrahDate) {
|
||||
HijrahDate date = HijrahChronology.INSTANCE.resolveDate(fieldValues, ResolverStyle.SMART);
|
||||
assertEquals(date, smart);
|
||||
assertEquals(smart, date);
|
||||
} else {
|
||||
try {
|
||||
HijrahDate date = HijrahChronology.INSTANCE.resolveDate(fieldValues, ResolverStyle.SMART);
|
||||
@ -408,7 +417,8 @@ public class TCKHijrahChronology {
|
||||
}
|
||||
}
|
||||
|
||||
@Test(dataProvider = "resolve_ymd")
|
||||
@ParameterizedTest
|
||||
@MethodSource("data_resolve_ymd")
|
||||
public void test_resolve_ymd_strict(int y, int m, int d, HijrahDate expected, Object smart, boolean strict) {
|
||||
Map<TemporalField, Long> fieldValues = new HashMap<>();
|
||||
fieldValues.put(ChronoField.YEAR, (long) y);
|
||||
@ -416,8 +426,8 @@ public class TCKHijrahChronology {
|
||||
fieldValues.put(ChronoField.DAY_OF_MONTH, (long) d);
|
||||
if (strict) {
|
||||
HijrahDate date = HijrahChronology.INSTANCE.resolveDate(fieldValues, ResolverStyle.STRICT);
|
||||
assertEquals(date, expected, "Resolved to incorrect date");
|
||||
assertEquals(fieldValues.size(), 0);
|
||||
assertEquals(expected, date, "Resolved to incorrect date");
|
||||
assertEquals(0, fieldValues.size());
|
||||
} else {
|
||||
try {
|
||||
HijrahDate date = HijrahChronology.INSTANCE.resolveDate(fieldValues, ResolverStyle.STRICT);
|
||||
@ -429,7 +439,6 @@ public class TCKHijrahChronology {
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
@DataProvider(name = "resolve_yd")
|
||||
Object[][] data_resolve_yd() {
|
||||
// Compute the number of days in various month and years so that test cases
|
||||
// are not dependent on specific calendar data
|
||||
@ -478,25 +487,27 @@ public class TCKHijrahChronology {
|
||||
};
|
||||
}
|
||||
|
||||
@Test(dataProvider = "resolve_yd")
|
||||
@ParameterizedTest
|
||||
@MethodSource("data_resolve_yd")
|
||||
public void test_resolve_yd_lenient(int y, int d, HijrahDate expected, boolean smart, boolean strict) {
|
||||
Map<TemporalField, Long> fieldValues = new HashMap<>();
|
||||
fieldValues.put(ChronoField.YEAR, (long) y);
|
||||
fieldValues.put(ChronoField.DAY_OF_YEAR, (long) d);
|
||||
HijrahDate date = HijrahChronology.INSTANCE.resolveDate(fieldValues, ResolverStyle.LENIENT);
|
||||
assertEquals(date, expected);
|
||||
assertEquals(fieldValues.size(), 0);
|
||||
assertEquals(expected, date);
|
||||
assertEquals(0, fieldValues.size());
|
||||
}
|
||||
|
||||
@Test(dataProvider = "resolve_yd")
|
||||
@ParameterizedTest
|
||||
@MethodSource("data_resolve_yd")
|
||||
public void test_resolve_yd_smart(int y, int d, HijrahDate expected, boolean smart, boolean strict) {
|
||||
Map<TemporalField, Long> fieldValues = new HashMap<>();
|
||||
fieldValues.put(ChronoField.YEAR, (long) y);
|
||||
fieldValues.put(ChronoField.DAY_OF_YEAR, (long) d);
|
||||
if (smart) {
|
||||
HijrahDate date = HijrahChronology.INSTANCE.resolveDate(fieldValues, ResolverStyle.SMART);
|
||||
assertEquals(date, expected);
|
||||
assertEquals(fieldValues.size(), 0);
|
||||
assertEquals(expected, date);
|
||||
assertEquals(0, fieldValues.size());
|
||||
} else {
|
||||
try {
|
||||
HijrahDate date = HijrahChronology.INSTANCE.resolveDate(fieldValues, ResolverStyle.SMART);
|
||||
@ -507,15 +518,16 @@ public class TCKHijrahChronology {
|
||||
}
|
||||
}
|
||||
|
||||
@Test(dataProvider = "resolve_yd")
|
||||
@ParameterizedTest
|
||||
@MethodSource("data_resolve_yd")
|
||||
public void test_resolve_yd_strict(int y, int d, HijrahDate expected, boolean smart, boolean strict) {
|
||||
Map<TemporalField, Long> fieldValues = new HashMap<>();
|
||||
fieldValues.put(ChronoField.YEAR, (long) y);
|
||||
fieldValues.put(ChronoField.DAY_OF_YEAR, (long) d);
|
||||
if (strict) {
|
||||
HijrahDate date = HijrahChronology.INSTANCE.resolveDate(fieldValues, ResolverStyle.STRICT);
|
||||
assertEquals(date, expected);
|
||||
assertEquals(fieldValues.size(), 0);
|
||||
assertEquals(expected, date);
|
||||
assertEquals(0, fieldValues.size());
|
||||
} else {
|
||||
try {
|
||||
HijrahDate date = HijrahChronology.INSTANCE.resolveDate(fieldValues, ResolverStyle.STRICT);
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2012, 2013, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2012, 2025, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
@ -55,8 +55,9 @@
|
||||
package tck.java.time.chrono;
|
||||
|
||||
import static java.time.temporal.ChronoField.ERA;
|
||||
import static org.testng.Assert.assertEquals;
|
||||
import static org.testng.Assert.assertTrue;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
import java.time.chrono.Era;
|
||||
import java.time.chrono.HijrahChronology;
|
||||
@ -64,29 +65,31 @@ import java.time.chrono.HijrahEra;
|
||||
import java.time.temporal.ValueRange;
|
||||
import java.util.List;
|
||||
|
||||
import org.testng.annotations.DataProvider;
|
||||
import org.testng.annotations.Test;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.TestInstance;
|
||||
import org.junit.jupiter.params.ParameterizedTest;
|
||||
import org.junit.jupiter.params.provider.MethodSource;
|
||||
|
||||
/**
|
||||
* Test.
|
||||
*/
|
||||
@Test
|
||||
@TestInstance(TestInstance.Lifecycle.PER_CLASS)
|
||||
public class TCKHijrahEra {
|
||||
|
||||
@DataProvider(name = "HijrahEras")
|
||||
Object[][] data_of_eras() {
|
||||
return new Object[][] {
|
||||
{HijrahEra.AH, "AH", 1},
|
||||
};
|
||||
}
|
||||
|
||||
@Test(dataProvider="HijrahEras")
|
||||
@ParameterizedTest
|
||||
@MethodSource("data_of_eras")
|
||||
public void test_valueOf(HijrahEra era , String eraName, int eraValue) {
|
||||
assertEquals(era.getValue(), eraValue);
|
||||
assertEquals(eraValue, era.getValue());
|
||||
|
||||
assertEquals(HijrahChronology.INSTANCE.eraOf(eraValue), era);
|
||||
assertEquals(HijrahEra.of(eraValue), era);
|
||||
assertEquals(HijrahEra.valueOf(eraName), era);
|
||||
assertEquals(era, HijrahChronology.INSTANCE.eraOf(eraValue));
|
||||
assertEquals(era, HijrahEra.of(eraValue));
|
||||
assertEquals(era, HijrahEra.valueOf(eraName));
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
@ -96,7 +99,7 @@ public class TCKHijrahEra {
|
||||
public void test_values() {
|
||||
List<Era> eraList = HijrahChronology.INSTANCE.eras();
|
||||
HijrahEra[] eras = HijrahEra.values();
|
||||
assertEquals(eraList.size(), eras.length);
|
||||
assertEquals(eras.length, eraList.size());
|
||||
for (HijrahEra era : eras) {
|
||||
assertTrue(eraList.contains(era));
|
||||
}
|
||||
@ -108,7 +111,7 @@ public class TCKHijrahEra {
|
||||
@Test
|
||||
public void test_range() {
|
||||
for (HijrahEra era : HijrahEra.values()) {
|
||||
assertEquals(era.range(ERA), ValueRange.of(1, 1));
|
||||
assertEquals(ValueRange.of(1, 1), era.range(ERA));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2012, 2016, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2012, 2025, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
@ -54,8 +54,8 @@
|
||||
*/
|
||||
package tck.java.time.chrono;
|
||||
|
||||
import static org.testng.Assert.assertEquals;
|
||||
import static org.testng.Assert.fail;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.fail;
|
||||
|
||||
import java.time.DateTimeException;
|
||||
import java.time.LocalDate;
|
||||
@ -81,13 +81,16 @@ import java.time.temporal.TemporalQuery;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import org.testng.annotations.DataProvider;
|
||||
import org.testng.annotations.Test;
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.TestInstance;
|
||||
import org.junit.jupiter.params.ParameterizedTest;
|
||||
import org.junit.jupiter.params.provider.MethodSource;
|
||||
|
||||
/**
|
||||
* Test.
|
||||
*/
|
||||
@Test
|
||||
@TestInstance(TestInstance.Lifecycle.PER_CLASS)
|
||||
public class TCKIsoChronology {
|
||||
// Can only work with IsoChronology here
|
||||
// others may be in separate module
|
||||
@ -96,12 +99,12 @@ public class TCKIsoChronology {
|
||||
|
||||
@Test
|
||||
public void factory_from_TemporalAccessor_dateWithChronlogy() {
|
||||
assertEquals(Chronology.from(LocalDate.of(2012, 6, 30)), IsoChronology.INSTANCE);
|
||||
assertEquals(IsoChronology.INSTANCE, Chronology.from(LocalDate.of(2012, 6, 30)));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void factory_from_TemporalAccessor_chronology() {
|
||||
assertEquals(Chronology.from(new TemporalAccessor() {
|
||||
assertEquals(IsoChronology.INSTANCE, Chronology.from(new TemporalAccessor() {
|
||||
@Override
|
||||
public boolean isSupported(TemporalField field) {
|
||||
throw new UnsupportedOperationException();
|
||||
@ -120,12 +123,12 @@ public class TCKIsoChronology {
|
||||
}
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
}), IsoChronology.INSTANCE);
|
||||
}));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void factory_from_TemporalAccessor_noChronology() {
|
||||
assertEquals(Chronology.from(new TemporalAccessor() {
|
||||
assertEquals(IsoChronology.INSTANCE, Chronology.from(new TemporalAccessor() {
|
||||
@Override
|
||||
public boolean isSupported(TemporalField field) {
|
||||
throw new UnsupportedOperationException();
|
||||
@ -143,18 +146,18 @@ public class TCKIsoChronology {
|
||||
}
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
}), IsoChronology.INSTANCE);
|
||||
}));
|
||||
}
|
||||
|
||||
@Test(expectedExceptions=NullPointerException.class)
|
||||
@Test
|
||||
public void factory_from_TemporalAccessor_null() {
|
||||
Chronology.from(null);
|
||||
Assertions.assertThrows(NullPointerException.class, () -> Chronology.from(null));
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
@Test
|
||||
public void test_date_TemporalAccessor() {
|
||||
assertEquals(IsoChronology.INSTANCE.date(new TemporalAccessor() {
|
||||
assertEquals(LocalDate.of(2012, 6, 30), IsoChronology.INSTANCE.date(new TemporalAccessor() {
|
||||
@Override
|
||||
public boolean isSupported(TemporalField field) {
|
||||
if (field == ChronoField.EPOCH_DAY) {
|
||||
@ -179,18 +182,18 @@ public class TCKIsoChronology {
|
||||
}
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
}), LocalDate.of(2012, 6, 30));
|
||||
}));
|
||||
}
|
||||
|
||||
@Test(expectedExceptions=NullPointerException.class)
|
||||
@Test
|
||||
public void test_date_TemporalAccessor_null() {
|
||||
IsoChronology.INSTANCE.date(null);
|
||||
Assertions.assertThrows(NullPointerException.class, () -> IsoChronology.INSTANCE.date(null));
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
@Test
|
||||
public void test_localDateTime_TemporalAccessor() {
|
||||
assertEquals(IsoChronology.INSTANCE.localDateTime(new TemporalAccessor() {
|
||||
assertEquals(LocalDateTime.of(2012, 6, 30, 12, 30, 40), IsoChronology.INSTANCE.localDateTime(new TemporalAccessor() {
|
||||
@Override
|
||||
public boolean isSupported(TemporalField field) {
|
||||
if (field == ChronoField.EPOCH_DAY || field == ChronoField.NANO_OF_DAY) {
|
||||
@ -221,18 +224,18 @@ public class TCKIsoChronology {
|
||||
}
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
}), LocalDateTime.of(2012, 6, 30, 12, 30, 40));
|
||||
}));
|
||||
}
|
||||
|
||||
@Test(expectedExceptions=NullPointerException.class)
|
||||
@Test
|
||||
public void test_localDateTime_TemporalAccessor_null() {
|
||||
IsoChronology.INSTANCE.localDateTime(null);
|
||||
Assertions.assertThrows(NullPointerException.class, () -> IsoChronology.INSTANCE.localDateTime(null));
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
@Test
|
||||
public void test_zonedDateTime_TemporalAccessor() {
|
||||
assertEquals(IsoChronology.INSTANCE.zonedDateTime(new TemporalAccessor() {
|
||||
assertEquals(ZonedDateTime.of(2012, 6, 30, 12, 30, 40, 0, ZoneId.of("Europe/London")), IsoChronology.INSTANCE.zonedDateTime(new TemporalAccessor() {
|
||||
@Override
|
||||
public boolean isSupported(TemporalField field) {
|
||||
if (field == ChronoField.EPOCH_DAY || field == ChronoField.NANO_OF_DAY ||
|
||||
@ -273,17 +276,16 @@ public class TCKIsoChronology {
|
||||
}
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
}), ZonedDateTime.of(2012, 6, 30, 12, 30, 40, 0, ZoneId.of("Europe/London")));
|
||||
}));
|
||||
}
|
||||
|
||||
@Test(expectedExceptions=NullPointerException.class)
|
||||
@Test
|
||||
public void test_zonedDateTime_TemporalAccessor_null() {
|
||||
IsoChronology.INSTANCE.zonedDateTime(null);
|
||||
Assertions.assertThrows(NullPointerException.class, () -> IsoChronology.INSTANCE.zonedDateTime(null));
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------
|
||||
@DataProvider(name = "resolve_yearOfEra")
|
||||
Object[][] data_resolve_yearOfEra() {
|
||||
return new Object[][] {
|
||||
// era only
|
||||
@ -348,7 +350,8 @@ public class TCKIsoChronology {
|
||||
};
|
||||
}
|
||||
|
||||
@Test(dataProvider = "resolve_yearOfEra")
|
||||
@ParameterizedTest
|
||||
@MethodSource("data_resolve_yearOfEra")
|
||||
public void test_resolve_yearOfEra(ResolverStyle style, Integer e, Integer yoe, Integer y, ChronoField field, Integer expected) {
|
||||
Map<TemporalField, Long> fieldValues = new HashMap<>();
|
||||
if (e != null) {
|
||||
@ -362,9 +365,9 @@ public class TCKIsoChronology {
|
||||
}
|
||||
if (field != null) {
|
||||
LocalDate date = IsoChronology.INSTANCE.resolveDate(fieldValues, style);
|
||||
assertEquals(date, null);
|
||||
assertEquals(fieldValues.get(field), (Long) expected.longValue());
|
||||
assertEquals(fieldValues.size(), 1);
|
||||
assertEquals(null, date);
|
||||
assertEquals((Long) expected.longValue(), fieldValues.get(field));
|
||||
assertEquals(1, fieldValues.size());
|
||||
} else {
|
||||
try {
|
||||
IsoChronology.INSTANCE.resolveDate(fieldValues, style);
|
||||
@ -377,7 +380,6 @@ public class TCKIsoChronology {
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------
|
||||
@DataProvider(name = "resolve_ymd")
|
||||
Object[][] data_resolve_ymd() {
|
||||
return new Object[][] {
|
||||
{2012, 1, -365, date(2010, 12, 31), false, false},
|
||||
@ -436,18 +438,20 @@ public class TCKIsoChronology {
|
||||
};
|
||||
}
|
||||
|
||||
@Test(dataProvider = "resolve_ymd")
|
||||
@ParameterizedTest
|
||||
@MethodSource("data_resolve_ymd")
|
||||
public void test_resolve_ymd_lenient(int y, int m, int d, LocalDate expected, Object smart, boolean strict) {
|
||||
Map<TemporalField, Long> fieldValues = new HashMap<>();
|
||||
fieldValues.put(ChronoField.YEAR, (long) y);
|
||||
fieldValues.put(ChronoField.MONTH_OF_YEAR, (long) m);
|
||||
fieldValues.put(ChronoField.DAY_OF_MONTH, (long) d);
|
||||
LocalDate date = IsoChronology.INSTANCE.resolveDate(fieldValues, ResolverStyle.LENIENT);
|
||||
assertEquals(date, expected);
|
||||
assertEquals(fieldValues.size(), 0);
|
||||
assertEquals(expected, date);
|
||||
assertEquals(0, fieldValues.size());
|
||||
}
|
||||
|
||||
@Test(dataProvider = "resolve_ymd")
|
||||
@ParameterizedTest
|
||||
@MethodSource("data_resolve_ymd")
|
||||
public void test_resolve_ymd_smart(int y, int m, int d, LocalDate expected, Object smart, boolean strict) {
|
||||
Map<TemporalField, Long> fieldValues = new HashMap<>();
|
||||
fieldValues.put(ChronoField.YEAR, (long) y);
|
||||
@ -455,11 +459,11 @@ public class TCKIsoChronology {
|
||||
fieldValues.put(ChronoField.DAY_OF_MONTH, (long) d);
|
||||
if (Boolean.TRUE.equals(smart)) {
|
||||
LocalDate date = IsoChronology.INSTANCE.resolveDate(fieldValues, ResolverStyle.SMART);
|
||||
assertEquals(date, expected);
|
||||
assertEquals(fieldValues.size(), 0);
|
||||
assertEquals(expected, date);
|
||||
assertEquals(0, fieldValues.size());
|
||||
} else if (smart instanceof LocalDate) {
|
||||
LocalDate date = IsoChronology.INSTANCE.resolveDate(fieldValues, ResolverStyle.SMART);
|
||||
assertEquals(date, smart);
|
||||
assertEquals(smart, date);
|
||||
} else {
|
||||
try {
|
||||
IsoChronology.INSTANCE.resolveDate(fieldValues, ResolverStyle.SMART);
|
||||
@ -470,7 +474,8 @@ public class TCKIsoChronology {
|
||||
}
|
||||
}
|
||||
|
||||
@Test(dataProvider = "resolve_ymd")
|
||||
@ParameterizedTest
|
||||
@MethodSource("data_resolve_ymd")
|
||||
public void test_resolve_ymd_strict(int y, int m, int d, LocalDate expected, Object smart, boolean strict) {
|
||||
Map<TemporalField, Long> fieldValues = new HashMap<>();
|
||||
fieldValues.put(ChronoField.YEAR, (long) y);
|
||||
@ -478,8 +483,8 @@ public class TCKIsoChronology {
|
||||
fieldValues.put(ChronoField.DAY_OF_MONTH, (long) d);
|
||||
if (strict) {
|
||||
LocalDate date = IsoChronology.INSTANCE.resolveDate(fieldValues, ResolverStyle.STRICT);
|
||||
assertEquals(date, expected);
|
||||
assertEquals(fieldValues.size(), 0);
|
||||
assertEquals(expected, date);
|
||||
assertEquals(0, fieldValues.size());
|
||||
} else {
|
||||
try {
|
||||
IsoChronology.INSTANCE.resolveDate(fieldValues, ResolverStyle.STRICT);
|
||||
@ -492,7 +497,6 @@ public class TCKIsoChronology {
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------
|
||||
@DataProvider(name = "resolve_yd")
|
||||
Object[][] data_resolve_yd() {
|
||||
return new Object[][] {
|
||||
{2012, -365, date(2010, 12, 31), false, false},
|
||||
@ -520,25 +524,27 @@ public class TCKIsoChronology {
|
||||
};
|
||||
}
|
||||
|
||||
@Test(dataProvider = "resolve_yd")
|
||||
@ParameterizedTest
|
||||
@MethodSource("data_resolve_yd")
|
||||
public void test_resolve_yd_lenient(int y, int d, LocalDate expected, boolean smart, boolean strict) {
|
||||
Map<TemporalField, Long> fieldValues = new HashMap<>();
|
||||
fieldValues.put(ChronoField.YEAR, (long) y);
|
||||
fieldValues.put(ChronoField.DAY_OF_YEAR, (long) d);
|
||||
LocalDate date = IsoChronology.INSTANCE.resolveDate(fieldValues, ResolverStyle.LENIENT);
|
||||
assertEquals(date, expected);
|
||||
assertEquals(fieldValues.size(), 0);
|
||||
assertEquals(expected, date);
|
||||
assertEquals(0, fieldValues.size());
|
||||
}
|
||||
|
||||
@Test(dataProvider = "resolve_yd")
|
||||
@ParameterizedTest
|
||||
@MethodSource("data_resolve_yd")
|
||||
public void test_resolve_yd_smart(int y, int d, LocalDate expected, boolean smart, boolean strict) {
|
||||
Map<TemporalField, Long> fieldValues = new HashMap<>();
|
||||
fieldValues.put(ChronoField.YEAR, (long) y);
|
||||
fieldValues.put(ChronoField.DAY_OF_YEAR, (long) d);
|
||||
if (smart) {
|
||||
LocalDate date = IsoChronology.INSTANCE.resolveDate(fieldValues, ResolverStyle.SMART);
|
||||
assertEquals(date, expected);
|
||||
assertEquals(fieldValues.size(), 0);
|
||||
assertEquals(expected, date);
|
||||
assertEquals(0, fieldValues.size());
|
||||
} else {
|
||||
try {
|
||||
IsoChronology.INSTANCE.resolveDate(fieldValues, ResolverStyle.SMART);
|
||||
@ -549,15 +555,16 @@ public class TCKIsoChronology {
|
||||
}
|
||||
}
|
||||
|
||||
@Test(dataProvider = "resolve_yd")
|
||||
@ParameterizedTest
|
||||
@MethodSource("data_resolve_yd")
|
||||
public void test_resolve_yd_strict(int y, int d, LocalDate expected, boolean smart, boolean strict) {
|
||||
Map<TemporalField, Long> fieldValues = new HashMap<>();
|
||||
fieldValues.put(ChronoField.YEAR, (long) y);
|
||||
fieldValues.put(ChronoField.DAY_OF_YEAR, (long) d);
|
||||
if (strict) {
|
||||
LocalDate date = IsoChronology.INSTANCE.resolveDate(fieldValues, ResolverStyle.STRICT);
|
||||
assertEquals(date, expected);
|
||||
assertEquals(fieldValues.size(), 0);
|
||||
assertEquals(expected, date);
|
||||
assertEquals(0, fieldValues.size());
|
||||
} else {
|
||||
try {
|
||||
IsoChronology.INSTANCE.resolveDate(fieldValues, ResolverStyle.STRICT);
|
||||
@ -570,7 +577,6 @@ public class TCKIsoChronology {
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------
|
||||
@DataProvider(name = "resolve_ymaa")
|
||||
Object[][] data_resolve_ymaa() {
|
||||
return new Object[][] {
|
||||
{2012, 1, 1, -365, date(2010, 12, 31), false, false},
|
||||
@ -627,7 +633,8 @@ public class TCKIsoChronology {
|
||||
};
|
||||
}
|
||||
|
||||
@Test(dataProvider = "resolve_ymaa")
|
||||
@ParameterizedTest
|
||||
@MethodSource("data_resolve_ymaa")
|
||||
public void test_resolve_ymaa_lenient(int y, int m, int w, int d, LocalDate expected, boolean smart, boolean strict) {
|
||||
Map<TemporalField, Long> fieldValues = new HashMap<>();
|
||||
fieldValues.put(ChronoField.YEAR, (long) y);
|
||||
@ -635,11 +642,12 @@ public class TCKIsoChronology {
|
||||
fieldValues.put(ChronoField.ALIGNED_WEEK_OF_MONTH, (long) w);
|
||||
fieldValues.put(ChronoField.ALIGNED_DAY_OF_WEEK_IN_MONTH, (long) d);
|
||||
LocalDate date = IsoChronology.INSTANCE.resolveDate(fieldValues, ResolverStyle.LENIENT);
|
||||
assertEquals(date, expected);
|
||||
assertEquals(fieldValues.size(), 0);
|
||||
assertEquals(expected, date);
|
||||
assertEquals(0, fieldValues.size());
|
||||
}
|
||||
|
||||
@Test(dataProvider = "resolve_ymaa")
|
||||
@ParameterizedTest
|
||||
@MethodSource("data_resolve_ymaa")
|
||||
public void test_resolve_ymaa_smart(int y, int m, int w, int d, LocalDate expected, boolean smart, boolean strict) {
|
||||
Map<TemporalField, Long> fieldValues = new HashMap<>();
|
||||
fieldValues.put(ChronoField.YEAR, (long) y);
|
||||
@ -648,8 +656,8 @@ public class TCKIsoChronology {
|
||||
fieldValues.put(ChronoField.ALIGNED_DAY_OF_WEEK_IN_MONTH, (long) d);
|
||||
if (smart) {
|
||||
LocalDate date = IsoChronology.INSTANCE.resolveDate(fieldValues, ResolverStyle.SMART);
|
||||
assertEquals(date, expected);
|
||||
assertEquals(fieldValues.size(), 0);
|
||||
assertEquals(expected, date);
|
||||
assertEquals(0, fieldValues.size());
|
||||
} else {
|
||||
try {
|
||||
IsoChronology.INSTANCE.resolveDate(fieldValues, ResolverStyle.SMART);
|
||||
@ -660,7 +668,8 @@ public class TCKIsoChronology {
|
||||
}
|
||||
}
|
||||
|
||||
@Test(dataProvider = "resolve_ymaa")
|
||||
@ParameterizedTest
|
||||
@MethodSource("data_resolve_ymaa")
|
||||
public void test_resolve_ymaa_strict(int y, int m, int w, int d, LocalDate expected, boolean smart, boolean strict) {
|
||||
Map<TemporalField, Long> fieldValues = new HashMap<>();
|
||||
fieldValues.put(ChronoField.YEAR, (long) y);
|
||||
@ -669,8 +678,8 @@ public class TCKIsoChronology {
|
||||
fieldValues.put(ChronoField.ALIGNED_DAY_OF_WEEK_IN_MONTH, (long) d);
|
||||
if (strict) {
|
||||
LocalDate date = IsoChronology.INSTANCE.resolveDate(fieldValues, ResolverStyle.STRICT);
|
||||
assertEquals(date, expected);
|
||||
assertEquals(fieldValues.size(), 0);
|
||||
assertEquals(expected, date);
|
||||
assertEquals(0, fieldValues.size());
|
||||
} else {
|
||||
try {
|
||||
IsoChronology.INSTANCE.resolveDate(fieldValues, ResolverStyle.STRICT);
|
||||
@ -681,7 +690,6 @@ public class TCKIsoChronology {
|
||||
}
|
||||
}
|
||||
|
||||
@DataProvider(name = "epochSecond_dataProvider")
|
||||
Object[][] data_epochSecond() {
|
||||
return new Object[][] {
|
||||
{2008, 3, 3, 1, 2, 2, OFFSET_P0100},
|
||||
@ -703,33 +711,28 @@ public class TCKIsoChronology {
|
||||
};
|
||||
}
|
||||
|
||||
@Test(dataProvider = "epochSecond_dataProvider")
|
||||
@ParameterizedTest
|
||||
@MethodSource("data_epochSecond")
|
||||
public void test_epochSecond_1(int y, int m, int d, int h , int min, int s, ZoneOffset offset) {
|
||||
assertEquals(IsoChronology.INSTANCE.epochSecond(y, m, d, h, min, s, offset),
|
||||
OffsetDateTime.of(y, m, d, h, min, s, 0, offset).toEpochSecond());
|
||||
assertEquals(OffsetDateTime.of(y, m, d, h, min, s, 0, offset).toEpochSecond(), IsoChronology.INSTANCE.epochSecond(y, m, d, h, min, s, offset));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test_epochSecond_2() {
|
||||
assertEquals(IsoChronology.INSTANCE.epochSecond(2008, 3, 3, 1, 2, 2, OFFSET_P0100),
|
||||
ZonedDateTime.of(2008, 3, 3, 1, 2, 2, 0, ZoneId.of("+01:00")).toEpochSecond());
|
||||
assertEquals(IsoChronology.INSTANCE.epochSecond(1969, 3, 3, 1, 2, 2, OFFSET_P0100),
|
||||
ZonedDateTime.of(1969, 3, 3, 1, 2, 2, 0, ZoneId.of("+01:00")).toEpochSecond());
|
||||
assertEquals(ZonedDateTime.of(2008, 3, 3, 1, 2, 2, 0, ZoneId.of("+01:00")).toEpochSecond(), IsoChronology.INSTANCE.epochSecond(2008, 3, 3, 1, 2, 2, OFFSET_P0100));
|
||||
assertEquals(ZonedDateTime.of(1969, 3, 3, 1, 2, 2, 0, ZoneId.of("+01:00")).toEpochSecond(), IsoChronology.INSTANCE.epochSecond(1969, 3, 3, 1, 2, 2, OFFSET_P0100));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test_epochSecond_max() {
|
||||
assertEquals(IsoChronology.INSTANCE.epochSecond(Year.MAX_VALUE, 12, 31, 23, 59, 59, ZoneOffset.MIN),
|
||||
OffsetDateTime.of(Year.MAX_VALUE, 12, 31, 23, 59, 59, 0, ZoneOffset.MIN).toEpochSecond());
|
||||
assertEquals(OffsetDateTime.of(Year.MAX_VALUE, 12, 31, 23, 59, 59, 0, ZoneOffset.MIN).toEpochSecond(), IsoChronology.INSTANCE.epochSecond(Year.MAX_VALUE, 12, 31, 23, 59, 59, ZoneOffset.MIN));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test_epochSecond_min() {
|
||||
assertEquals(IsoChronology.INSTANCE.epochSecond(Year.MIN_VALUE, 1, 1, 0, 0, 0, ZoneOffset.MAX),
|
||||
OffsetDateTime.of(Year.MIN_VALUE, 1, 1, 0, 0, 0, 0, ZoneOffset.MAX).toEpochSecond());
|
||||
assertEquals(OffsetDateTime.of(Year.MIN_VALUE, 1, 1, 0, 0, 0, 0, ZoneOffset.MAX).toEpochSecond(), IsoChronology.INSTANCE.epochSecond(Year.MIN_VALUE, 1, 1, 0, 0, 0, ZoneOffset.MAX));
|
||||
}
|
||||
|
||||
@DataProvider(name = "bad_epochSecond_dataProvider")
|
||||
Object[][] bad_data_epochSecond() {
|
||||
return new Object[][] {
|
||||
{2009, 13, 1, 1, 1, 1, OFFSET_P0100},
|
||||
@ -739,12 +742,12 @@ public class TCKIsoChronology {
|
||||
{2009, 1, 1, 1, 1, -11, OFFSET_P0100},
|
||||
};
|
||||
}
|
||||
@Test(dataProvider = "bad_epochSecond_dataProvider", expectedExceptions = DateTimeException.class)
|
||||
@ParameterizedTest
|
||||
@MethodSource("bad_data_epochSecond")
|
||||
public void test_epochSecond_bad(int y, int m, int d, int h , int min, int s, ZoneOffset offset) {
|
||||
IsoChronology.INSTANCE.epochSecond(y, m, d, h, min, s, offset);
|
||||
Assertions.assertThrows(DateTimeException.class, () -> IsoChronology.INSTANCE.epochSecond(y, m, d, h, min, s, offset));
|
||||
}
|
||||
|
||||
@DataProvider(name = "era_epochSecond_dataProvider")
|
||||
Object[][] data_era_epochSecond() {
|
||||
return new Object[][] {
|
||||
{IsoEra.CE, 2008, 3, 3, 1, 2, 2, OFFSET_P0100},
|
||||
@ -766,24 +769,22 @@ public class TCKIsoChronology {
|
||||
};
|
||||
}
|
||||
|
||||
@Test(dataProvider = "era_epochSecond_dataProvider")
|
||||
@ParameterizedTest
|
||||
@MethodSource("data_era_epochSecond")
|
||||
public void test_era_epochSecond_1(Era era, int y, int m, int d, int h , int min, int s, ZoneOffset offset) {
|
||||
assertEquals(IsoChronology.INSTANCE.epochSecond(era, y, m, d, h, min, s, offset),
|
||||
OffsetDateTime.of(IsoChronology.INSTANCE.date(era, y, m, d), LocalTime.of(h, min, s), offset)
|
||||
.toEpochSecond());
|
||||
assertEquals(OffsetDateTime.of(IsoChronology.INSTANCE.date(era, y, m, d), LocalTime.of(h, min, s), offset)
|
||||
.toEpochSecond(), IsoChronology.INSTANCE.epochSecond(era, y, m, d, h, min, s, offset));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test_era_epochSecond_2() {
|
||||
assertEquals(IsoChronology.INSTANCE.epochSecond(IsoEra.CE, 2008, 3, 3, 1, 2, 2, OFFSET_P0100),
|
||||
ZonedDateTime.of(2008, 3, 3, 1, 2, 2, 0, ZoneId.of("+01:00")).toEpochSecond());
|
||||
assertEquals(IsoChronology.INSTANCE.epochSecond(IsoEra.CE, 1969, 3, 3, 1, 2, 2, OFFSET_P0100),
|
||||
ZonedDateTime.of(1969, 3, 3, 1, 2, 2, 0, ZoneId.of("+01:00")).toEpochSecond());
|
||||
assertEquals(ZonedDateTime.of(2008, 3, 3, 1, 2, 2, 0, ZoneId.of("+01:00")).toEpochSecond(), IsoChronology.INSTANCE.epochSecond(IsoEra.CE, 2008, 3, 3, 1, 2, 2, OFFSET_P0100));
|
||||
assertEquals(ZonedDateTime.of(1969, 3, 3, 1, 2, 2, 0, ZoneId.of("+01:00")).toEpochSecond(), IsoChronology.INSTANCE.epochSecond(IsoEra.CE, 1969, 3, 3, 1, 2, 2, OFFSET_P0100));
|
||||
}
|
||||
|
||||
@Test(expectedExceptions = ClassCastException.class)
|
||||
@Test
|
||||
public void test_era_epochSecond_bad() {
|
||||
IsoChronology.INSTANCE.epochSecond(HijrahEra.AH, 2009, 2, 29, 1, 2, 2, OFFSET_P0100);
|
||||
Assertions.assertThrows(ClassCastException.class, () -> IsoChronology.INSTANCE.epochSecond(HijrahEra.AH, 2009, 2, 29, 1, 2, 2, OFFSET_P0100));
|
||||
}
|
||||
|
||||
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2012, 2013, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2012, 2025, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
@ -55,8 +55,9 @@
|
||||
package tck.java.time.chrono;
|
||||
|
||||
import static java.time.temporal.ChronoField.ERA;
|
||||
import static org.testng.Assert.assertEquals;
|
||||
import static org.testng.Assert.assertTrue;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
import java.time.chrono.Era;
|
||||
import java.time.chrono.IsoChronology;
|
||||
@ -64,16 +65,17 @@ import java.time.chrono.IsoEra;
|
||||
import java.time.temporal.ValueRange;
|
||||
import java.util.List;
|
||||
|
||||
import org.testng.annotations.DataProvider;
|
||||
import org.testng.annotations.Test;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.TestInstance;
|
||||
import org.junit.jupiter.params.ParameterizedTest;
|
||||
import org.junit.jupiter.params.provider.MethodSource;
|
||||
|
||||
/**
|
||||
* Test.
|
||||
*/
|
||||
@Test
|
||||
@TestInstance(TestInstance.Lifecycle.PER_CLASS)
|
||||
public class TCKIsoEra {
|
||||
|
||||
@DataProvider(name = "IsoEras")
|
||||
Object[][] data_of_eras() {
|
||||
return new Object[][] {
|
||||
{IsoEra.BCE, "BCE", 0},
|
||||
@ -81,11 +83,12 @@ public class TCKIsoEra {
|
||||
};
|
||||
}
|
||||
|
||||
@Test(dataProvider="IsoEras")
|
||||
@ParameterizedTest
|
||||
@MethodSource("data_of_eras")
|
||||
public void test_valueOf(IsoEra era , String eraName, int eraValue) {
|
||||
assertEquals(era.getValue(), eraValue);
|
||||
assertEquals(IsoEra.of(eraValue), era);
|
||||
assertEquals(IsoEra.valueOf(eraName), era);
|
||||
assertEquals(eraValue, era.getValue());
|
||||
assertEquals(era, IsoEra.of(eraValue));
|
||||
assertEquals(era, IsoEra.valueOf(eraName));
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
@ -95,7 +98,7 @@ public class TCKIsoEra {
|
||||
public void test_values() {
|
||||
List<Era> eraList = IsoChronology.INSTANCE.eras();
|
||||
IsoEra[] eras = IsoEra.values();
|
||||
assertEquals(eraList.size(), eras.length);
|
||||
assertEquals(eras.length, eraList.size());
|
||||
for (IsoEra era : eras) {
|
||||
assertTrue(eraList.contains(era));
|
||||
}
|
||||
@ -107,7 +110,7 @@ public class TCKIsoEra {
|
||||
@Test
|
||||
public void test_range() {
|
||||
for (IsoEra era : IsoEra.values()) {
|
||||
assertEquals(era.range(ERA), ValueRange.of(0, 1));
|
||||
assertEquals(ValueRange.of(0, 1), era.range(ERA));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
/*
|
||||
o Copyright (c) 2012, 2022, Oracle and/or its affiliates. All rights reserved.
|
||||
o Copyright (c) 2012, 2025, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
@ -61,18 +61,17 @@ import static java.time.temporal.ChronoField.ERA;
|
||||
import static java.time.temporal.ChronoField.MONTH_OF_YEAR;
|
||||
import static java.time.temporal.ChronoField.YEAR;
|
||||
import static java.time.temporal.ChronoField.YEAR_OF_ERA;
|
||||
import static org.testng.Assert.assertEquals;
|
||||
import static org.testng.Assert.assertFalse;
|
||||
import static org.testng.Assert.assertNotEquals;
|
||||
import static org.testng.Assert.assertTrue;
|
||||
import static org.testng.Assert.fail;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
import static org.junit.jupiter.api.Assertions.fail;
|
||||
|
||||
import java.time.Clock;
|
||||
import java.time.DateTimeException;
|
||||
import java.time.LocalDate;
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.Month;
|
||||
import java.time.Period;
|
||||
import java.time.Year;
|
||||
import java.time.ZoneId;
|
||||
import java.time.ZoneOffset;
|
||||
@ -86,7 +85,6 @@ import java.time.chrono.JapaneseDate;
|
||||
import java.time.chrono.JapaneseEra;
|
||||
import java.time.chrono.MinguoChronology;
|
||||
import java.time.chrono.MinguoDate;
|
||||
import java.time.chrono.ThaiBuddhistChronology;
|
||||
import java.time.format.ResolverStyle;
|
||||
import java.time.temporal.ChronoField;
|
||||
import java.time.temporal.ChronoUnit;
|
||||
@ -100,14 +98,16 @@ import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
|
||||
import org.testng.Assert;
|
||||
import org.testng.annotations.DataProvider;
|
||||
import org.testng.annotations.Test;
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.TestInstance;
|
||||
import org.junit.jupiter.params.ParameterizedTest;
|
||||
import org.junit.jupiter.params.provider.MethodSource;
|
||||
|
||||
/**
|
||||
* Test.
|
||||
*/
|
||||
@Test
|
||||
@TestInstance(TestInstance.Lifecycle.PER_CLASS)
|
||||
public class TCKJapaneseChronology {
|
||||
|
||||
// Year differences from Gregorian years.
|
||||
@ -124,10 +124,10 @@ public class TCKJapaneseChronology {
|
||||
public void test_chrono_byName() {
|
||||
Chronology c = JapaneseChronology.INSTANCE;
|
||||
Chronology test = Chronology.of("Japanese");
|
||||
Assert.assertNotNull(test, "The Japanese calendar could not be found byName");
|
||||
Assert.assertEquals(test.getId(), "Japanese", "ID mismatch");
|
||||
Assert.assertEquals(test.getCalendarType(), "japanese", "Type mismatch");
|
||||
Assert.assertEquals(test, c);
|
||||
Assertions.assertNotNull(test, "The Japanese calendar could not be found byName");
|
||||
assertEquals("Japanese", test.getId(), "ID mismatch");
|
||||
assertEquals("japanese", test.getCalendarType(), "Type mismatch");
|
||||
assertEquals(c, test);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
@ -136,42 +136,41 @@ public class TCKJapaneseChronology {
|
||||
@Test
|
||||
public void test_chrono_byLocale_fullTag_japaneseCalendarFromJapan() {
|
||||
Chronology test = Chronology.ofLocale(Locale.forLanguageTag("ja-JP-u-ca-japanese"));
|
||||
Assert.assertEquals(test.getId(), "Japanese");
|
||||
Assert.assertEquals(test, JapaneseChronology.INSTANCE);
|
||||
assertEquals("Japanese", test.getId());
|
||||
assertEquals(JapaneseChronology.INSTANCE, test);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test_chrono_byLocale_fullTag_japaneseCalendarFromElsewhere() {
|
||||
Chronology test = Chronology.ofLocale(Locale.forLanguageTag("en-US-u-ca-japanese"));
|
||||
Assert.assertEquals(test.getId(), "Japanese");
|
||||
Assert.assertEquals(test, JapaneseChronology.INSTANCE);
|
||||
assertEquals("Japanese", test.getId());
|
||||
assertEquals(JapaneseChronology.INSTANCE, test);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test_chrono_byLocale_oldJP_noVariant() {
|
||||
Chronology test = Chronology.ofLocale(Locale.JAPAN);
|
||||
Assert.assertEquals(test.getId(), "ISO");
|
||||
Assert.assertEquals(test, IsoChronology.INSTANCE);
|
||||
assertEquals("ISO", test.getId());
|
||||
assertEquals(IsoChronology.INSTANCE, test);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test_chrono_byLocale_oldJP_variant() {
|
||||
Chronology test = Chronology.ofLocale(Locale.of("ja", "JP", "JP"));
|
||||
Assert.assertEquals(test.getId(), "Japanese");
|
||||
Assert.assertEquals(test, JapaneseChronology.INSTANCE);
|
||||
assertEquals("Japanese", test.getId());
|
||||
assertEquals(JapaneseChronology.INSTANCE, test);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test_chrono_byLocale_iso() {
|
||||
Assert.assertEquals(Chronology.ofLocale(Locale.JAPAN).getId(), "ISO");
|
||||
Assert.assertEquals(Chronology.ofLocale(Locale.forLanguageTag("ja-JP")).getId(), "ISO");
|
||||
Assert.assertEquals(Chronology.ofLocale(Locale.forLanguageTag("ja-JP-JP")).getId(), "ISO");
|
||||
assertEquals("ISO", Chronology.ofLocale(Locale.JAPAN).getId());
|
||||
assertEquals("ISO", Chronology.ofLocale(Locale.forLanguageTag("ja-JP")).getId());
|
||||
assertEquals("ISO", Chronology.ofLocale(Locale.forLanguageTag("ja-JP-JP")).getId());
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
// creation and cross-checks
|
||||
//-----------------------------------------------------------------------
|
||||
@DataProvider(name="createByEra")
|
||||
Object[][] data_createByEra() {
|
||||
return new Object[][] {
|
||||
{JapaneseEra.REIWA, 2020 - YDIFF_REIWA, 2, 29, 60, LocalDate.of(2020, 2, 29)},
|
||||
@ -190,58 +189,64 @@ public class TCKJapaneseChronology {
|
||||
};
|
||||
}
|
||||
|
||||
@Test(dataProvider="createByEra")
|
||||
@ParameterizedTest
|
||||
@MethodSource("data_createByEra")
|
||||
public void test_createEymd(JapaneseEra era, int yoe, int moy, int dom, int doy, LocalDate iso) {
|
||||
JapaneseDate dateByChronoFactory = JapaneseChronology.INSTANCE.date(era, yoe, moy, dom);
|
||||
JapaneseDate dateByDateFactory = JapaneseDate.of(era, yoe, moy, dom);
|
||||
assertEquals(dateByChronoFactory, dateByDateFactory);
|
||||
assertEquals(dateByChronoFactory.hashCode(), dateByDateFactory.hashCode());
|
||||
assertEquals(dateByDateFactory, dateByChronoFactory);
|
||||
assertEquals(dateByDateFactory.hashCode(), dateByChronoFactory.hashCode());
|
||||
}
|
||||
|
||||
@Test(dataProvider="createByEra")
|
||||
@ParameterizedTest
|
||||
@MethodSource("data_createByEra")
|
||||
public void test_createEyd(JapaneseEra era, int yoe, int moy, int dom, int doy, LocalDate iso) {
|
||||
JapaneseDate dateByChronoFactory = JapaneseChronology.INSTANCE.dateYearDay(era, yoe, doy);
|
||||
JapaneseDate dateByDateFactory = JapaneseDate.of(era, yoe, moy, dom);
|
||||
assertEquals(dateByChronoFactory, dateByDateFactory);
|
||||
assertEquals(dateByChronoFactory.hashCode(), dateByDateFactory.hashCode());
|
||||
assertEquals(dateByDateFactory, dateByChronoFactory);
|
||||
assertEquals(dateByDateFactory.hashCode(), dateByChronoFactory.hashCode());
|
||||
}
|
||||
|
||||
@Test(dataProvider="createByEra")
|
||||
@ParameterizedTest
|
||||
@MethodSource("data_createByEra")
|
||||
public void test_createByEra_isEqual(JapaneseEra era, int yoe, int moy, int dom, int doy, LocalDate iso) {
|
||||
JapaneseDate test = JapaneseDate.of(era, yoe, moy, dom);
|
||||
assertEquals(test.isEqual(iso), true);
|
||||
assertEquals(iso.isEqual(test), true);
|
||||
assertEquals(true, test.isEqual(iso));
|
||||
assertEquals(true, iso.isEqual(test));
|
||||
}
|
||||
|
||||
@Test(dataProvider="createByEra")
|
||||
@ParameterizedTest
|
||||
@MethodSource("data_createByEra")
|
||||
public void test_createByEra_chronologyTemporalFactory(JapaneseEra era, int yoe, int moy, int dom, int doy, LocalDate iso) {
|
||||
JapaneseDate test = JapaneseDate.of(era, yoe, moy, dom);
|
||||
assertEquals(IsoChronology.INSTANCE.date(test), iso);
|
||||
assertEquals(JapaneseChronology.INSTANCE.date(iso), test);
|
||||
assertEquals(iso, IsoChronology.INSTANCE.date(test));
|
||||
assertEquals(test, JapaneseChronology.INSTANCE.date(iso));
|
||||
}
|
||||
|
||||
@Test(dataProvider="createByEra")
|
||||
@ParameterizedTest
|
||||
@MethodSource("data_createByEra")
|
||||
public void test_createByEra_dateFrom(JapaneseEra era, int yoe, int moy, int dom, int doy, LocalDate iso) {
|
||||
JapaneseDate test = JapaneseDate.of(era, yoe, moy, dom);
|
||||
assertEquals(LocalDate.from(test), iso);
|
||||
assertEquals(JapaneseDate.from(iso), test);
|
||||
assertEquals(iso, LocalDate.from(test));
|
||||
assertEquals(test, JapaneseDate.from(iso));
|
||||
}
|
||||
|
||||
@Test(dataProvider="createByEra")
|
||||
@ParameterizedTest
|
||||
@MethodSource("data_createByEra")
|
||||
public void test_createByEra_query(JapaneseEra era, int yoe, int moy, int dom, int doy, LocalDate iso) {
|
||||
JapaneseDate test = JapaneseDate.of(era, yoe, moy, dom);
|
||||
assertEquals(test.query(TemporalQueries.localDate()), iso);
|
||||
assertEquals(iso, test.query(TemporalQueries.localDate()));
|
||||
}
|
||||
|
||||
@Test(dataProvider="createByEra")
|
||||
@ParameterizedTest
|
||||
@MethodSource("data_createByEra")
|
||||
public void test_createByEra_epochDay(JapaneseEra era, int yoe, int moy, int dom, int doy, LocalDate iso) {
|
||||
JapaneseDate test = JapaneseDate.of(era, yoe, moy, dom);
|
||||
assertEquals(test.getLong(EPOCH_DAY), iso.getLong(EPOCH_DAY));
|
||||
assertEquals(test.toEpochDay(), iso.toEpochDay());
|
||||
assertEquals(iso.getLong(EPOCH_DAY), test.getLong(EPOCH_DAY));
|
||||
assertEquals(iso.toEpochDay(), test.toEpochDay());
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
@DataProvider(name="createByProleptic")
|
||||
Object[][] data_createByProleptic() {
|
||||
return new Object[][] {
|
||||
{1928, 2, 28, 59, LocalDate.of(1928, 2, 28)},
|
||||
@ -258,79 +263,85 @@ public class TCKJapaneseChronology {
|
||||
};
|
||||
}
|
||||
|
||||
@Test(dataProvider="createByProleptic")
|
||||
@ParameterizedTest
|
||||
@MethodSource("data_createByProleptic")
|
||||
public void test_createYmd(int y, int moy, int dom, int doy, LocalDate iso) {
|
||||
JapaneseDate dateByChronoFactory = JapaneseChronology.INSTANCE.date(y, moy, dom);
|
||||
JapaneseDate dateByDateFactory = JapaneseDate.of(y, moy, dom);
|
||||
assertEquals(dateByChronoFactory, dateByDateFactory);
|
||||
assertEquals(dateByChronoFactory.hashCode(), dateByDateFactory.hashCode());
|
||||
assertEquals(dateByDateFactory, dateByChronoFactory);
|
||||
assertEquals(dateByDateFactory.hashCode(), dateByChronoFactory.hashCode());
|
||||
}
|
||||
|
||||
@Test(dataProvider="createByProleptic")
|
||||
@ParameterizedTest
|
||||
@MethodSource("data_createByProleptic")
|
||||
public void test_createYd(int y, int moy, int dom, int doy, LocalDate iso) {
|
||||
JapaneseDate dateByChronoFactory = JapaneseChronology.INSTANCE.dateYearDay(y, doy);
|
||||
JapaneseDate dateByDateFactory = JapaneseDate.of(y, moy, dom);
|
||||
assertEquals(dateByChronoFactory, dateByDateFactory);
|
||||
assertEquals(dateByChronoFactory.hashCode(), dateByDateFactory.hashCode());
|
||||
assertEquals(dateByDateFactory, dateByChronoFactory);
|
||||
assertEquals(dateByDateFactory.hashCode(), dateByChronoFactory.hashCode());
|
||||
}
|
||||
|
||||
@Test(dataProvider="createByProleptic")
|
||||
@ParameterizedTest
|
||||
@MethodSource("data_createByProleptic")
|
||||
public void test_createByProleptic_isEqual(int y, int moy, int dom, int doy, LocalDate iso) {
|
||||
JapaneseDate test = JapaneseDate.of(y, moy, dom);
|
||||
assertEquals(test.isEqual(iso), true);
|
||||
assertEquals(iso.isEqual(test), true);
|
||||
assertEquals(true, test.isEqual(iso));
|
||||
assertEquals(true, iso.isEqual(test));
|
||||
}
|
||||
|
||||
@Test(dataProvider="createByProleptic")
|
||||
@ParameterizedTest
|
||||
@MethodSource("data_createByProleptic")
|
||||
public void test_createByProleptic_chronologyTemporalFactory(int y, int moy, int dom, int doy, LocalDate iso) {
|
||||
JapaneseDate test = JapaneseDate.of(y, moy, dom);
|
||||
assertEquals(IsoChronology.INSTANCE.date(test), iso);
|
||||
assertEquals(JapaneseChronology.INSTANCE.date(iso), test);
|
||||
assertEquals(iso, IsoChronology.INSTANCE.date(test));
|
||||
assertEquals(test, JapaneseChronology.INSTANCE.date(iso));
|
||||
}
|
||||
|
||||
@Test(dataProvider="createByProleptic")
|
||||
@ParameterizedTest
|
||||
@MethodSource("data_createByProleptic")
|
||||
public void test_createByProleptic_dateFrom(int y, int moy, int dom, int doy, LocalDate iso) {
|
||||
JapaneseDate test = JapaneseDate.of(y, moy, dom);
|
||||
assertEquals(LocalDate.from(test), iso);
|
||||
assertEquals(JapaneseDate.from(iso), test);
|
||||
assertEquals(iso, LocalDate.from(test));
|
||||
assertEquals(test, JapaneseDate.from(iso));
|
||||
}
|
||||
|
||||
@Test(dataProvider="createByProleptic")
|
||||
@ParameterizedTest
|
||||
@MethodSource("data_createByProleptic")
|
||||
public void test_createByProleptic_query(int y, int moy, int dom, int doy, LocalDate iso) {
|
||||
JapaneseDate test = JapaneseDate.of(y, moy, dom);
|
||||
assertEquals(test.query(TemporalQueries.localDate()), iso);
|
||||
assertEquals(iso, test.query(TemporalQueries.localDate()));
|
||||
}
|
||||
|
||||
@Test(dataProvider="createByProleptic")
|
||||
@ParameterizedTest
|
||||
@MethodSource("data_createByProleptic")
|
||||
public void test_createByProleptic_epochDay(int y, int moy, int dom, int doy, LocalDate iso) {
|
||||
JapaneseDate test = JapaneseDate.of(y, moy, dom);
|
||||
assertEquals(test.getLong(EPOCH_DAY), iso.getLong(EPOCH_DAY));
|
||||
assertEquals(test.toEpochDay(), iso.toEpochDay());
|
||||
assertEquals(iso.getLong(EPOCH_DAY), test.getLong(EPOCH_DAY));
|
||||
assertEquals(iso.toEpochDay(), test.toEpochDay());
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
@Test
|
||||
public void test_dateNow(){
|
||||
assertEquals(JapaneseChronology.INSTANCE.dateNow(), JapaneseDate.now()) ;
|
||||
assertEquals(JapaneseChronology.INSTANCE.dateNow(), JapaneseDate.now(ZoneId.systemDefault())) ;
|
||||
assertEquals(JapaneseChronology.INSTANCE.dateNow(), JapaneseDate.now(Clock.systemDefaultZone())) ;
|
||||
assertEquals(JapaneseChronology.INSTANCE.dateNow(), JapaneseDate.now(Clock.systemDefaultZone().getZone())) ;
|
||||
assertEquals(JapaneseDate.now(), JapaneseChronology.INSTANCE.dateNow()) ;
|
||||
assertEquals(JapaneseDate.now(ZoneId.systemDefault()), JapaneseChronology.INSTANCE.dateNow()) ;
|
||||
assertEquals(JapaneseDate.now(Clock.systemDefaultZone()), JapaneseChronology.INSTANCE.dateNow()) ;
|
||||
assertEquals(JapaneseDate.now(Clock.systemDefaultZone().getZone()), JapaneseChronology.INSTANCE.dateNow()) ;
|
||||
|
||||
assertEquals(JapaneseChronology.INSTANCE.dateNow(), JapaneseChronology.INSTANCE.dateNow(ZoneId.systemDefault())) ;
|
||||
assertEquals(JapaneseChronology.INSTANCE.dateNow(), JapaneseChronology.INSTANCE.dateNow(Clock.systemDefaultZone())) ;
|
||||
assertEquals(JapaneseChronology.INSTANCE.dateNow(), JapaneseChronology.INSTANCE.dateNow(Clock.systemDefaultZone().getZone())) ;
|
||||
assertEquals(JapaneseChronology.INSTANCE.dateNow(ZoneId.systemDefault()), JapaneseChronology.INSTANCE.dateNow()) ;
|
||||
assertEquals(JapaneseChronology.INSTANCE.dateNow(Clock.systemDefaultZone()), JapaneseChronology.INSTANCE.dateNow()) ;
|
||||
assertEquals(JapaneseChronology.INSTANCE.dateNow(Clock.systemDefaultZone().getZone()), JapaneseChronology.INSTANCE.dateNow()) ;
|
||||
|
||||
ZoneId zoneId = ZoneId.of("Europe/Paris");
|
||||
assertEquals(JapaneseChronology.INSTANCE.dateNow(zoneId), JapaneseChronology.INSTANCE.dateNow(Clock.system(zoneId))) ;
|
||||
assertEquals(JapaneseChronology.INSTANCE.dateNow(zoneId), JapaneseChronology.INSTANCE.dateNow(Clock.system(zoneId).getZone())) ;
|
||||
assertEquals(JapaneseChronology.INSTANCE.dateNow(zoneId), JapaneseDate.now(Clock.system(zoneId))) ;
|
||||
assertEquals(JapaneseChronology.INSTANCE.dateNow(zoneId), JapaneseDate.now(Clock.system(zoneId).getZone())) ;
|
||||
assertEquals(JapaneseChronology.INSTANCE.dateNow(Clock.system(zoneId)), JapaneseChronology.INSTANCE.dateNow(zoneId)) ;
|
||||
assertEquals(JapaneseChronology.INSTANCE.dateNow(Clock.system(zoneId).getZone()), JapaneseChronology.INSTANCE.dateNow(zoneId)) ;
|
||||
assertEquals(JapaneseDate.now(Clock.system(zoneId)), JapaneseChronology.INSTANCE.dateNow(zoneId)) ;
|
||||
assertEquals(JapaneseDate.now(Clock.system(zoneId).getZone()), JapaneseChronology.INSTANCE.dateNow(zoneId)) ;
|
||||
|
||||
assertEquals(JapaneseChronology.INSTANCE.dateNow(ZoneId.of(ZoneOffset.UTC.getId())), JapaneseChronology.INSTANCE.dateNow(Clock.systemUTC())) ;
|
||||
assertEquals(JapaneseChronology.INSTANCE.dateNow(Clock.systemUTC()), JapaneseChronology.INSTANCE.dateNow(ZoneId.of(ZoneOffset.UTC.getId()))) ;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
@DataProvider(name="badDates")
|
||||
Object[][] data_badDates() {
|
||||
return new Object[][] {
|
||||
{1928, 0, 0},
|
||||
@ -356,15 +367,15 @@ public class TCKJapaneseChronology {
|
||||
};
|
||||
}
|
||||
|
||||
@Test(dataProvider="badDates", expectedExceptions=DateTimeException.class)
|
||||
@ParameterizedTest
|
||||
@MethodSource("data_badDates")
|
||||
public void test_badDates(int year, int month, int dom) {
|
||||
JapaneseChronology.INSTANCE.date(year, month, dom);
|
||||
Assertions.assertThrows(DateTimeException.class, () -> JapaneseChronology.INSTANCE.date(year, month, dom));
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
// prolepticYear() and is LeapYear()
|
||||
//-----------------------------------------------------------------------
|
||||
@DataProvider(name="prolepticYear")
|
||||
Object[][] data_prolepticYear() {
|
||||
return new Object[][] {
|
||||
{3, JapaneseEra.REIWA, 1, 1 + YDIFF_REIWA, false},
|
||||
@ -384,29 +395,30 @@ public class TCKJapaneseChronology {
|
||||
};
|
||||
}
|
||||
|
||||
@Test(dataProvider="prolepticYear")
|
||||
@ParameterizedTest
|
||||
@MethodSource("data_prolepticYear")
|
||||
public void test_prolepticYear(int eraValue, Era era, int yearOfEra, int expectedProlepticYear, boolean isLeapYear) {
|
||||
Era eraObj = JapaneseChronology.INSTANCE.eraOf(eraValue);
|
||||
assertTrue(JapaneseChronology.INSTANCE.eras().contains(eraObj));
|
||||
assertEquals(eraObj, era);
|
||||
assertEquals(JapaneseChronology.INSTANCE.prolepticYear(era, yearOfEra), expectedProlepticYear);
|
||||
assertEquals(era, eraObj);
|
||||
assertEquals(expectedProlepticYear, JapaneseChronology.INSTANCE.prolepticYear(era, yearOfEra));
|
||||
}
|
||||
|
||||
@Test(dataProvider="prolepticYear")
|
||||
@ParameterizedTest
|
||||
@MethodSource("data_prolepticYear")
|
||||
public void test_isLeapYear(int eraValue, Era era, int yearOfEra, int expectedProlepticYear, boolean isLeapYear) {
|
||||
assertEquals(JapaneseChronology.INSTANCE.isLeapYear(expectedProlepticYear), isLeapYear);
|
||||
assertEquals(JapaneseChronology.INSTANCE.isLeapYear(expectedProlepticYear), Year.of(expectedProlepticYear).isLeap());
|
||||
assertEquals(isLeapYear, JapaneseChronology.INSTANCE.isLeapYear(expectedProlepticYear));
|
||||
assertEquals(Year.of(expectedProlepticYear).isLeap(), JapaneseChronology.INSTANCE.isLeapYear(expectedProlepticYear));
|
||||
|
||||
JapaneseDate jdate = JapaneseDate.now();
|
||||
jdate = jdate.with(ChronoField.YEAR, expectedProlepticYear).with(ChronoField.MONTH_OF_YEAR, 2);
|
||||
if (isLeapYear) {
|
||||
assertEquals(jdate.lengthOfMonth(), 29);
|
||||
assertEquals(29, jdate.lengthOfMonth());
|
||||
} else {
|
||||
assertEquals(jdate.lengthOfMonth(), 28);
|
||||
assertEquals(28, jdate.lengthOfMonth());
|
||||
}
|
||||
}
|
||||
|
||||
@DataProvider(name="prolepticYearError")
|
||||
Object[][] data_prolepticYearError() {
|
||||
return new Object[][] {
|
||||
{JapaneseEra.MEIJI, 100},
|
||||
@ -423,9 +435,10 @@ public class TCKJapaneseChronology {
|
||||
};
|
||||
}
|
||||
|
||||
@Test(dataProvider="prolepticYearError", expectedExceptions=DateTimeException.class)
|
||||
@ParameterizedTest
|
||||
@MethodSource("data_prolepticYearError")
|
||||
public void test_prolepticYearError(Era era, int yearOfEra) {
|
||||
JapaneseChronology.INSTANCE.prolepticYear(era, yearOfEra);
|
||||
Assertions.assertThrows(DateTimeException.class, () -> JapaneseChronology.INSTANCE.prolepticYear(era, yearOfEra));
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
@ -464,11 +477,11 @@ public class TCKJapaneseChronology {
|
||||
@Test
|
||||
public void test_getLong() {
|
||||
JapaneseDate base = JapaneseChronology.INSTANCE.date(JapaneseEra.SHOWA, 63, 6, 30);
|
||||
assertEquals(base.getLong(ERA), JapaneseEra.SHOWA.getValue());
|
||||
assertEquals(base.getLong(YEAR), 1988L);
|
||||
assertEquals(base.getLong(YEAR_OF_ERA), 63L);
|
||||
assertEquals(base.getLong(MONTH_OF_YEAR), 6L);
|
||||
assertEquals(base.getLong(DAY_OF_MONTH), 30L);
|
||||
assertEquals(JapaneseEra.SHOWA.getValue(), base.getLong(ERA));
|
||||
assertEquals(1988L, base.getLong(YEAR));
|
||||
assertEquals(63L, base.getLong(YEAR_OF_ERA));
|
||||
assertEquals(6L, base.getLong(MONTH_OF_YEAR));
|
||||
assertEquals(30L, base.getLong(DAY_OF_MONTH));
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
@ -478,19 +491,19 @@ public class TCKJapaneseChronology {
|
||||
public void test_with_TemporalField_long() {
|
||||
JapaneseDate base = JapaneseChronology.INSTANCE.date(JapaneseEra.SHOWA, 63, 6, 30);
|
||||
JapaneseDate test = base.with(YEAR, 1987);
|
||||
assertEquals(test, JapaneseChronology.INSTANCE.date(JapaneseEra.SHOWA, 62, 6, 30));
|
||||
assertEquals(JapaneseChronology.INSTANCE.date(JapaneseEra.SHOWA, 62, 6, 30), test);
|
||||
|
||||
test = test.with(YEAR_OF_ERA, 2);
|
||||
assertEquals(test, JapaneseChronology.INSTANCE.date(JapaneseEra.SHOWA, 2, 6, 30));
|
||||
assertEquals(JapaneseChronology.INSTANCE.date(JapaneseEra.SHOWA, 2, 6, 30), test);
|
||||
|
||||
test = test.with(ERA, JapaneseEra.HEISEI.getValue());
|
||||
assertEquals(test, JapaneseChronology.INSTANCE.date(JapaneseEra.HEISEI, 2, 6, 30));
|
||||
assertEquals(JapaneseChronology.INSTANCE.date(JapaneseEra.HEISEI, 2, 6, 30), test);
|
||||
|
||||
test = test.with(MONTH_OF_YEAR, 3);
|
||||
assertEquals(test, JapaneseChronology.INSTANCE.date(JapaneseEra.HEISEI, 2, 3, 30));
|
||||
assertEquals(JapaneseChronology.INSTANCE.date(JapaneseEra.HEISEI, 2, 3, 30), test);
|
||||
|
||||
test = test.with(DAY_OF_MONTH, 4);
|
||||
assertEquals(test, JapaneseChronology.INSTANCE.date(JapaneseEra.HEISEI, 2, 3, 4));
|
||||
assertEquals(JapaneseChronology.INSTANCE.date(JapaneseEra.HEISEI, 2, 3, 4), test);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
@ -500,14 +513,14 @@ public class TCKJapaneseChronology {
|
||||
public void test_adjust1() {
|
||||
JapaneseDate base = JapaneseChronology.INSTANCE.date(1928, 10, 29);
|
||||
JapaneseDate test = base.with(TemporalAdjusters.lastDayOfMonth());
|
||||
assertEquals(test, JapaneseChronology.INSTANCE.date(1928, 10, 31));
|
||||
assertEquals(JapaneseChronology.INSTANCE.date(1928, 10, 31), test);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test_adjust2() {
|
||||
JapaneseDate base = JapaneseChronology.INSTANCE.date(1928, 12, 2);
|
||||
JapaneseDate test = base.with(TemporalAdjusters.lastDayOfMonth());
|
||||
assertEquals(test, JapaneseChronology.INSTANCE.date(1928, 12, 31));
|
||||
assertEquals(JapaneseChronology.INSTANCE.date(1928, 12, 31), test);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
@ -517,13 +530,15 @@ public class TCKJapaneseChronology {
|
||||
public void test_adjust_toLocalDate() {
|
||||
JapaneseDate jdate = JapaneseChronology.INSTANCE.date(1926, 1, 4);
|
||||
JapaneseDate test = jdate.with(LocalDate.of(2012, 7, 6));
|
||||
assertEquals(test, JapaneseChronology.INSTANCE.date(2012, 7, 6));
|
||||
assertEquals(JapaneseChronology.INSTANCE.date(2012, 7, 6), test);
|
||||
}
|
||||
|
||||
@Test(expectedExceptions=DateTimeException.class)
|
||||
@Test
|
||||
public void test_adjust_toMonth() {
|
||||
JapaneseDate jdate = JapaneseChronology.INSTANCE.date(1926, 1, 4);
|
||||
jdate.with(Month.APRIL);
|
||||
Assertions.assertThrows(DateTimeException.class, () -> {
|
||||
JapaneseDate jdate = JapaneseChronology.INSTANCE.date(1926, 1, 4);
|
||||
jdate.with(Month.APRIL);
|
||||
});
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
@ -533,20 +548,19 @@ public class TCKJapaneseChronology {
|
||||
public void test_LocalDate_adjustToJapaneseDate() {
|
||||
JapaneseDate jdate = JapaneseChronology.INSTANCE.date(1928, 10, 29);
|
||||
LocalDate test = LocalDate.MIN.with(jdate);
|
||||
assertEquals(test, LocalDate.of(1928, 10, 29));
|
||||
assertEquals(LocalDate.of(1928, 10, 29), test);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test_LocalDateTime_adjustToJapaneseDate() {
|
||||
JapaneseDate jdate = JapaneseChronology.INSTANCE.date(1928, 10, 29);
|
||||
LocalDateTime test = LocalDateTime.MIN.with(jdate);
|
||||
assertEquals(test, LocalDateTime.of(1928, 10, 29, 0, 0));
|
||||
assertEquals(LocalDateTime.of(1928, 10, 29, 0, 0), test);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
// Check Japanese Eras
|
||||
//-----------------------------------------------------------------------
|
||||
@DataProvider(name="japaneseEras")
|
||||
Object[][] data_japanseseEras() {
|
||||
return new Object[][] {
|
||||
{ JapaneseEra.MEIJI, -1, "Meiji"},
|
||||
@ -557,11 +571,12 @@ public class TCKJapaneseChronology {
|
||||
};
|
||||
}
|
||||
|
||||
@Test(dataProvider="japaneseEras")
|
||||
@ParameterizedTest
|
||||
@MethodSource("data_japanseseEras")
|
||||
public void test_Japanese_Eras(Era era, int eraValue, String name) {
|
||||
assertEquals(era.getValue(), eraValue, "EraValue");
|
||||
assertEquals(era.toString(), name, "Era Name");
|
||||
assertEquals(era, JapaneseChronology.INSTANCE.eraOf(eraValue), "JapaneseChronology.eraOf()");
|
||||
assertEquals(eraValue, era.getValue(), "EraValue");
|
||||
assertEquals(name, era.toString(), "Era Name");
|
||||
assertEquals(JapaneseChronology.INSTANCE.eraOf(eraValue), era, "JapaneseChronology.eraOf()");
|
||||
List<Era> eras = JapaneseChronology.INSTANCE.eras();
|
||||
assertTrue(eras.contains(era), "Era is not present in JapaneseChronology.INSTANCE.eras()");
|
||||
}
|
||||
@ -579,27 +594,28 @@ public class TCKJapaneseChronology {
|
||||
}
|
||||
}
|
||||
|
||||
@Test(dataProvider="japaneseEras")
|
||||
@ParameterizedTest
|
||||
@MethodSource("data_japanseseEras")
|
||||
public void test_JapaneseEra_singletons(Era expectedEra, int eraValue, String name) {
|
||||
JapaneseEra actualEra = JapaneseEra.valueOf(name);
|
||||
assertEquals(actualEra, expectedEra, "JapaneseEra.valueOf(name)");
|
||||
assertEquals(expectedEra, actualEra, "JapaneseEra.valueOf(name)");
|
||||
|
||||
actualEra = JapaneseEra.of(eraValue);
|
||||
assertEquals(actualEra, expectedEra, "JapaneseEra.of(value)");
|
||||
assertEquals(expectedEra, actualEra, "JapaneseEra.of(value)");
|
||||
|
||||
String string = actualEra.toString();
|
||||
assertEquals(string, name, "JapaneseEra.toString()");
|
||||
assertEquals(name, string, "JapaneseEra.toString()");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test_JapaneseEra_values() {
|
||||
JapaneseEra[] actualEras = JapaneseEra.values();
|
||||
Object[][] erasInfo = data_japanseseEras();
|
||||
assertEquals(actualEras.length, erasInfo.length, "Wrong number of Eras");
|
||||
assertEquals(erasInfo.length, actualEras.length, "Wrong number of Eras");
|
||||
|
||||
for (int i = 0; i < erasInfo.length; i++) {
|
||||
Object[] eraInfo = erasInfo[i];
|
||||
assertEquals(actualEras[i], eraInfo[0], "Singleton mismatch");
|
||||
assertEquals(eraInfo[0], actualEras[i], "Singleton mismatch");
|
||||
}
|
||||
}
|
||||
|
||||
@ -607,11 +623,11 @@ public class TCKJapaneseChronology {
|
||||
public void test_JapaneseChronology_eras() {
|
||||
List<Era> actualEras = JapaneseChronology.INSTANCE.eras();
|
||||
Object[][] erasInfo = data_japanseseEras();
|
||||
assertEquals(actualEras.size(), erasInfo.length, "Wrong number of Eras");
|
||||
assertEquals(erasInfo.length, actualEras.size(), "Wrong number of Eras");
|
||||
|
||||
for (int i = 0; i < erasInfo.length; i++) {
|
||||
Object[] eraInfo = erasInfo[i];
|
||||
assertEquals(actualEras.get(i), eraInfo[0], "Singleton mismatch");
|
||||
assertEquals(eraInfo[0], actualEras.get(i), "Singleton mismatch");
|
||||
}
|
||||
}
|
||||
|
||||
@ -623,7 +639,7 @@ public class TCKJapaneseChronology {
|
||||
JapaneseDate mdate1 = JapaneseDate.of(1970, 1, 1);
|
||||
JapaneseDate mdate2 = JapaneseDate.of(1971, 2, 2);
|
||||
ChronoPeriod period = mdate1.until(mdate2);
|
||||
assertEquals(period, JapaneseChronology.INSTANCE.period(1, 1, 1));
|
||||
assertEquals(JapaneseChronology.INSTANCE.period(1, 1, 1), period);
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -631,7 +647,7 @@ public class TCKJapaneseChronology {
|
||||
JapaneseDate mdate1 = JapaneseDate.of(1970, 1, 1);
|
||||
JapaneseDate mdate2 = JapaneseDate.of(1971, 2, 2);
|
||||
long months = mdate1.until(mdate2, ChronoUnit.MONTHS);
|
||||
assertEquals(months, 13);
|
||||
assertEquals(13, months);
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -640,7 +656,7 @@ public class TCKJapaneseChronology {
|
||||
JapaneseDate mdate2 = JapaneseDate.of(1971, 2, 2);
|
||||
MinguoDate ldate2 = MinguoChronology.INSTANCE.date(mdate2);
|
||||
ChronoPeriod period = mdate1.until(ldate2);
|
||||
assertEquals(period, JapaneseChronology.INSTANCE.period(1, 1, 1));
|
||||
assertEquals(JapaneseChronology.INSTANCE.period(1, 1, 1), period);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
@ -653,12 +669,12 @@ public class TCKJapaneseChronology {
|
||||
int firstYear = (era == JapaneseEra.MEIJI) ? 6 : 1; // Until Era supports range(YEAR_OF_ERA)
|
||||
JapaneseDate hd1 = JapaneseChronology.INSTANCE.dateYearDay(era, firstYear, 1);
|
||||
ValueRange range = hd1.range(DAY_OF_YEAR);
|
||||
assertEquals(range.getMaximum(), hd1.lengthOfYear(), "lengthOfYear should match range.getMaximum()");
|
||||
assertEquals(hd1.lengthOfYear(), range.getMaximum(), "lengthOfYear should match range.getMaximum()");
|
||||
|
||||
for (int i = 1; i <= hd1.lengthOfYear(); i++) {
|
||||
JapaneseDate hd = JapaneseChronology.INSTANCE.dateYearDay(era, firstYear, i);
|
||||
int doy = hd.get(DAY_OF_YEAR);
|
||||
assertEquals(doy, i, "get(DAY_OF_YEAR) incorrect for " + i + ", of date: " + hd);
|
||||
assertEquals(i, doy, "get(DAY_OF_YEAR) incorrect for " + i + ", of date: " + hd);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -669,14 +685,13 @@ public class TCKJapaneseChronology {
|
||||
for (int i = 1; i <= hd.lengthOfYear(); i++) {
|
||||
JapaneseDate hd2 = hd.with(DAY_OF_YEAR, i);
|
||||
int doy = hd2.get(DAY_OF_YEAR);
|
||||
assertEquals(doy, i, "with(DAY_OF_YEAR) incorrect for " + i + " " + hd2);
|
||||
assertEquals(i, doy, "with(DAY_OF_YEAR) incorrect for " + i + " " + hd2);
|
||||
}
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
// toString()
|
||||
//-----------------------------------------------------------------------
|
||||
@DataProvider(name="toString")
|
||||
Object[][] data_toString() {
|
||||
return new Object[][] {
|
||||
{JapaneseChronology.INSTANCE.date(1873, 12, 5), "Japanese Meiji 6-12-05"},
|
||||
@ -693,9 +708,10 @@ public class TCKJapaneseChronology {
|
||||
};
|
||||
}
|
||||
|
||||
@Test(dataProvider="toString")
|
||||
@ParameterizedTest
|
||||
@MethodSource("data_toString")
|
||||
public void test_toString(JapaneseDate jdate, String expected) {
|
||||
assertEquals(jdate.toString(), expected);
|
||||
assertEquals(expected, jdate.toString());
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
@ -713,7 +729,6 @@ public class TCKJapaneseChronology {
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------
|
||||
@DataProvider(name = "resolve_styleByEra")
|
||||
Object[][] data_resolve_styleByEra() {
|
||||
Object[][] result = new Object[ResolverStyle.values().length * JapaneseEra.values().length][];
|
||||
int i = 0;
|
||||
@ -725,41 +740,43 @@ public class TCKJapaneseChronology {
|
||||
return result;
|
||||
}
|
||||
|
||||
@Test(dataProvider = "resolve_styleByEra")
|
||||
@ParameterizedTest
|
||||
@MethodSource("data_resolve_styleByEra")
|
||||
public void test_resolve_yearOfEra_eraOnly_valid(ResolverStyle style, JapaneseEra era) {
|
||||
Map<TemporalField, Long> fieldValues = new HashMap<>();
|
||||
fieldValues.put(ChronoField.ERA, (long) era.getValue());
|
||||
JapaneseDate date = JapaneseChronology.INSTANCE.resolveDate(fieldValues, style);
|
||||
assertEquals(date, null);
|
||||
assertEquals(fieldValues.get(ChronoField.ERA), (Long) (long) era.getValue());
|
||||
assertEquals(fieldValues.size(), 1);
|
||||
assertEquals(null, date);
|
||||
assertEquals((Long) (long) era.getValue(), fieldValues.get(ChronoField.ERA));
|
||||
assertEquals(1, fieldValues.size());
|
||||
}
|
||||
|
||||
@Test(dataProvider = "resolve_styleByEra")
|
||||
@ParameterizedTest
|
||||
@MethodSource("data_resolve_styleByEra")
|
||||
public void test_resolve_yearOfEra_eraAndYearOfEraOnly_valid(ResolverStyle style, JapaneseEra era) {
|
||||
Map<TemporalField, Long> fieldValues = new HashMap<>();
|
||||
fieldValues.put(ChronoField.ERA, (long) era.getValue());
|
||||
fieldValues.put(ChronoField.YEAR_OF_ERA, 1L);
|
||||
JapaneseDate date = JapaneseChronology.INSTANCE.resolveDate(fieldValues, style);
|
||||
assertEquals(date, null);
|
||||
assertEquals(fieldValues.get(ChronoField.ERA), (Long) (long) era.getValue());
|
||||
assertEquals(fieldValues.get(ChronoField.YEAR_OF_ERA), (Long) 1L);
|
||||
assertEquals(fieldValues.size(), 2);
|
||||
assertEquals(null, date);
|
||||
assertEquals((Long) (long) era.getValue(), fieldValues.get(ChronoField.ERA));
|
||||
assertEquals((Long) 1L, fieldValues.get(ChronoField.YEAR_OF_ERA));
|
||||
assertEquals(2, fieldValues.size());
|
||||
}
|
||||
|
||||
@Test(dataProvider = "resolve_styleByEra")
|
||||
@ParameterizedTest
|
||||
@MethodSource("data_resolve_styleByEra")
|
||||
public void test_resolve_yearOfEra_eraAndYearOnly_valid(ResolverStyle style, JapaneseEra era) {
|
||||
Map<TemporalField, Long> fieldValues = new HashMap<>();
|
||||
fieldValues.put(ChronoField.ERA, (long) era.getValue());
|
||||
fieldValues.put(ChronoField.YEAR, 1L);
|
||||
JapaneseDate date = JapaneseChronology.INSTANCE.resolveDate(fieldValues, style);
|
||||
assertEquals(date, null);
|
||||
assertEquals(fieldValues.get(ChronoField.ERA), (Long) (long) era.getValue());
|
||||
assertEquals(fieldValues.get(ChronoField.YEAR), (Long) 1L);
|
||||
assertEquals(fieldValues.size(), 2);
|
||||
assertEquals(null, date);
|
||||
assertEquals((Long) (long) era.getValue(), fieldValues.get(ChronoField.ERA));
|
||||
assertEquals((Long) 1L, fieldValues.get(ChronoField.YEAR));
|
||||
assertEquals(2, fieldValues.size());
|
||||
}
|
||||
|
||||
@DataProvider(name = "resolve_styles")
|
||||
Object[][] data_resolve_styles() {
|
||||
Object[][] result = new Object[ResolverStyle.values().length][];
|
||||
int i = 0;
|
||||
@ -769,28 +786,31 @@ public class TCKJapaneseChronology {
|
||||
return result;
|
||||
}
|
||||
|
||||
@Test(dataProvider = "resolve_styles")
|
||||
@ParameterizedTest
|
||||
@MethodSource("data_resolve_styles")
|
||||
public void test_resolve_yearOfEra_yearOfEraOnly_valid(ResolverStyle style) {
|
||||
Map<TemporalField, Long> fieldValues = new HashMap<>();
|
||||
fieldValues.put(ChronoField.YEAR_OF_ERA, 1L);
|
||||
JapaneseDate date = JapaneseChronology.INSTANCE.resolveDate(fieldValues, style);
|
||||
assertEquals(date, null);
|
||||
assertEquals(fieldValues.get(ChronoField.YEAR_OF_ERA), (Long) 1L);
|
||||
assertEquals(fieldValues.size(), 1);
|
||||
assertEquals(null, date);
|
||||
assertEquals((Long) 1L, fieldValues.get(ChronoField.YEAR_OF_ERA));
|
||||
assertEquals(1, fieldValues.size());
|
||||
}
|
||||
|
||||
@Test(dataProvider = "resolve_styles")
|
||||
@ParameterizedTest
|
||||
@MethodSource("data_resolve_styles")
|
||||
public void test_resolve_yearOfEra_yearOfEraAndYearOnly_valid(ResolverStyle style) {
|
||||
Map<TemporalField, Long> fieldValues = new HashMap<>();
|
||||
fieldValues.put(ChronoField.YEAR_OF_ERA, 1L);
|
||||
fieldValues.put(ChronoField.YEAR, 2012L);
|
||||
JapaneseDate date = JapaneseChronology.INSTANCE.resolveDate(fieldValues, style);
|
||||
assertEquals(date, null);
|
||||
assertEquals(fieldValues.get(ChronoField.YEAR_OF_ERA), (Long) 1L);
|
||||
assertEquals(fieldValues.get(ChronoField.YEAR), (Long) 2012L);
|
||||
assertEquals(fieldValues.size(), 2);
|
||||
assertEquals(null, date);
|
||||
assertEquals((Long) 1L, fieldValues.get(ChronoField.YEAR_OF_ERA));
|
||||
assertEquals((Long) 2012L, fieldValues.get(ChronoField.YEAR));
|
||||
assertEquals(2, fieldValues.size());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test_resolve_yearOfEra_eraOnly_invalidTooSmall() {
|
||||
for (ResolverStyle style : ResolverStyle.values()) {
|
||||
Map<TemporalField, Long> fieldValues = new HashMap<>();
|
||||
@ -804,6 +824,7 @@ public class TCKJapaneseChronology {
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test_resolve_yearOfEra_eraOnly_invalidTooLarge() {
|
||||
for (ResolverStyle style : ResolverStyle.values()) {
|
||||
Map<TemporalField, Long> fieldValues = new HashMap<>();
|
||||
@ -819,7 +840,6 @@ public class TCKJapaneseChronology {
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------
|
||||
@DataProvider(name = "resolve_ymd")
|
||||
Object[][] data_resolve_ymd() {
|
||||
return new Object[][] {
|
||||
{2012, 1, -365, date(2010, 12, 31), false, false},
|
||||
@ -873,18 +893,20 @@ public class TCKJapaneseChronology {
|
||||
};
|
||||
}
|
||||
|
||||
@Test(dataProvider = "resolve_ymd")
|
||||
@ParameterizedTest
|
||||
@MethodSource("data_resolve_ymd")
|
||||
public void test_resolve_ymd_lenient(int y, int m, int d, JapaneseDate expected, Object smart, boolean strict) {
|
||||
Map<TemporalField, Long> fieldValues = new HashMap<>();
|
||||
fieldValues.put(ChronoField.YEAR, (long) y);
|
||||
fieldValues.put(ChronoField.MONTH_OF_YEAR, (long) m);
|
||||
fieldValues.put(ChronoField.DAY_OF_MONTH, (long) d);
|
||||
JapaneseDate date = JapaneseChronology.INSTANCE.resolveDate(fieldValues, ResolverStyle.LENIENT);
|
||||
assertEquals(date, expected);
|
||||
assertEquals(fieldValues.size(), 0);
|
||||
assertEquals(expected, date);
|
||||
assertEquals(0, fieldValues.size());
|
||||
}
|
||||
|
||||
@Test(dataProvider = "resolve_ymd")
|
||||
@ParameterizedTest
|
||||
@MethodSource("data_resolve_ymd")
|
||||
public void test_resolve_ymd_smart(int y, int m, int d, JapaneseDate expected, Object smart, boolean strict) {
|
||||
Map<TemporalField, Long> fieldValues = new HashMap<>();
|
||||
fieldValues.put(ChronoField.YEAR, (long) y);
|
||||
@ -892,11 +914,11 @@ public class TCKJapaneseChronology {
|
||||
fieldValues.put(ChronoField.DAY_OF_MONTH, (long) d);
|
||||
if (Boolean.TRUE.equals(smart)) {
|
||||
JapaneseDate date = JapaneseChronology.INSTANCE.resolveDate(fieldValues, ResolverStyle.SMART);
|
||||
assertEquals(date, expected);
|
||||
assertEquals(fieldValues.size(), 0);
|
||||
assertEquals(expected, date);
|
||||
assertEquals(0, fieldValues.size());
|
||||
} else if (smart instanceof JapaneseDate) {
|
||||
JapaneseDate date = JapaneseChronology.INSTANCE.resolveDate(fieldValues, ResolverStyle.SMART);
|
||||
assertEquals(date, smart);
|
||||
assertEquals(smart, date);
|
||||
} else {
|
||||
try {
|
||||
JapaneseChronology.INSTANCE.resolveDate(fieldValues, ResolverStyle.SMART);
|
||||
@ -907,7 +929,8 @@ public class TCKJapaneseChronology {
|
||||
}
|
||||
}
|
||||
|
||||
@Test(dataProvider = "resolve_ymd")
|
||||
@ParameterizedTest
|
||||
@MethodSource("data_resolve_ymd")
|
||||
public void test_resolve_ymd_strict(int y, int m, int d, JapaneseDate expected, Object smart, boolean strict) {
|
||||
Map<TemporalField, Long> fieldValues = new HashMap<>();
|
||||
fieldValues.put(ChronoField.YEAR, (long) y);
|
||||
@ -915,8 +938,8 @@ public class TCKJapaneseChronology {
|
||||
fieldValues.put(ChronoField.DAY_OF_MONTH, (long) d);
|
||||
if (strict) {
|
||||
JapaneseDate date = JapaneseChronology.INSTANCE.resolveDate(fieldValues, ResolverStyle.STRICT);
|
||||
assertEquals(date, expected);
|
||||
assertEquals(fieldValues.size(), 0);
|
||||
assertEquals(expected, date);
|
||||
assertEquals(0, fieldValues.size());
|
||||
} else {
|
||||
try {
|
||||
JapaneseChronology.INSTANCE.resolveDate(fieldValues, ResolverStyle.STRICT);
|
||||
@ -929,7 +952,6 @@ public class TCKJapaneseChronology {
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------
|
||||
@DataProvider(name = "resolve_yd")
|
||||
Object[][] data_resolve_yd() {
|
||||
return new Object[][] {
|
||||
{2012, -365, date(2010, 12, 31), false, false},
|
||||
@ -957,25 +979,27 @@ public class TCKJapaneseChronology {
|
||||
};
|
||||
}
|
||||
|
||||
@Test(dataProvider = "resolve_yd")
|
||||
@ParameterizedTest
|
||||
@MethodSource("data_resolve_yd")
|
||||
public void test_resolve_yd_lenient(int y, int d, JapaneseDate expected, boolean smart, boolean strict) {
|
||||
Map<TemporalField, Long> fieldValues = new HashMap<>();
|
||||
fieldValues.put(ChronoField.YEAR, (long) y);
|
||||
fieldValues.put(ChronoField.DAY_OF_YEAR, (long) d);
|
||||
JapaneseDate date = JapaneseChronology.INSTANCE.resolveDate(fieldValues, ResolverStyle.LENIENT);
|
||||
assertEquals(date, expected);
|
||||
assertEquals(fieldValues.size(), 0);
|
||||
assertEquals(expected, date);
|
||||
assertEquals(0, fieldValues.size());
|
||||
}
|
||||
|
||||
@Test(dataProvider = "resolve_yd")
|
||||
@ParameterizedTest
|
||||
@MethodSource("data_resolve_yd")
|
||||
public void test_resolve_yd_smart(int y, int d, JapaneseDate expected, boolean smart, boolean strict) {
|
||||
Map<TemporalField, Long> fieldValues = new HashMap<>();
|
||||
fieldValues.put(ChronoField.YEAR, (long) y);
|
||||
fieldValues.put(ChronoField.DAY_OF_YEAR, (long) d);
|
||||
if (smart) {
|
||||
JapaneseDate date = JapaneseChronology.INSTANCE.resolveDate(fieldValues, ResolverStyle.SMART);
|
||||
assertEquals(date, expected);
|
||||
assertEquals(fieldValues.size(), 0);
|
||||
assertEquals(expected, date);
|
||||
assertEquals(0, fieldValues.size());
|
||||
} else {
|
||||
try {
|
||||
JapaneseChronology.INSTANCE.resolveDate(fieldValues, ResolverStyle.SMART);
|
||||
@ -986,15 +1010,16 @@ public class TCKJapaneseChronology {
|
||||
}
|
||||
}
|
||||
|
||||
@Test(dataProvider = "resolve_yd")
|
||||
@ParameterizedTest
|
||||
@MethodSource("data_resolve_yd")
|
||||
public void test_resolve_yd_strict(int y, int d, JapaneseDate expected, boolean smart, boolean strict) {
|
||||
Map<TemporalField, Long> fieldValues = new HashMap<>();
|
||||
fieldValues.put(ChronoField.YEAR, (long) y);
|
||||
fieldValues.put(ChronoField.DAY_OF_YEAR, (long) d);
|
||||
if (strict) {
|
||||
JapaneseDate date = JapaneseChronology.INSTANCE.resolveDate(fieldValues, ResolverStyle.STRICT);
|
||||
assertEquals(date, expected);
|
||||
assertEquals(fieldValues.size(), 0);
|
||||
assertEquals(expected, date);
|
||||
assertEquals(0, fieldValues.size());
|
||||
} else {
|
||||
try {
|
||||
JapaneseChronology.INSTANCE.resolveDate(fieldValues, ResolverStyle.STRICT);
|
||||
@ -1007,7 +1032,6 @@ public class TCKJapaneseChronology {
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------
|
||||
@DataProvider(name = "resolve_eymd")
|
||||
Object[][] data_resolve_eymd() {
|
||||
return new Object[][] {
|
||||
// lenient
|
||||
@ -1157,7 +1181,8 @@ public class TCKJapaneseChronology {
|
||||
};
|
||||
}
|
||||
|
||||
@Test(dataProvider = "resolve_eymd")
|
||||
@ParameterizedTest
|
||||
@MethodSource("data_resolve_eymd")
|
||||
public void test_resolve_eymd(ResolverStyle style, JapaneseEra era, int yoe, int m, int d, JapaneseDate expected) {
|
||||
Map<TemporalField, Long> fieldValues = new HashMap<>();
|
||||
fieldValues.put(ChronoField.ERA, (long) era.getValue());
|
||||
@ -1166,8 +1191,8 @@ public class TCKJapaneseChronology {
|
||||
fieldValues.put(ChronoField.DAY_OF_MONTH, (long) d);
|
||||
if (expected != null) {
|
||||
JapaneseDate date = JapaneseChronology.INSTANCE.resolveDate(fieldValues, style);
|
||||
assertEquals(date, expected);
|
||||
assertEquals(fieldValues.size(), 0);
|
||||
assertEquals(expected, date);
|
||||
assertEquals(0, fieldValues.size());
|
||||
} else {
|
||||
try {
|
||||
JapaneseChronology.INSTANCE.resolveDate(fieldValues, style);
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2012, 2019, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2012, 2025, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
@ -54,27 +54,30 @@
|
||||
*/
|
||||
package tck.java.time.chrono;
|
||||
|
||||
import java.time.DateTimeException;
|
||||
import static java.time.temporal.ChronoField.ERA;
|
||||
import static org.testng.Assert.assertEquals;
|
||||
import static org.testng.Assert.assertTrue;
|
||||
import static org.testng.Assert.fail;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
import java.time.chrono.Era;
|
||||
import java.time.chrono.JapaneseChronology;
|
||||
import java.time.chrono.JapaneseEra;
|
||||
import java.util.List;
|
||||
|
||||
import org.testng.annotations.DataProvider;
|
||||
import org.testng.annotations.Test;
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.TestInstance;
|
||||
import org.junit.jupiter.params.ParameterizedTest;
|
||||
import org.junit.jupiter.params.provider.MethodSource;
|
||||
|
||||
/**
|
||||
* Tests for JapaneseEra
|
||||
* @bug 8068278
|
||||
*/
|
||||
@Test
|
||||
@TestInstance(TestInstance.Lifecycle.PER_CLASS)
|
||||
public class TCKJapaneseEra {
|
||||
|
||||
@DataProvider(name = "JapaneseEras")
|
||||
Object[][] data_of_eras() {
|
||||
return new Object[][] {
|
||||
{JapaneseEra.REIWA, "Reiwa", 3},
|
||||
@ -85,7 +88,6 @@ public class TCKJapaneseEra {
|
||||
};
|
||||
}
|
||||
|
||||
@DataProvider(name = "InvalidJapaneseEras")
|
||||
Object[][] data_of_invalid_eras() {
|
||||
return new Object[][] {
|
||||
{-2},
|
||||
@ -99,11 +101,12 @@ public class TCKJapaneseEra {
|
||||
//-----------------------------------------------------------------------
|
||||
// JapaneseEra value test
|
||||
//-----------------------------------------------------------------------
|
||||
@Test(dataProvider="JapaneseEras")
|
||||
@ParameterizedTest
|
||||
@MethodSource("data_of_eras")
|
||||
public void test_valueOf(JapaneseEra era , String eraName, int eraValue) {
|
||||
assertEquals(era.getValue(), eraValue);
|
||||
assertEquals(JapaneseEra.of(eraValue), era);
|
||||
assertEquals(JapaneseEra.valueOf(eraName), era);
|
||||
assertEquals(eraValue, era.getValue());
|
||||
assertEquals(era, JapaneseEra.of(eraValue));
|
||||
assertEquals(era, JapaneseEra.valueOf(eraName));
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
@ -113,7 +116,7 @@ public class TCKJapaneseEra {
|
||||
public void test_values() {
|
||||
List<Era> eraList = JapaneseChronology.INSTANCE.eras();
|
||||
JapaneseEra[] eras = JapaneseEra.values();
|
||||
assertEquals(eraList.size(), eras.length);
|
||||
assertEquals(eras.length, eraList.size());
|
||||
for (JapaneseEra era : eras) {
|
||||
assertTrue(eraList.contains(era));
|
||||
}
|
||||
@ -126,18 +129,19 @@ public class TCKJapaneseEra {
|
||||
public void test_range() {
|
||||
// eras may be added after release
|
||||
for (JapaneseEra era : JapaneseEra.values()) {
|
||||
assertEquals(era.range(ERA).getMinimum(), -1);
|
||||
assertEquals(era.range(ERA).getLargestMinimum(), -1);
|
||||
assertEquals(era.range(ERA).getSmallestMaximum(), era.range(ERA).getMaximum());
|
||||
assertEquals(era.range(ERA).getMaximum() >= 2, true);
|
||||
assertEquals(-1, era.range(ERA).getMinimum());
|
||||
assertEquals(-1, era.range(ERA).getLargestMinimum());
|
||||
assertEquals(era.range(ERA).getMaximum(), era.range(ERA).getSmallestMaximum());
|
||||
assertEquals(true, era.range(ERA).getMaximum() >= 2);
|
||||
}
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
// JapaneseChronology.INSTANCE.eraOf invalid era test
|
||||
//-----------------------------------------------------------------------
|
||||
@Test(dataProvider="InvalidJapaneseEras", expectedExceptions=java.time.DateTimeException.class)
|
||||
@ParameterizedTest
|
||||
@MethodSource("data_of_invalid_eras")
|
||||
public void test_outofrange(int era) {
|
||||
JapaneseChronology.INSTANCE.eraOf(era);
|
||||
Assertions.assertThrows(DateTimeException.class, () -> JapaneseChronology.INSTANCE.eraOf(era));
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2012, 2013, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2012, 2025, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
@ -54,11 +54,11 @@
|
||||
*/
|
||||
package tck.java.time.chrono;
|
||||
|
||||
import static org.testng.Assert.assertEquals;
|
||||
import static org.testng.Assert.assertFalse;
|
||||
import static org.testng.Assert.assertNotEquals;
|
||||
import static org.testng.Assert.assertTrue;
|
||||
import static org.testng.Assert.fail;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||
import static org.junit.jupiter.api.Assertions.assertNotEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
import static org.junit.jupiter.api.Assertions.fail;
|
||||
|
||||
import java.time.Clock;
|
||||
import java.time.DateTimeException;
|
||||
@ -94,14 +94,16 @@ import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.testng.Assert;
|
||||
import org.testng.annotations.DataProvider;
|
||||
import org.testng.annotations.Test;
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.TestInstance;
|
||||
import org.junit.jupiter.params.ParameterizedTest;
|
||||
import org.junit.jupiter.params.provider.MethodSource;
|
||||
|
||||
/**
|
||||
* Test.
|
||||
*/
|
||||
@Test
|
||||
@TestInstance(TestInstance.Lifecycle.PER_CLASS)
|
||||
public class TCKMinguoChronology {
|
||||
|
||||
private static final ZoneOffset OFFSET_PTWO = ZoneOffset.ofHours(2);
|
||||
@ -114,16 +116,15 @@ public class TCKMinguoChronology {
|
||||
public void test_chrono_byName() {
|
||||
Chronology c = MinguoChronology.INSTANCE;
|
||||
Chronology test = Chronology.of("Minguo");
|
||||
Assert.assertNotNull(test, "The Minguo calendar could not be found byName");
|
||||
Assert.assertEquals(test.getId(), "Minguo", "ID mismatch");
|
||||
Assert.assertEquals(test.getCalendarType(), "roc", "Type mismatch");
|
||||
Assert.assertEquals(test, c);
|
||||
Assertions.assertNotNull(test, "The Minguo calendar could not be found byName");
|
||||
assertEquals("Minguo", test.getId(), "ID mismatch");
|
||||
assertEquals("roc", test.getCalendarType(), "Type mismatch");
|
||||
assertEquals(c, test);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
// creation, toLocalDate()
|
||||
//-----------------------------------------------------------------------
|
||||
@DataProvider(name="samples")
|
||||
Object[][] data_samples() {
|
||||
return new Object[][] {
|
||||
{MinguoChronology.INSTANCE.date(1, 1, 1), LocalDate.of(1 + YDIFF, 1, 1)},
|
||||
@ -158,50 +159,55 @@ public class TCKMinguoChronology {
|
||||
};
|
||||
}
|
||||
|
||||
@Test(dataProvider="samples")
|
||||
@ParameterizedTest
|
||||
@MethodSource("data_samples")
|
||||
public void test_toLocalDate(MinguoDate minguo, LocalDate iso) {
|
||||
assertEquals(LocalDate.from(minguo), iso);
|
||||
assertEquals(iso, LocalDate.from(minguo));
|
||||
}
|
||||
|
||||
@Test(dataProvider="samples")
|
||||
@ParameterizedTest
|
||||
@MethodSource("data_samples")
|
||||
public void test_fromCalendrical(MinguoDate minguo, LocalDate iso) {
|
||||
assertEquals(MinguoChronology.INSTANCE.date(iso), minguo);
|
||||
assertEquals(MinguoDate.from(iso), minguo);
|
||||
assertEquals(minguo, MinguoChronology.INSTANCE.date(iso));
|
||||
assertEquals(minguo, MinguoDate.from(iso));
|
||||
}
|
||||
|
||||
@Test(dataProvider="samples")
|
||||
@ParameterizedTest
|
||||
@MethodSource("data_samples")
|
||||
public void test_isEqual(MinguoDate minguo, LocalDate iso) {
|
||||
assertTrue(minguo.isEqual(iso));
|
||||
}
|
||||
|
||||
@Test(dataProvider="samples")
|
||||
@ParameterizedTest
|
||||
@MethodSource("data_samples")
|
||||
public void test_date_equals(MinguoDate minguo, LocalDate iso) {
|
||||
assertFalse(minguo.equals(iso));
|
||||
assertNotEquals(minguo.hashCode(), iso.hashCode());
|
||||
assertNotEquals(iso.hashCode(), minguo.hashCode());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test_dateNow(){
|
||||
assertEquals(MinguoChronology.INSTANCE.dateNow(), MinguoDate.now()) ;
|
||||
assertEquals(MinguoChronology.INSTANCE.dateNow(), MinguoDate.now(ZoneId.systemDefault())) ;
|
||||
assertEquals(MinguoChronology.INSTANCE.dateNow(), MinguoDate.now(Clock.systemDefaultZone())) ;
|
||||
assertEquals(MinguoChronology.INSTANCE.dateNow(), MinguoDate.now(Clock.systemDefaultZone().getZone())) ;
|
||||
assertEquals(MinguoDate.now(), MinguoChronology.INSTANCE.dateNow()) ;
|
||||
assertEquals(MinguoDate.now(ZoneId.systemDefault()), MinguoChronology.INSTANCE.dateNow()) ;
|
||||
assertEquals(MinguoDate.now(Clock.systemDefaultZone()), MinguoChronology.INSTANCE.dateNow()) ;
|
||||
assertEquals(MinguoDate.now(Clock.systemDefaultZone().getZone()), MinguoChronology.INSTANCE.dateNow()) ;
|
||||
|
||||
assertEquals(MinguoChronology.INSTANCE.dateNow(), MinguoChronology.INSTANCE.dateNow(ZoneId.systemDefault())) ;
|
||||
assertEquals(MinguoChronology.INSTANCE.dateNow(), MinguoChronology.INSTANCE.dateNow(Clock.systemDefaultZone())) ;
|
||||
assertEquals(MinguoChronology.INSTANCE.dateNow(), MinguoChronology.INSTANCE.dateNow(Clock.systemDefaultZone().getZone())) ;
|
||||
assertEquals(MinguoChronology.INSTANCE.dateNow(ZoneId.systemDefault()), MinguoChronology.INSTANCE.dateNow()) ;
|
||||
assertEquals(MinguoChronology.INSTANCE.dateNow(Clock.systemDefaultZone()), MinguoChronology.INSTANCE.dateNow()) ;
|
||||
assertEquals(MinguoChronology.INSTANCE.dateNow(Clock.systemDefaultZone().getZone()), MinguoChronology.INSTANCE.dateNow()) ;
|
||||
|
||||
ZoneId zoneId = ZoneId.of("Europe/Paris");
|
||||
assertEquals(MinguoChronology.INSTANCE.dateNow(zoneId), MinguoChronology.INSTANCE.dateNow(Clock.system(zoneId))) ;
|
||||
assertEquals(MinguoChronology.INSTANCE.dateNow(zoneId), MinguoChronology.INSTANCE.dateNow(Clock.system(zoneId).getZone())) ;
|
||||
assertEquals(MinguoChronology.INSTANCE.dateNow(zoneId), MinguoDate.now(Clock.system(zoneId))) ;
|
||||
assertEquals(MinguoChronology.INSTANCE.dateNow(zoneId), MinguoDate.now(Clock.system(zoneId).getZone())) ;
|
||||
assertEquals(MinguoChronology.INSTANCE.dateNow(Clock.system(zoneId)), MinguoChronology.INSTANCE.dateNow(zoneId)) ;
|
||||
assertEquals(MinguoChronology.INSTANCE.dateNow(Clock.system(zoneId).getZone()), MinguoChronology.INSTANCE.dateNow(zoneId)) ;
|
||||
assertEquals(MinguoDate.now(Clock.system(zoneId)), MinguoChronology.INSTANCE.dateNow(zoneId)) ;
|
||||
assertEquals(MinguoDate.now(Clock.system(zoneId).getZone()), MinguoChronology.INSTANCE.dateNow(zoneId)) ;
|
||||
|
||||
assertEquals(MinguoChronology.INSTANCE.dateNow(ZoneId.of(ZoneOffset.UTC.getId())), MinguoChronology.INSTANCE.dateNow(Clock.systemUTC())) ;
|
||||
assertEquals(MinguoChronology.INSTANCE.dateNow(Clock.systemUTC()), MinguoChronology.INSTANCE.dateNow(ZoneId.of(ZoneOffset.UTC.getId()))) ;
|
||||
}
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
@Test(dataProvider="samples")
|
||||
@ParameterizedTest
|
||||
@MethodSource("data_samples")
|
||||
public void test_MinguoDate(MinguoDate minguoDate, LocalDate iso) {
|
||||
MinguoDate hd = minguoDate;
|
||||
ChronoLocalDateTime<MinguoDate> hdt = hd.atTime(LocalTime.NOON);
|
||||
@ -229,7 +235,6 @@ public class TCKMinguoChronology {
|
||||
ChronoZonedDateTime<MinguoDate> h4 = h3.atZone(ZoneOffset.UTC);
|
||||
}
|
||||
|
||||
@DataProvider(name="badDates")
|
||||
Object[][] data_badDates() {
|
||||
return new Object[][] {
|
||||
{1912, 0, 0},
|
||||
@ -256,15 +261,15 @@ public class TCKMinguoChronology {
|
||||
};
|
||||
}
|
||||
|
||||
@Test(dataProvider="badDates", expectedExceptions=DateTimeException.class)
|
||||
@ParameterizedTest
|
||||
@MethodSource("data_badDates")
|
||||
public void test_badDates(int year, int month, int dom) {
|
||||
MinguoChronology.INSTANCE.date(year, month, dom);
|
||||
Assertions.assertThrows(DateTimeException.class, () -> MinguoChronology.INSTANCE.date(year, month, dom));
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
// prolepticYear() and is LeapYear()
|
||||
//-----------------------------------------------------------------------
|
||||
@DataProvider(name="prolepticYear")
|
||||
Object[][] data_prolepticYear() {
|
||||
return new Object[][] {
|
||||
{1, MinguoEra.ROC, 1912 - YDIFF, 1912 - YDIFF, true},
|
||||
@ -290,25 +295,27 @@ public class TCKMinguoChronology {
|
||||
};
|
||||
}
|
||||
|
||||
@Test(dataProvider="prolepticYear")
|
||||
@ParameterizedTest
|
||||
@MethodSource("data_prolepticYear")
|
||||
public void test_prolepticYear(int eraValue, Era era, int yearOfEra, int expectedProlepticYear, boolean isLeapYear) {
|
||||
Era eraObj = MinguoChronology.INSTANCE.eraOf(eraValue);
|
||||
assertTrue(MinguoChronology.INSTANCE.eras().contains(eraObj));
|
||||
assertEquals(eraObj, era);
|
||||
assertEquals(MinguoChronology.INSTANCE.prolepticYear(era, yearOfEra), expectedProlepticYear);
|
||||
assertEquals(era, eraObj);
|
||||
assertEquals(expectedProlepticYear, MinguoChronology.INSTANCE.prolepticYear(era, yearOfEra));
|
||||
}
|
||||
|
||||
@Test(dataProvider="prolepticYear")
|
||||
@ParameterizedTest
|
||||
@MethodSource("data_prolepticYear")
|
||||
public void test_isLeapYear(int eraValue, Era era, int yearOfEra, int expectedProlepticYear, boolean isLeapYear) {
|
||||
assertEquals(MinguoChronology.INSTANCE.isLeapYear(expectedProlepticYear), isLeapYear);
|
||||
assertEquals(MinguoChronology.INSTANCE.isLeapYear(expectedProlepticYear), Year.of(expectedProlepticYear + YDIFF).isLeap());
|
||||
assertEquals(isLeapYear, MinguoChronology.INSTANCE.isLeapYear(expectedProlepticYear));
|
||||
assertEquals(Year.of(expectedProlepticYear + YDIFF).isLeap(), MinguoChronology.INSTANCE.isLeapYear(expectedProlepticYear));
|
||||
|
||||
MinguoDate minguo = MinguoDate.now();
|
||||
minguo = minguo.with(ChronoField.YEAR, expectedProlepticYear).with(ChronoField.MONTH_OF_YEAR, 2);
|
||||
if (isLeapYear) {
|
||||
assertEquals(minguo.lengthOfMonth(), 29);
|
||||
assertEquals(29, minguo.lengthOfMonth());
|
||||
} else {
|
||||
assertEquals(minguo.lengthOfMonth(), 28);
|
||||
assertEquals(28, minguo.lengthOfMonth());
|
||||
}
|
||||
}
|
||||
|
||||
@ -359,14 +366,14 @@ public class TCKMinguoChronology {
|
||||
public void test_adjust1() {
|
||||
MinguoDate base = MinguoChronology.INSTANCE.date(2012, 10, 29);
|
||||
MinguoDate test = base.with(TemporalAdjusters.lastDayOfMonth());
|
||||
assertEquals(test, MinguoChronology.INSTANCE.date(2012, 10, 31));
|
||||
assertEquals(MinguoChronology.INSTANCE.date(2012, 10, 31), test);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test_adjust2() {
|
||||
MinguoDate base = MinguoChronology.INSTANCE.date(1728, 12, 2);
|
||||
MinguoDate test = base.with(TemporalAdjusters.lastDayOfMonth());
|
||||
assertEquals(test, MinguoChronology.INSTANCE.date(1728, 12, 31));
|
||||
assertEquals(MinguoChronology.INSTANCE.date(1728, 12, 31), test);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
@ -376,13 +383,15 @@ public class TCKMinguoChronology {
|
||||
public void test_adjust_toLocalDate() {
|
||||
MinguoDate minguo = MinguoChronology.INSTANCE.date(99, 1, 4);
|
||||
MinguoDate test = minguo.with(LocalDate.of(2012, 7, 6));
|
||||
assertEquals(test, MinguoChronology.INSTANCE.date(101, 7, 6));
|
||||
assertEquals(MinguoChronology.INSTANCE.date(101, 7, 6), test);
|
||||
}
|
||||
|
||||
@Test(expectedExceptions=DateTimeException.class)
|
||||
@Test
|
||||
public void test_adjust_toMonth() {
|
||||
MinguoDate minguo = MinguoChronology.INSTANCE.date(1726, 1, 4);
|
||||
minguo.with(Month.APRIL);
|
||||
Assertions.assertThrows(DateTimeException.class, () -> {
|
||||
MinguoDate minguo = MinguoChronology.INSTANCE.date(1726, 1, 4);
|
||||
minguo.with(Month.APRIL);
|
||||
});
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
@ -392,20 +401,19 @@ public class TCKMinguoChronology {
|
||||
public void test_LocalDate_adjustToMinguoDate() {
|
||||
MinguoDate minguo = MinguoChronology.INSTANCE.date(101, 10, 29);
|
||||
LocalDate test = LocalDate.MIN.with(minguo);
|
||||
assertEquals(test, LocalDate.of(2012, 10, 29));
|
||||
assertEquals(LocalDate.of(2012, 10, 29), test);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test_LocalDateTime_adjustToMinguoDate() {
|
||||
MinguoDate minguo = MinguoChronology.INSTANCE.date(101, 10, 29);
|
||||
LocalDateTime test = LocalDateTime.MIN.with(minguo);
|
||||
assertEquals(test, LocalDateTime.of(2012, 10, 29, 0, 0));
|
||||
assertEquals(LocalDateTime.of(2012, 10, 29, 0, 0), test);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
// localDateTime()
|
||||
//-----------------------------------------------------------------------
|
||||
@DataProvider(name="localDateTime")
|
||||
Object[][] data_localDateTime() {
|
||||
return new Object[][] {
|
||||
{LocalDateTime.of(2012, 2, 29, 2, 7), MinguoChronology.INSTANCE.date(MinguoEra.ROC, 2012 - YDIFF, 2, 29), LocalTime.of(2, 7), null},
|
||||
@ -419,13 +427,14 @@ public class TCKMinguoChronology {
|
||||
};
|
||||
}
|
||||
|
||||
@Test(dataProvider="localDateTime")
|
||||
@ParameterizedTest
|
||||
@MethodSource("data_localDateTime")
|
||||
public void test_localDateTime(TemporalAccessor accessor, MinguoDate expectedDate, LocalTime expectedTime, Class<?> expectedEx) {
|
||||
if (expectedEx == null) {
|
||||
ChronoLocalDateTime<MinguoDate> result = MinguoChronology.INSTANCE.localDateTime(accessor);
|
||||
assertEquals(result.toLocalDate(), expectedDate);
|
||||
assertEquals(MinguoDate.from(accessor), expectedDate);
|
||||
assertEquals(result.toLocalTime(), expectedTime);
|
||||
assertEquals(expectedDate, result.toLocalDate());
|
||||
assertEquals(expectedDate, MinguoDate.from(accessor));
|
||||
assertEquals(expectedTime, result.toLocalTime());
|
||||
} else {
|
||||
try {
|
||||
ChronoLocalDateTime<MinguoDate> result = MinguoChronology.INSTANCE.localDateTime(accessor);
|
||||
@ -439,7 +448,6 @@ public class TCKMinguoChronology {
|
||||
//-----------------------------------------------------------------------
|
||||
// zonedDateTime(TemporalAccessor)
|
||||
//-----------------------------------------------------------------------
|
||||
@DataProvider(name="zonedDateTime")
|
||||
Object[][] data_zonedDateTime() {
|
||||
return new Object[][] {
|
||||
{ZonedDateTime.of(2012, 2, 29, 2, 7, 1, 1, ZONE_PARIS), MinguoChronology.INSTANCE.date(MinguoEra.ROC, 2012 - YDIFF, 2, 29), LocalTime.of(2, 7, 1, 1), null},
|
||||
@ -453,13 +461,14 @@ public class TCKMinguoChronology {
|
||||
};
|
||||
}
|
||||
|
||||
@Test(dataProvider="zonedDateTime")
|
||||
@ParameterizedTest
|
||||
@MethodSource("data_zonedDateTime")
|
||||
public void test_zonedDateTime(TemporalAccessor accessor, MinguoDate expectedDate, LocalTime expectedTime, Class<?> expectedEx) {
|
||||
if (expectedEx == null) {
|
||||
ChronoZonedDateTime<MinguoDate> result = MinguoChronology.INSTANCE.zonedDateTime(accessor);
|
||||
assertEquals(result.toLocalDate(), expectedDate);
|
||||
assertEquals(MinguoDate.from(accessor), expectedDate);
|
||||
assertEquals(result.toLocalTime(), expectedTime);
|
||||
assertEquals(expectedDate, result.toLocalDate());
|
||||
assertEquals(expectedDate, MinguoDate.from(accessor));
|
||||
assertEquals(expectedTime, result.toLocalTime());
|
||||
|
||||
} else {
|
||||
try {
|
||||
@ -480,12 +489,12 @@ public class TCKMinguoChronology {
|
||||
ZonedDateTime zonedDateTime = ZonedDateTime.of(2012, 2, 29, 2, 7, 1, 1, ZONE_PARIS);
|
||||
|
||||
ChronoZonedDateTime<MinguoDate> result = MinguoChronology.INSTANCE.zonedDateTime(offsetDateTime.toInstant(), offsetDateTime.getOffset());
|
||||
assertEquals(result.toLocalDate(), MinguoChronology.INSTANCE.date(MinguoEra.ROC, 2012 - YDIFF, 2, 29));
|
||||
assertEquals(result.toLocalTime(), LocalTime.of(2, 7, 1, 1));
|
||||
assertEquals(MinguoChronology.INSTANCE.date(MinguoEra.ROC, 2012 - YDIFF, 2, 29), result.toLocalDate());
|
||||
assertEquals(LocalTime.of(2, 7, 1, 1), result.toLocalTime());
|
||||
|
||||
result = MinguoChronology.INSTANCE.zonedDateTime(zonedDateTime.toInstant(), zonedDateTime.getOffset());
|
||||
assertEquals(result.toLocalDate(), MinguoChronology.INSTANCE.date(MinguoEra.ROC, 2012 - YDIFF, 2, 29));
|
||||
assertEquals(result.toLocalTime(), LocalTime.of(2, 7, 1, 1));
|
||||
assertEquals(MinguoChronology.INSTANCE.date(MinguoEra.ROC, 2012 - YDIFF, 2, 29), result.toLocalDate());
|
||||
assertEquals(LocalTime.of(2, 7, 1, 1), result.toLocalTime());
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
@ -496,7 +505,7 @@ public class TCKMinguoChronology {
|
||||
MinguoDate mdate1 = MinguoDate.of(1970, 1, 1);
|
||||
MinguoDate mdate2 = MinguoDate.of(1971, 2, 2);
|
||||
ChronoPeriod period = mdate1.until(mdate2);
|
||||
assertEquals(period, MinguoChronology.INSTANCE.period(1, 1, 1));
|
||||
assertEquals(MinguoChronology.INSTANCE.period(1, 1, 1), period);
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -504,7 +513,7 @@ public class TCKMinguoChronology {
|
||||
MinguoDate mdate1 = MinguoDate.of(1970, 1, 1);
|
||||
MinguoDate mdate2 = MinguoDate.of(1971, 2, 2);
|
||||
long months = mdate1.until(mdate2, ChronoUnit.MONTHS);
|
||||
assertEquals(months, 13);
|
||||
assertEquals(13, months);
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -513,13 +522,12 @@ public class TCKMinguoChronology {
|
||||
MinguoDate mdate2 = MinguoDate.of(1971, 2, 2);
|
||||
ThaiBuddhistDate ldate2 = ThaiBuddhistChronology.INSTANCE.date(mdate2);
|
||||
ChronoPeriod period = mdate1.until(ldate2);
|
||||
assertEquals(period, MinguoChronology.INSTANCE.period(1, 1, 1));
|
||||
assertEquals(MinguoChronology.INSTANCE.period(1, 1, 1), period);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
// toString()
|
||||
//-----------------------------------------------------------------------
|
||||
@DataProvider(name="toString")
|
||||
Object[][] data_toString() {
|
||||
return new Object[][] {
|
||||
{MinguoChronology.INSTANCE.date(1, 1, 1), "Minguo ROC 1-01-01"},
|
||||
@ -530,9 +538,10 @@ public class TCKMinguoChronology {
|
||||
};
|
||||
}
|
||||
|
||||
@Test(dataProvider="toString")
|
||||
@ParameterizedTest
|
||||
@MethodSource("data_toString")
|
||||
public void test_toString(MinguoDate minguo, String expected) {
|
||||
assertEquals(minguo.toString(), expected);
|
||||
assertEquals(expected, minguo.toString());
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
@ -550,7 +559,6 @@ public class TCKMinguoChronology {
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------
|
||||
@DataProvider(name = "resolve_yearOfEra")
|
||||
Object[][] data_resolve_yearOfEra() {
|
||||
return new Object[][] {
|
||||
// era only
|
||||
@ -615,7 +623,8 @@ public class TCKMinguoChronology {
|
||||
};
|
||||
}
|
||||
|
||||
@Test(dataProvider = "resolve_yearOfEra")
|
||||
@ParameterizedTest
|
||||
@MethodSource("data_resolve_yearOfEra")
|
||||
public void test_resolve_yearOfEra(ResolverStyle style, Integer e, Integer yoe, Integer y, ChronoField field, Integer expected) {
|
||||
Map<TemporalField, Long> fieldValues = new HashMap<>();
|
||||
if (e != null) {
|
||||
@ -629,9 +638,9 @@ public class TCKMinguoChronology {
|
||||
}
|
||||
if (field != null) {
|
||||
MinguoDate date = MinguoChronology.INSTANCE.resolveDate(fieldValues, style);
|
||||
assertEquals(date, null);
|
||||
assertEquals(fieldValues.get(field), (Long) expected.longValue());
|
||||
assertEquals(fieldValues.size(), 1);
|
||||
assertEquals(null, date);
|
||||
assertEquals((Long) expected.longValue(), fieldValues.get(field));
|
||||
assertEquals(1, fieldValues.size());
|
||||
} else {
|
||||
try {
|
||||
MinguoChronology.INSTANCE.resolveDate(fieldValues, style);
|
||||
@ -644,7 +653,6 @@ public class TCKMinguoChronology {
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------
|
||||
@DataProvider(name = "resolve_ymd")
|
||||
Object[][] data_resolve_ymd() {
|
||||
return new Object[][] {
|
||||
{2012 - YDIFF, 1, -365, date(2010 - YDIFF, 12, 31), false, false},
|
||||
@ -703,18 +711,20 @@ public class TCKMinguoChronology {
|
||||
};
|
||||
}
|
||||
|
||||
@Test(dataProvider = "resolve_ymd")
|
||||
@ParameterizedTest
|
||||
@MethodSource("data_resolve_ymd")
|
||||
public void test_resolve_ymd_lenient(int y, int m, int d, MinguoDate expected, Object smart, boolean strict) {
|
||||
Map<TemporalField, Long> fieldValues = new HashMap<>();
|
||||
fieldValues.put(ChronoField.YEAR, (long) y);
|
||||
fieldValues.put(ChronoField.MONTH_OF_YEAR, (long) m);
|
||||
fieldValues.put(ChronoField.DAY_OF_MONTH, (long) d);
|
||||
MinguoDate date = MinguoChronology.INSTANCE.resolveDate(fieldValues, ResolverStyle.LENIENT);
|
||||
assertEquals(date, expected);
|
||||
assertEquals(fieldValues.size(), 0);
|
||||
assertEquals(expected, date);
|
||||
assertEquals(0, fieldValues.size());
|
||||
}
|
||||
|
||||
@Test(dataProvider = "resolve_ymd")
|
||||
@ParameterizedTest
|
||||
@MethodSource("data_resolve_ymd")
|
||||
public void test_resolve_ymd_smart(int y, int m, int d, MinguoDate expected, Object smart, boolean strict) {
|
||||
Map<TemporalField, Long> fieldValues = new HashMap<>();
|
||||
fieldValues.put(ChronoField.YEAR, (long) y);
|
||||
@ -722,11 +732,11 @@ public class TCKMinguoChronology {
|
||||
fieldValues.put(ChronoField.DAY_OF_MONTH, (long) d);
|
||||
if (Boolean.TRUE.equals(smart)) {
|
||||
MinguoDate date = MinguoChronology.INSTANCE.resolveDate(fieldValues, ResolverStyle.SMART);
|
||||
assertEquals(date, expected);
|
||||
assertEquals(fieldValues.size(), 0);
|
||||
assertEquals(expected, date);
|
||||
assertEquals(0, fieldValues.size());
|
||||
} else if (smart instanceof MinguoDate) {
|
||||
MinguoDate date = MinguoChronology.INSTANCE.resolveDate(fieldValues, ResolverStyle.SMART);
|
||||
assertEquals(date, smart);
|
||||
assertEquals(smart, date);
|
||||
} else {
|
||||
try {
|
||||
MinguoChronology.INSTANCE.resolveDate(fieldValues, ResolverStyle.SMART);
|
||||
@ -737,7 +747,8 @@ public class TCKMinguoChronology {
|
||||
}
|
||||
}
|
||||
|
||||
@Test(dataProvider = "resolve_ymd")
|
||||
@ParameterizedTest
|
||||
@MethodSource("data_resolve_ymd")
|
||||
public void test_resolve_ymd_strict(int y, int m, int d, MinguoDate expected, Object smart, boolean strict) {
|
||||
Map<TemporalField, Long> fieldValues = new HashMap<>();
|
||||
fieldValues.put(ChronoField.YEAR, (long) y);
|
||||
@ -745,8 +756,8 @@ public class TCKMinguoChronology {
|
||||
fieldValues.put(ChronoField.DAY_OF_MONTH, (long) d);
|
||||
if (strict) {
|
||||
MinguoDate date = MinguoChronology.INSTANCE.resolveDate(fieldValues, ResolverStyle.STRICT);
|
||||
assertEquals(date, expected);
|
||||
assertEquals(fieldValues.size(), 0);
|
||||
assertEquals(expected, date);
|
||||
assertEquals(0, fieldValues.size());
|
||||
} else {
|
||||
try {
|
||||
MinguoChronology.INSTANCE.resolveDate(fieldValues, ResolverStyle.STRICT);
|
||||
@ -759,7 +770,6 @@ public class TCKMinguoChronology {
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------
|
||||
@DataProvider(name = "resolve_yd")
|
||||
Object[][] data_resolve_yd() {
|
||||
return new Object[][] {
|
||||
{2012 - YDIFF, -365, date(2010 - YDIFF, 12, 31), false, false},
|
||||
@ -787,25 +797,27 @@ public class TCKMinguoChronology {
|
||||
};
|
||||
}
|
||||
|
||||
@Test(dataProvider = "resolve_yd")
|
||||
@ParameterizedTest
|
||||
@MethodSource("data_resolve_yd")
|
||||
public void test_resolve_yd_lenient(int y, int d, MinguoDate expected, boolean smart, boolean strict) {
|
||||
Map<TemporalField, Long> fieldValues = new HashMap<>();
|
||||
fieldValues.put(ChronoField.YEAR, (long) y);
|
||||
fieldValues.put(ChronoField.DAY_OF_YEAR, (long) d);
|
||||
MinguoDate date = MinguoChronology.INSTANCE.resolveDate(fieldValues, ResolverStyle.LENIENT);
|
||||
assertEquals(date, expected);
|
||||
assertEquals(fieldValues.size(), 0);
|
||||
assertEquals(expected, date);
|
||||
assertEquals(0, fieldValues.size());
|
||||
}
|
||||
|
||||
@Test(dataProvider = "resolve_yd")
|
||||
@ParameterizedTest
|
||||
@MethodSource("data_resolve_yd")
|
||||
public void test_resolve_yd_smart(int y, int d, MinguoDate expected, boolean smart, boolean strict) {
|
||||
Map<TemporalField, Long> fieldValues = new HashMap<>();
|
||||
fieldValues.put(ChronoField.YEAR, (long) y);
|
||||
fieldValues.put(ChronoField.DAY_OF_YEAR, (long) d);
|
||||
if (smart) {
|
||||
MinguoDate date = MinguoChronology.INSTANCE.resolveDate(fieldValues, ResolverStyle.SMART);
|
||||
assertEquals(date, expected);
|
||||
assertEquals(fieldValues.size(), 0);
|
||||
assertEquals(expected, date);
|
||||
assertEquals(0, fieldValues.size());
|
||||
} else {
|
||||
try {
|
||||
MinguoChronology.INSTANCE.resolveDate(fieldValues, ResolverStyle.SMART);
|
||||
@ -816,15 +828,16 @@ public class TCKMinguoChronology {
|
||||
}
|
||||
}
|
||||
|
||||
@Test(dataProvider = "resolve_yd")
|
||||
@ParameterizedTest
|
||||
@MethodSource("data_resolve_yd")
|
||||
public void test_resolve_yd_strict(int y, int d, MinguoDate expected, boolean smart, boolean strict) {
|
||||
Map<TemporalField, Long> fieldValues = new HashMap<>();
|
||||
fieldValues.put(ChronoField.YEAR, (long) y);
|
||||
fieldValues.put(ChronoField.DAY_OF_YEAR, (long) d);
|
||||
if (strict) {
|
||||
MinguoDate date = MinguoChronology.INSTANCE.resolveDate(fieldValues, ResolverStyle.STRICT);
|
||||
assertEquals(date, expected);
|
||||
assertEquals(fieldValues.size(), 0);
|
||||
assertEquals(expected, date);
|
||||
assertEquals(0, fieldValues.size());
|
||||
} else {
|
||||
try {
|
||||
MinguoChronology.INSTANCE.resolveDate(fieldValues, ResolverStyle.STRICT);
|
||||
@ -837,7 +850,6 @@ public class TCKMinguoChronology {
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------
|
||||
@DataProvider(name = "resolve_ymaa")
|
||||
Object[][] data_resolve_ymaa() {
|
||||
return new Object[][] {
|
||||
{2012 - YDIFF, 1, 1, -365, date(2010 - YDIFF, 12, 31), false, false},
|
||||
@ -894,7 +906,8 @@ public class TCKMinguoChronology {
|
||||
};
|
||||
}
|
||||
|
||||
@Test(dataProvider = "resolve_ymaa")
|
||||
@ParameterizedTest
|
||||
@MethodSource("data_resolve_ymaa")
|
||||
public void test_resolve_ymaa_lenient(int y, int m, int w, int d, MinguoDate expected, boolean smart, boolean strict) {
|
||||
Map<TemporalField, Long> fieldValues = new HashMap<>();
|
||||
fieldValues.put(ChronoField.YEAR, (long) y);
|
||||
@ -902,11 +915,12 @@ public class TCKMinguoChronology {
|
||||
fieldValues.put(ChronoField.ALIGNED_WEEK_OF_MONTH, (long) w);
|
||||
fieldValues.put(ChronoField.ALIGNED_DAY_OF_WEEK_IN_MONTH, (long) d);
|
||||
MinguoDate date = MinguoChronology.INSTANCE.resolveDate(fieldValues, ResolverStyle.LENIENT);
|
||||
assertEquals(date, expected);
|
||||
assertEquals(fieldValues.size(), 0);
|
||||
assertEquals(expected, date);
|
||||
assertEquals(0, fieldValues.size());
|
||||
}
|
||||
|
||||
@Test(dataProvider = "resolve_ymaa")
|
||||
@ParameterizedTest
|
||||
@MethodSource("data_resolve_ymaa")
|
||||
public void test_resolve_ymaa_smart(int y, int m, int w, int d, MinguoDate expected, boolean smart, boolean strict) {
|
||||
Map<TemporalField, Long> fieldValues = new HashMap<>();
|
||||
fieldValues.put(ChronoField.YEAR, (long) y);
|
||||
@ -915,8 +929,8 @@ public class TCKMinguoChronology {
|
||||
fieldValues.put(ChronoField.ALIGNED_DAY_OF_WEEK_IN_MONTH, (long) d);
|
||||
if (smart) {
|
||||
MinguoDate date = MinguoChronology.INSTANCE.resolveDate(fieldValues, ResolverStyle.SMART);
|
||||
assertEquals(date, expected);
|
||||
assertEquals(fieldValues.size(), 0);
|
||||
assertEquals(expected, date);
|
||||
assertEquals(0, fieldValues.size());
|
||||
} else {
|
||||
try {
|
||||
MinguoChronology.INSTANCE.resolveDate(fieldValues, ResolverStyle.SMART);
|
||||
@ -927,7 +941,8 @@ public class TCKMinguoChronology {
|
||||
}
|
||||
}
|
||||
|
||||
@Test(dataProvider = "resolve_ymaa")
|
||||
@ParameterizedTest
|
||||
@MethodSource("data_resolve_ymaa")
|
||||
public void test_resolve_ymaa_strict(int y, int m, int w, int d, MinguoDate expected, boolean smart, boolean strict) {
|
||||
Map<TemporalField, Long> fieldValues = new HashMap<>();
|
||||
fieldValues.put(ChronoField.YEAR, (long) y);
|
||||
@ -936,8 +951,8 @@ public class TCKMinguoChronology {
|
||||
fieldValues.put(ChronoField.ALIGNED_DAY_OF_WEEK_IN_MONTH, (long) d);
|
||||
if (strict) {
|
||||
MinguoDate date = MinguoChronology.INSTANCE.resolveDate(fieldValues, ResolverStyle.STRICT);
|
||||
assertEquals(date, expected);
|
||||
assertEquals(fieldValues.size(), 0);
|
||||
assertEquals(expected, date);
|
||||
assertEquals(0, fieldValues.size());
|
||||
} else {
|
||||
try {
|
||||
MinguoChronology.INSTANCE.resolveDate(fieldValues, ResolverStyle.STRICT);
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2012, 2013, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2012, 2025, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
@ -56,8 +56,9 @@ package tck.java.time.chrono;
|
||||
|
||||
|
||||
import static java.time.temporal.ChronoField.ERA;
|
||||
import static org.testng.Assert.assertEquals;
|
||||
import static org.testng.Assert.assertTrue;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
import java.time.chrono.Era;
|
||||
import java.time.chrono.MinguoChronology;
|
||||
@ -65,16 +66,17 @@ import java.time.chrono.MinguoEra;
|
||||
import java.time.temporal.ValueRange;
|
||||
import java.util.List;
|
||||
|
||||
import org.testng.annotations.DataProvider;
|
||||
import org.testng.annotations.Test;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.TestInstance;
|
||||
import org.junit.jupiter.params.ParameterizedTest;
|
||||
import org.junit.jupiter.params.provider.MethodSource;
|
||||
|
||||
/**
|
||||
* Test.
|
||||
*/
|
||||
@Test
|
||||
@TestInstance(TestInstance.Lifecycle.PER_CLASS)
|
||||
public class TCKMinguoEra {
|
||||
|
||||
@DataProvider(name = "MinguoEras")
|
||||
Object[][] data_of_eras() {
|
||||
return new Object[][] {
|
||||
{MinguoEra.BEFORE_ROC, "BEFORE_ROC", 0},
|
||||
@ -85,11 +87,12 @@ public class TCKMinguoEra {
|
||||
//-----------------------------------------------------------------------
|
||||
// valueOf()
|
||||
//-----------------------------------------------------------------------
|
||||
@Test(dataProvider="MinguoEras")
|
||||
@ParameterizedTest
|
||||
@MethodSource("data_of_eras")
|
||||
public void test_valueOf(MinguoEra era , String eraName, int eraValue) {
|
||||
assertEquals(era.getValue(), eraValue);
|
||||
assertEquals(MinguoEra.of(eraValue), era);
|
||||
assertEquals(MinguoEra.valueOf(eraName), era);
|
||||
assertEquals(eraValue, era.getValue());
|
||||
assertEquals(era, MinguoEra.of(eraValue));
|
||||
assertEquals(era, MinguoEra.valueOf(eraName));
|
||||
}
|
||||
|
||||
|
||||
@ -100,7 +103,7 @@ public class TCKMinguoEra {
|
||||
public void test_values() {
|
||||
List<Era> eraList = MinguoChronology.INSTANCE.eras();
|
||||
MinguoEra[] eras = MinguoEra.values() ;
|
||||
assertEquals(eraList.size(), eras.length);
|
||||
assertEquals(eras.length, eraList.size());
|
||||
for (MinguoEra era : eras) {
|
||||
assertTrue(eraList.contains(era));
|
||||
}
|
||||
@ -112,7 +115,7 @@ public class TCKMinguoEra {
|
||||
@Test
|
||||
public void test_range() {
|
||||
for (MinguoEra era : MinguoEra.values()) {
|
||||
assertEquals(era.range(ERA), ValueRange.of(0, 1));
|
||||
assertEquals(ValueRange.of(0, 1), era.range(ERA));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2012, 2022, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2012, 2025, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
@ -59,19 +59,18 @@
|
||||
*/
|
||||
package tck.java.time.chrono;
|
||||
|
||||
import static org.testng.Assert.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
|
||||
import java.time.LocalDate;
|
||||
import java.time.chrono.ChronoLocalDate;
|
||||
import java.time.chrono.Chronology;
|
||||
|
||||
import org.testng.annotations.Test;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
/**
|
||||
* Tests that a custom Chronology is available via the ServiceLoader.
|
||||
* The CopticChronology is configured via META-INF/services/java.time.chrono.Chronology.
|
||||
*/
|
||||
@Test
|
||||
public class TCKTestServiceLoader {
|
||||
|
||||
@Test
|
||||
@ -79,8 +78,8 @@ public class TCKTestServiceLoader {
|
||||
Chronology chrono = Chronology.of("Coptic");
|
||||
ChronoLocalDate copticDate = chrono.date(1729, 4, 27);
|
||||
LocalDate ld = LocalDate.from(copticDate);
|
||||
assertEquals(ld, LocalDate.of(2013, 1, 5), "CopticDate does not match LocalDate");
|
||||
assertEquals(chrono.isIsoBased(), false);
|
||||
assertEquals(LocalDate.of(2013, 1, 5), ld, "CopticDate does not match LocalDate");
|
||||
assertEquals(false, chrono.isIsoBased());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2012, 2022, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2012, 2025, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
@ -59,11 +59,12 @@ import static java.time.temporal.ChronoField.DAY_OF_YEAR;
|
||||
import static java.time.temporal.ChronoField.MONTH_OF_YEAR;
|
||||
import static java.time.temporal.ChronoField.YEAR;
|
||||
import static java.time.temporal.ChronoField.YEAR_OF_ERA;
|
||||
import static org.testng.Assert.assertEquals;
|
||||
import static org.testng.Assert.assertFalse;
|
||||
import static org.testng.Assert.assertNotEquals;
|
||||
import static org.testng.Assert.assertTrue;
|
||||
import static org.testng.Assert.fail;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||
import static org.junit.jupiter.api.Assertions.assertNotEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
import static org.junit.jupiter.api.Assertions.fail;
|
||||
|
||||
import java.time.Clock;
|
||||
import java.time.DateTimeException;
|
||||
@ -94,14 +95,16 @@ import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
|
||||
import org.testng.Assert;
|
||||
import org.testng.annotations.DataProvider;
|
||||
import org.testng.annotations.Test;
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.TestInstance;
|
||||
import org.junit.jupiter.params.ParameterizedTest;
|
||||
import org.junit.jupiter.params.provider.MethodSource;
|
||||
|
||||
/**
|
||||
* Test.
|
||||
*/
|
||||
@Test
|
||||
@TestInstance(TestInstance.Lifecycle.PER_CLASS)
|
||||
public class TCKThaiBuddhistChronology {
|
||||
|
||||
private static final int YDIFF = 543;
|
||||
@ -113,10 +116,10 @@ public class TCKThaiBuddhistChronology {
|
||||
public void test_chrono_byName() {
|
||||
Chronology c = ThaiBuddhistChronology.INSTANCE;
|
||||
Chronology test = Chronology.of("ThaiBuddhist");
|
||||
Assert.assertNotNull(test, "The ThaiBuddhist calendar could not be found byName");
|
||||
Assert.assertEquals(test.getId(), "ThaiBuddhist", "ID mismatch");
|
||||
Assert.assertEquals(test.getCalendarType(), "buddhist", "Type mismatch");
|
||||
Assert.assertEquals(test, c);
|
||||
Assertions.assertNotNull(test, "The ThaiBuddhist calendar could not be found byName");
|
||||
assertEquals("ThaiBuddhist", test.getId(), "ID mismatch");
|
||||
assertEquals("buddhist", test.getCalendarType(), "Type mismatch");
|
||||
assertEquals(c, test);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
@ -125,42 +128,41 @@ public class TCKThaiBuddhistChronology {
|
||||
@Test
|
||||
public void test_chrono_byLocale_fullTag_thaiCalendarFromThai() {
|
||||
Chronology test = Chronology.ofLocale(Locale.forLanguageTag("th-TH-u-ca-buddhist"));
|
||||
Assert.assertEquals(test.getId(), "ThaiBuddhist");
|
||||
Assert.assertEquals(test, ThaiBuddhistChronology.INSTANCE);
|
||||
assertEquals("ThaiBuddhist", test.getId());
|
||||
assertEquals(ThaiBuddhistChronology.INSTANCE, test);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test_chrono_byLocale_fullTag_thaiCalendarFromElsewhere() {
|
||||
Chronology test = Chronology.ofLocale(Locale.forLanguageTag("en-US-u-ca-buddhist"));
|
||||
Assert.assertEquals(test.getId(), "ThaiBuddhist");
|
||||
Assert.assertEquals(test, ThaiBuddhistChronology.INSTANCE);
|
||||
assertEquals("ThaiBuddhist", test.getId());
|
||||
assertEquals(ThaiBuddhistChronology.INSTANCE, test);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test_chrono_byLocale_oldTH_noVariant() { // deliberately different to Calendar
|
||||
Chronology test = Chronology.ofLocale(Locale.of("th", "TH"));
|
||||
Assert.assertEquals(test.getId(), "ISO");
|
||||
Assert.assertEquals(test, IsoChronology.INSTANCE);
|
||||
assertEquals("ISO", test.getId());
|
||||
assertEquals(IsoChronology.INSTANCE, test);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test_chrono_byLocale_oldTH_variant() {
|
||||
Chronology test = Chronology.ofLocale(Locale.of("th", "TH", "TH"));
|
||||
Assert.assertEquals(test.getId(), "ISO");
|
||||
Assert.assertEquals(test, IsoChronology.INSTANCE);
|
||||
assertEquals("ISO", test.getId());
|
||||
assertEquals(IsoChronology.INSTANCE, test);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test_chrono_byLocale_iso() {
|
||||
Assert.assertEquals(Chronology.ofLocale(Locale.of("th", "TH")).getId(), "ISO");
|
||||
Assert.assertEquals(Chronology.ofLocale(Locale.forLanguageTag("th-TH")).getId(), "ISO");
|
||||
Assert.assertEquals(Chronology.ofLocale(Locale.forLanguageTag("th-TH-TH")).getId(), "ISO");
|
||||
assertEquals("ISO", Chronology.ofLocale(Locale.of("th", "TH")).getId());
|
||||
assertEquals("ISO", Chronology.ofLocale(Locale.forLanguageTag("th-TH")).getId());
|
||||
assertEquals("ISO", Chronology.ofLocale(Locale.forLanguageTag("th-TH-TH")).getId());
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
// creation, toLocalDate()
|
||||
//-----------------------------------------------------------------------
|
||||
@DataProvider(name="samples")
|
||||
Object[][] data_samples() {
|
||||
return new Object[][] {
|
||||
{ThaiBuddhistChronology.INSTANCE.date(1 + YDIFF, 1, 1), LocalDate.of(1, 1, 1)},
|
||||
@ -195,49 +197,52 @@ public class TCKThaiBuddhistChronology {
|
||||
};
|
||||
}
|
||||
|
||||
@Test(dataProvider="samples")
|
||||
@ParameterizedTest
|
||||
@MethodSource("data_samples")
|
||||
public void test_toLocalDate(ThaiBuddhistDate jdate, LocalDate iso) {
|
||||
assertEquals(LocalDate.from(jdate), iso);
|
||||
assertEquals(iso, LocalDate.from(jdate));
|
||||
}
|
||||
|
||||
@Test(dataProvider="samples")
|
||||
@ParameterizedTest
|
||||
@MethodSource("data_samples")
|
||||
public void test_fromCalendrical(ThaiBuddhistDate jdate, LocalDate iso) {
|
||||
assertEquals(ThaiBuddhistChronology.INSTANCE.date(iso), jdate);
|
||||
assertEquals(ThaiBuddhistDate.from(iso), jdate);
|
||||
assertEquals(jdate, ThaiBuddhistChronology.INSTANCE.date(iso));
|
||||
assertEquals(jdate, ThaiBuddhistDate.from(iso));
|
||||
}
|
||||
|
||||
@Test(dataProvider="samples")
|
||||
@ParameterizedTest
|
||||
@MethodSource("data_samples")
|
||||
public void test_isEqual(ThaiBuddhistDate jdate, LocalDate iso) {
|
||||
assertTrue(jdate.isEqual(iso));
|
||||
}
|
||||
|
||||
@Test(dataProvider="samples")
|
||||
@ParameterizedTest
|
||||
@MethodSource("data_samples")
|
||||
public void test_date_equals(ThaiBuddhistDate jdate, LocalDate iso) {
|
||||
assertFalse(jdate.equals(iso));
|
||||
assertNotEquals(jdate.hashCode(), iso.hashCode());
|
||||
assertNotEquals(iso.hashCode(), jdate.hashCode());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test_dateNow(){
|
||||
assertEquals(ThaiBuddhistChronology.INSTANCE.dateNow(), ThaiBuddhistDate.now()) ;
|
||||
assertEquals(ThaiBuddhistChronology.INSTANCE.dateNow(), ThaiBuddhistDate.now(ZoneId.systemDefault())) ;
|
||||
assertEquals(ThaiBuddhistChronology.INSTANCE.dateNow(), ThaiBuddhistDate.now(Clock.systemDefaultZone())) ;
|
||||
assertEquals(ThaiBuddhistChronology.INSTANCE.dateNow(), ThaiBuddhistDate.now(Clock.systemDefaultZone().getZone())) ;
|
||||
assertEquals(ThaiBuddhistDate.now(), ThaiBuddhistChronology.INSTANCE.dateNow()) ;
|
||||
assertEquals(ThaiBuddhistDate.now(ZoneId.systemDefault()), ThaiBuddhistChronology.INSTANCE.dateNow()) ;
|
||||
assertEquals(ThaiBuddhistDate.now(Clock.systemDefaultZone()), ThaiBuddhistChronology.INSTANCE.dateNow()) ;
|
||||
assertEquals(ThaiBuddhistDate.now(Clock.systemDefaultZone().getZone()), ThaiBuddhistChronology.INSTANCE.dateNow()) ;
|
||||
|
||||
assertEquals(ThaiBuddhistChronology.INSTANCE.dateNow(), ThaiBuddhistChronology.INSTANCE.dateNow(ZoneId.systemDefault())) ;
|
||||
assertEquals(ThaiBuddhistChronology.INSTANCE.dateNow(), ThaiBuddhistChronology.INSTANCE.dateNow(Clock.systemDefaultZone())) ;
|
||||
assertEquals(ThaiBuddhistChronology.INSTANCE.dateNow(), ThaiBuddhistChronology.INSTANCE.dateNow(Clock.systemDefaultZone().getZone())) ;
|
||||
assertEquals(ThaiBuddhistChronology.INSTANCE.dateNow(ZoneId.systemDefault()), ThaiBuddhistChronology.INSTANCE.dateNow()) ;
|
||||
assertEquals(ThaiBuddhistChronology.INSTANCE.dateNow(Clock.systemDefaultZone()), ThaiBuddhistChronology.INSTANCE.dateNow()) ;
|
||||
assertEquals(ThaiBuddhistChronology.INSTANCE.dateNow(Clock.systemDefaultZone().getZone()), ThaiBuddhistChronology.INSTANCE.dateNow()) ;
|
||||
|
||||
ZoneId zoneId = ZoneId.of("Europe/Paris");
|
||||
assertEquals(ThaiBuddhistChronology.INSTANCE.dateNow(zoneId), ThaiBuddhistChronology.INSTANCE.dateNow(Clock.system(zoneId))) ;
|
||||
assertEquals(ThaiBuddhistChronology.INSTANCE.dateNow(zoneId), ThaiBuddhistChronology.INSTANCE.dateNow(Clock.system(zoneId).getZone())) ;
|
||||
assertEquals(ThaiBuddhistChronology.INSTANCE.dateNow(zoneId), ThaiBuddhistDate.now(Clock.system(zoneId))) ;
|
||||
assertEquals(ThaiBuddhistChronology.INSTANCE.dateNow(zoneId), ThaiBuddhistDate.now(Clock.system(zoneId).getZone())) ;
|
||||
assertEquals(ThaiBuddhistChronology.INSTANCE.dateNow(Clock.system(zoneId)), ThaiBuddhistChronology.INSTANCE.dateNow(zoneId)) ;
|
||||
assertEquals(ThaiBuddhistChronology.INSTANCE.dateNow(Clock.system(zoneId).getZone()), ThaiBuddhistChronology.INSTANCE.dateNow(zoneId)) ;
|
||||
assertEquals(ThaiBuddhistDate.now(Clock.system(zoneId)), ThaiBuddhistChronology.INSTANCE.dateNow(zoneId)) ;
|
||||
assertEquals(ThaiBuddhistDate.now(Clock.system(zoneId).getZone()), ThaiBuddhistChronology.INSTANCE.dateNow(zoneId)) ;
|
||||
|
||||
assertEquals(ThaiBuddhistChronology.INSTANCE.dateNow(ZoneId.of(ZoneOffset.UTC.getId())), ThaiBuddhistChronology.INSTANCE.dateNow(Clock.systemUTC())) ;
|
||||
assertEquals(ThaiBuddhistChronology.INSTANCE.dateNow(Clock.systemUTC()), ThaiBuddhistChronology.INSTANCE.dateNow(ZoneId.of(ZoneOffset.UTC.getId()))) ;
|
||||
}
|
||||
|
||||
@DataProvider(name="badDates")
|
||||
Object[][] data_badDates() {
|
||||
return new Object[][] {
|
||||
{1728, 0, 0},
|
||||
@ -261,15 +266,15 @@ public class TCKThaiBuddhistChronology {
|
||||
};
|
||||
}
|
||||
|
||||
@Test(dataProvider="badDates", expectedExceptions=DateTimeException.class)
|
||||
@ParameterizedTest
|
||||
@MethodSource("data_badDates")
|
||||
public void test_badDates(int year, int month, int dom) {
|
||||
ThaiBuddhistChronology.INSTANCE.date(year, month, dom);
|
||||
Assertions.assertThrows(DateTimeException.class, () -> ThaiBuddhistChronology.INSTANCE.date(year, month, dom));
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
// prolepticYear() and is LeapYear()
|
||||
//-----------------------------------------------------------------------
|
||||
@DataProvider(name="prolepticYear")
|
||||
Object[][] data_prolepticYear() {
|
||||
return new Object[][] {
|
||||
{1, ThaiBuddhistEra.BE, 4 + YDIFF, 4 + YDIFF, true},
|
||||
@ -297,25 +302,27 @@ public class TCKThaiBuddhistChronology {
|
||||
};
|
||||
}
|
||||
|
||||
@Test(dataProvider="prolepticYear")
|
||||
@ParameterizedTest
|
||||
@MethodSource("data_prolepticYear")
|
||||
public void test_prolepticYear(int eraValue, Era era, int yearOfEra, int expectedProlepticYear, boolean isLeapYear) {
|
||||
Era eraObj = ThaiBuddhistChronology.INSTANCE.eraOf(eraValue);
|
||||
assertTrue(ThaiBuddhistChronology.INSTANCE.eras().contains(eraObj));
|
||||
assertEquals(eraObj, era);
|
||||
assertEquals(ThaiBuddhistChronology.INSTANCE.prolepticYear(era, yearOfEra), expectedProlepticYear);
|
||||
assertEquals(era, eraObj);
|
||||
assertEquals(expectedProlepticYear, ThaiBuddhistChronology.INSTANCE.prolepticYear(era, yearOfEra));
|
||||
}
|
||||
|
||||
@Test(dataProvider="prolepticYear")
|
||||
@ParameterizedTest
|
||||
@MethodSource("data_prolepticYear")
|
||||
public void test_isLeapYear(int eraValue, Era era, int yearOfEra, int expectedProlepticYear, boolean isLeapYear) {
|
||||
assertEquals(ThaiBuddhistChronology.INSTANCE.isLeapYear(expectedProlepticYear), isLeapYear) ;
|
||||
assertEquals(ThaiBuddhistChronology.INSTANCE.isLeapYear(expectedProlepticYear), Year.of(expectedProlepticYear - YDIFF).isLeap());
|
||||
assertEquals(isLeapYear, ThaiBuddhistChronology.INSTANCE.isLeapYear(expectedProlepticYear)) ;
|
||||
assertEquals(Year.of(expectedProlepticYear - YDIFF).isLeap(), ThaiBuddhistChronology.INSTANCE.isLeapYear(expectedProlepticYear));
|
||||
|
||||
ThaiBuddhistDate jdate = ThaiBuddhistDate.now();
|
||||
jdate = jdate.with(ChronoField.YEAR, expectedProlepticYear).with(ChronoField.MONTH_OF_YEAR, 2);
|
||||
if (isLeapYear) {
|
||||
assertEquals(jdate.lengthOfMonth(), 29);
|
||||
assertEquals(29, jdate.lengthOfMonth());
|
||||
} else {
|
||||
assertEquals(jdate.lengthOfMonth(), 28);
|
||||
assertEquals(28, jdate.lengthOfMonth());
|
||||
}
|
||||
}
|
||||
|
||||
@ -365,14 +372,14 @@ public class TCKThaiBuddhistChronology {
|
||||
public void test_adjust1() {
|
||||
ThaiBuddhistDate base = ThaiBuddhistChronology.INSTANCE.date(1728, 10, 29);
|
||||
ThaiBuddhistDate test = base.with(TemporalAdjusters.lastDayOfMonth());
|
||||
assertEquals(test, ThaiBuddhistChronology.INSTANCE.date(1728, 10, 31));
|
||||
assertEquals(ThaiBuddhistChronology.INSTANCE.date(1728, 10, 31), test);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test_adjust2() {
|
||||
ThaiBuddhistDate base = ThaiBuddhistChronology.INSTANCE.date(1728, 12, 2);
|
||||
ThaiBuddhistDate test = base.with(TemporalAdjusters.lastDayOfMonth());
|
||||
assertEquals(test, ThaiBuddhistChronology.INSTANCE.date(1728, 12, 31));
|
||||
assertEquals(ThaiBuddhistChronology.INSTANCE.date(1728, 12, 31), test);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
@ -382,14 +389,14 @@ public class TCKThaiBuddhistChronology {
|
||||
public void test_withYear_BE() {
|
||||
ThaiBuddhistDate base = ThaiBuddhistChronology.INSTANCE.date(2555, 8, 29);
|
||||
ThaiBuddhistDate test = base.with(YEAR, 2554);
|
||||
assertEquals(test, ThaiBuddhistChronology.INSTANCE.date(2554, 8, 29));
|
||||
assertEquals(ThaiBuddhistChronology.INSTANCE.date(2554, 8, 29), test);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test_withYear_BBE() {
|
||||
ThaiBuddhistDate base = ThaiBuddhistChronology.INSTANCE.date(-2554, 8, 29);
|
||||
ThaiBuddhistDate test = base.with(YEAR_OF_ERA, 2554);
|
||||
assertEquals(test, ThaiBuddhistChronology.INSTANCE.date(-2553, 8, 29));
|
||||
assertEquals(ThaiBuddhistChronology.INSTANCE.date(-2553, 8, 29), test);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
@ -399,21 +406,21 @@ public class TCKThaiBuddhistChronology {
|
||||
public void test_withEra_BE() {
|
||||
ThaiBuddhistDate base = ThaiBuddhistChronology.INSTANCE.date(2555, 8, 29);
|
||||
ThaiBuddhistDate test = base.with(ChronoField.ERA, ThaiBuddhistEra.BE.getValue());
|
||||
assertEquals(test, ThaiBuddhistChronology.INSTANCE.date(2555, 8, 29));
|
||||
assertEquals(ThaiBuddhistChronology.INSTANCE.date(2555, 8, 29), test);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test_withEra_BBE() {
|
||||
ThaiBuddhistDate base = ThaiBuddhistChronology.INSTANCE.date(-2554, 8, 29);
|
||||
ThaiBuddhistDate test = base.with(ChronoField.ERA, ThaiBuddhistEra.BEFORE_BE.getValue());
|
||||
assertEquals(test, ThaiBuddhistChronology.INSTANCE.date(-2554, 8, 29));
|
||||
assertEquals(ThaiBuddhistChronology.INSTANCE.date(-2554, 8, 29), test);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test_withEra_swap() {
|
||||
ThaiBuddhistDate base = ThaiBuddhistChronology.INSTANCE.date(-2554, 8, 29);
|
||||
ThaiBuddhistDate test = base.with(ChronoField.ERA, ThaiBuddhistEra.BE.getValue());
|
||||
assertEquals(test, ThaiBuddhistChronology.INSTANCE.date(2555, 8, 29));
|
||||
assertEquals(ThaiBuddhistChronology.INSTANCE.date(2555, 8, 29), test);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
@ -423,13 +430,15 @@ public class TCKThaiBuddhistChronology {
|
||||
public void test_adjust_toLocalDate() {
|
||||
ThaiBuddhistDate jdate = ThaiBuddhistChronology.INSTANCE.date(1726, 1, 4);
|
||||
ThaiBuddhistDate test = jdate.with(LocalDate.of(2012, 7, 6));
|
||||
assertEquals(test, ThaiBuddhistChronology.INSTANCE.date(2555, 7, 6));
|
||||
assertEquals(ThaiBuddhistChronology.INSTANCE.date(2555, 7, 6), test);
|
||||
}
|
||||
|
||||
@Test(expectedExceptions=DateTimeException.class)
|
||||
@Test
|
||||
public void test_adjust_toMonth() {
|
||||
ThaiBuddhistDate jdate = ThaiBuddhistChronology.INSTANCE.date(1726, 1, 4);
|
||||
jdate.with(Month.APRIL);
|
||||
Assertions.assertThrows(DateTimeException.class, () -> {
|
||||
ThaiBuddhistDate jdate = ThaiBuddhistChronology.INSTANCE.date(1726, 1, 4);
|
||||
jdate.with(Month.APRIL);
|
||||
});
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
@ -439,14 +448,14 @@ public class TCKThaiBuddhistChronology {
|
||||
public void test_LocalDate_adjustToBuddhistDate() {
|
||||
ThaiBuddhistDate jdate = ThaiBuddhistChronology.INSTANCE.date(2555, 10, 29);
|
||||
LocalDate test = LocalDate.MIN.with(jdate);
|
||||
assertEquals(test, LocalDate.of(2012, 10, 29));
|
||||
assertEquals(LocalDate.of(2012, 10, 29), test);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test_LocalDateTime_adjustToBuddhistDate() {
|
||||
ThaiBuddhistDate jdate = ThaiBuddhistChronology.INSTANCE.date(2555, 10, 29);
|
||||
LocalDateTime test = LocalDateTime.MIN.with(jdate);
|
||||
assertEquals(test, LocalDateTime.of(2012, 10, 29, 0, 0));
|
||||
assertEquals(LocalDateTime.of(2012, 10, 29, 0, 0), test);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
@ -457,7 +466,7 @@ public class TCKThaiBuddhistChronology {
|
||||
ThaiBuddhistDate mdate1 = ThaiBuddhistDate.of(1, 1, 1);
|
||||
ThaiBuddhistDate mdate2 = ThaiBuddhistDate.of(2, 2, 2);
|
||||
ChronoPeriod period = mdate1.until(mdate2);
|
||||
assertEquals(period, ThaiBuddhistChronology.INSTANCE.period(1, 1, 1));
|
||||
assertEquals(ThaiBuddhistChronology.INSTANCE.period(1, 1, 1), period);
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -465,7 +474,7 @@ public class TCKThaiBuddhistChronology {
|
||||
ThaiBuddhistDate mdate1 = ThaiBuddhistDate.of(1, 1, 1);
|
||||
ThaiBuddhistDate mdate2 = ThaiBuddhistDate.of(2, 2, 2);
|
||||
long months = mdate1.until(mdate2, ChronoUnit.MONTHS);
|
||||
assertEquals(months, 13);
|
||||
assertEquals(13, months);
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -474,13 +483,12 @@ public class TCKThaiBuddhistChronology {
|
||||
ThaiBuddhistDate mdate2 = ThaiBuddhistDate.of(2, 2, 2);
|
||||
MinguoDate ldate2 = MinguoChronology.INSTANCE.date(mdate2);
|
||||
ChronoPeriod period = mdate1.until(ldate2);
|
||||
assertEquals(period, ThaiBuddhistChronology.INSTANCE.period(1, 1, 1));
|
||||
assertEquals(ThaiBuddhistChronology.INSTANCE.period(1, 1, 1), period);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
// toString()
|
||||
//-----------------------------------------------------------------------
|
||||
@DataProvider(name="toString")
|
||||
Object[][] data_toString() {
|
||||
return new Object[][] {
|
||||
{ThaiBuddhistChronology.INSTANCE.date(544, 1, 1), "ThaiBuddhist BE 544-01-01"},
|
||||
@ -491,9 +499,10 @@ public class TCKThaiBuddhistChronology {
|
||||
};
|
||||
}
|
||||
|
||||
@Test(dataProvider="toString")
|
||||
@ParameterizedTest
|
||||
@MethodSource("data_toString")
|
||||
public void test_toString(ThaiBuddhistDate jdate, String expected) {
|
||||
assertEquals(jdate.toString(), expected);
|
||||
assertEquals(expected, jdate.toString());
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
@ -503,12 +512,12 @@ public class TCKThaiBuddhistChronology {
|
||||
public void test_Chrono_range() {
|
||||
long minYear = LocalDate.MIN.getYear() + YDIFF;
|
||||
long maxYear = LocalDate.MAX.getYear() + YDIFF;
|
||||
assertEquals(ThaiBuddhistChronology.INSTANCE.range(YEAR), ValueRange.of(minYear, maxYear));
|
||||
assertEquals(ThaiBuddhistChronology.INSTANCE.range(YEAR_OF_ERA), ValueRange.of(1, -minYear + 1, maxYear));
|
||||
assertEquals(ValueRange.of(minYear, maxYear), ThaiBuddhistChronology.INSTANCE.range(YEAR));
|
||||
assertEquals(ValueRange.of(1, -minYear + 1, maxYear), ThaiBuddhistChronology.INSTANCE.range(YEAR_OF_ERA));
|
||||
|
||||
assertEquals(ThaiBuddhistChronology.INSTANCE.range(DAY_OF_MONTH), DAY_OF_MONTH.range());
|
||||
assertEquals(ThaiBuddhistChronology.INSTANCE.range(DAY_OF_YEAR), DAY_OF_YEAR.range());
|
||||
assertEquals(ThaiBuddhistChronology.INSTANCE.range(MONTH_OF_YEAR), MONTH_OF_YEAR.range());
|
||||
assertEquals(DAY_OF_MONTH.range(), ThaiBuddhistChronology.INSTANCE.range(DAY_OF_MONTH));
|
||||
assertEquals(DAY_OF_YEAR.range(), ThaiBuddhistChronology.INSTANCE.range(DAY_OF_YEAR));
|
||||
assertEquals(MONTH_OF_YEAR.range(), ThaiBuddhistChronology.INSTANCE.range(MONTH_OF_YEAR));
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
@ -526,7 +535,6 @@ public class TCKThaiBuddhistChronology {
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------
|
||||
@DataProvider(name = "resolve_yearOfEra")
|
||||
Object[][] data_resolve_yearOfEra() {
|
||||
return new Object[][] {
|
||||
// era only
|
||||
@ -591,7 +599,8 @@ public class TCKThaiBuddhistChronology {
|
||||
};
|
||||
}
|
||||
|
||||
@Test(dataProvider = "resolve_yearOfEra")
|
||||
@ParameterizedTest
|
||||
@MethodSource("data_resolve_yearOfEra")
|
||||
public void test_resolve_yearOfEra(ResolverStyle style, Integer e, Integer yoe, Integer y, ChronoField field, Integer expected) {
|
||||
Map<TemporalField, Long> fieldValues = new HashMap<>();
|
||||
if (e != null) {
|
||||
@ -605,9 +614,9 @@ public class TCKThaiBuddhistChronology {
|
||||
}
|
||||
if (field != null) {
|
||||
ThaiBuddhistDate date = ThaiBuddhistChronology.INSTANCE.resolveDate(fieldValues, style);
|
||||
assertEquals(date, null);
|
||||
assertEquals(fieldValues.get(field), (Long) expected.longValue());
|
||||
assertEquals(fieldValues.size(), 1);
|
||||
assertEquals(null, date);
|
||||
assertEquals((Long) expected.longValue(), fieldValues.get(field));
|
||||
assertEquals(1, fieldValues.size());
|
||||
} else {
|
||||
try {
|
||||
ThaiBuddhistChronology.INSTANCE.resolveDate(fieldValues, style);
|
||||
@ -620,7 +629,6 @@ public class TCKThaiBuddhistChronology {
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------
|
||||
@DataProvider(name = "resolve_ymd")
|
||||
Object[][] data_resolve_ymd() {
|
||||
return new Object[][] {
|
||||
{YDIFF + 2012, 1, -365, date(YDIFF + 2010, 12, 31), false, false},
|
||||
@ -679,18 +687,20 @@ public class TCKThaiBuddhistChronology {
|
||||
};
|
||||
}
|
||||
|
||||
@Test(dataProvider = "resolve_ymd")
|
||||
@ParameterizedTest
|
||||
@MethodSource("data_resolve_ymd")
|
||||
public void test_resolve_ymd_lenient(int y, int m, int d, ThaiBuddhistDate expected, Object smart, boolean strict) {
|
||||
Map<TemporalField, Long> fieldValues = new HashMap<>();
|
||||
fieldValues.put(ChronoField.YEAR, (long) y);
|
||||
fieldValues.put(ChronoField.MONTH_OF_YEAR, (long) m);
|
||||
fieldValues.put(ChronoField.DAY_OF_MONTH, (long) d);
|
||||
ThaiBuddhistDate date = ThaiBuddhistChronology.INSTANCE.resolveDate(fieldValues, ResolverStyle.LENIENT);
|
||||
assertEquals(date, expected);
|
||||
assertEquals(fieldValues.size(), 0);
|
||||
assertEquals(expected, date);
|
||||
assertEquals(0, fieldValues.size());
|
||||
}
|
||||
|
||||
@Test(dataProvider = "resolve_ymd")
|
||||
@ParameterizedTest
|
||||
@MethodSource("data_resolve_ymd")
|
||||
public void test_resolve_ymd_smart(int y, int m, int d, ThaiBuddhistDate expected, Object smart, boolean strict) {
|
||||
Map<TemporalField, Long> fieldValues = new HashMap<>();
|
||||
fieldValues.put(ChronoField.YEAR, (long) y);
|
||||
@ -698,11 +708,11 @@ public class TCKThaiBuddhistChronology {
|
||||
fieldValues.put(ChronoField.DAY_OF_MONTH, (long) d);
|
||||
if (Boolean.TRUE.equals(smart)) {
|
||||
ThaiBuddhistDate date = ThaiBuddhistChronology.INSTANCE.resolveDate(fieldValues, ResolverStyle.SMART);
|
||||
assertEquals(date, expected);
|
||||
assertEquals(fieldValues.size(), 0);
|
||||
assertEquals(expected, date);
|
||||
assertEquals(0, fieldValues.size());
|
||||
} else if (smart instanceof ThaiBuddhistDate) {
|
||||
ThaiBuddhistDate date = ThaiBuddhistChronology.INSTANCE.resolveDate(fieldValues, ResolverStyle.SMART);
|
||||
assertEquals(date, smart);
|
||||
assertEquals(smart, date);
|
||||
} else {
|
||||
try {
|
||||
ThaiBuddhistChronology.INSTANCE.resolveDate(fieldValues, ResolverStyle.SMART);
|
||||
@ -713,7 +723,8 @@ public class TCKThaiBuddhistChronology {
|
||||
}
|
||||
}
|
||||
|
||||
@Test(dataProvider = "resolve_ymd")
|
||||
@ParameterizedTest
|
||||
@MethodSource("data_resolve_ymd")
|
||||
public void test_resolve_ymd_strict(int y, int m, int d, ThaiBuddhistDate expected, Object smart, boolean strict) {
|
||||
Map<TemporalField, Long> fieldValues = new HashMap<>();
|
||||
fieldValues.put(ChronoField.YEAR, (long) y);
|
||||
@ -721,8 +732,8 @@ public class TCKThaiBuddhistChronology {
|
||||
fieldValues.put(ChronoField.DAY_OF_MONTH, (long) d);
|
||||
if (strict) {
|
||||
ThaiBuddhistDate date = ThaiBuddhistChronology.INSTANCE.resolveDate(fieldValues, ResolverStyle.STRICT);
|
||||
assertEquals(date, expected);
|
||||
assertEquals(fieldValues.size(), 0);
|
||||
assertEquals(expected, date);
|
||||
assertEquals(0, fieldValues.size());
|
||||
} else {
|
||||
try {
|
||||
ThaiBuddhistChronology.INSTANCE.resolveDate(fieldValues, ResolverStyle.STRICT);
|
||||
@ -735,7 +746,6 @@ public class TCKThaiBuddhistChronology {
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------
|
||||
@DataProvider(name = "resolve_yd")
|
||||
Object[][] data_resolve_yd() {
|
||||
return new Object[][] {
|
||||
{YDIFF + 2012, -365, date(YDIFF + 2010, 12, 31), false, false},
|
||||
@ -763,25 +773,27 @@ public class TCKThaiBuddhistChronology {
|
||||
};
|
||||
}
|
||||
|
||||
@Test(dataProvider = "resolve_yd")
|
||||
@ParameterizedTest
|
||||
@MethodSource("data_resolve_yd")
|
||||
public void test_resolve_yd_lenient(int y, int d, ThaiBuddhistDate expected, boolean smart, boolean strict) {
|
||||
Map<TemporalField, Long> fieldValues = new HashMap<>();
|
||||
fieldValues.put(ChronoField.YEAR, (long) y);
|
||||
fieldValues.put(ChronoField.DAY_OF_YEAR, (long) d);
|
||||
ThaiBuddhistDate date = ThaiBuddhistChronology.INSTANCE.resolveDate(fieldValues, ResolverStyle.LENIENT);
|
||||
assertEquals(date, expected);
|
||||
assertEquals(fieldValues.size(), 0);
|
||||
assertEquals(expected, date);
|
||||
assertEquals(0, fieldValues.size());
|
||||
}
|
||||
|
||||
@Test(dataProvider = "resolve_yd")
|
||||
@ParameterizedTest
|
||||
@MethodSource("data_resolve_yd")
|
||||
public void test_resolve_yd_smart(int y, int d, ThaiBuddhistDate expected, boolean smart, boolean strict) {
|
||||
Map<TemporalField, Long> fieldValues = new HashMap<>();
|
||||
fieldValues.put(ChronoField.YEAR, (long) y);
|
||||
fieldValues.put(ChronoField.DAY_OF_YEAR, (long) d);
|
||||
if (smart) {
|
||||
ThaiBuddhistDate date = ThaiBuddhistChronology.INSTANCE.resolveDate(fieldValues, ResolverStyle.SMART);
|
||||
assertEquals(date, expected);
|
||||
assertEquals(fieldValues.size(), 0);
|
||||
assertEquals(expected, date);
|
||||
assertEquals(0, fieldValues.size());
|
||||
} else {
|
||||
try {
|
||||
ThaiBuddhistChronology.INSTANCE.resolveDate(fieldValues, ResolverStyle.SMART);
|
||||
@ -792,15 +804,16 @@ public class TCKThaiBuddhistChronology {
|
||||
}
|
||||
}
|
||||
|
||||
@Test(dataProvider = "resolve_yd")
|
||||
@ParameterizedTest
|
||||
@MethodSource("data_resolve_yd")
|
||||
public void test_resolve_yd_strict(int y, int d, ThaiBuddhistDate expected, boolean smart, boolean strict) {
|
||||
Map<TemporalField, Long> fieldValues = new HashMap<>();
|
||||
fieldValues.put(ChronoField.YEAR, (long) y);
|
||||
fieldValues.put(ChronoField.DAY_OF_YEAR, (long) d);
|
||||
if (strict) {
|
||||
ThaiBuddhistDate date = ThaiBuddhistChronology.INSTANCE.resolveDate(fieldValues, ResolverStyle.STRICT);
|
||||
assertEquals(date, expected);
|
||||
assertEquals(fieldValues.size(), 0);
|
||||
assertEquals(expected, date);
|
||||
assertEquals(0, fieldValues.size());
|
||||
} else {
|
||||
try {
|
||||
ThaiBuddhistChronology.INSTANCE.resolveDate(fieldValues, ResolverStyle.STRICT);
|
||||
@ -813,7 +826,6 @@ public class TCKThaiBuddhistChronology {
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------
|
||||
@DataProvider(name = "resolve_ymaa")
|
||||
Object[][] data_resolve_ymaa() {
|
||||
return new Object[][] {
|
||||
{YDIFF + 2012, 1, 1, -365, date(YDIFF + 2010, 12, 31), false, false},
|
||||
@ -870,7 +882,8 @@ public class TCKThaiBuddhistChronology {
|
||||
};
|
||||
}
|
||||
|
||||
@Test(dataProvider = "resolve_ymaa")
|
||||
@ParameterizedTest
|
||||
@MethodSource("data_resolve_ymaa")
|
||||
public void test_resolve_ymaa_lenient(int y, int m, int w, int d, ThaiBuddhistDate expected, boolean smart, boolean strict) {
|
||||
Map<TemporalField, Long> fieldValues = new HashMap<>();
|
||||
fieldValues.put(ChronoField.YEAR, (long) y);
|
||||
@ -878,11 +891,12 @@ public class TCKThaiBuddhistChronology {
|
||||
fieldValues.put(ChronoField.ALIGNED_WEEK_OF_MONTH, (long) w);
|
||||
fieldValues.put(ChronoField.ALIGNED_DAY_OF_WEEK_IN_MONTH, (long) d);
|
||||
ThaiBuddhistDate date = ThaiBuddhistChronology.INSTANCE.resolveDate(fieldValues, ResolverStyle.LENIENT);
|
||||
assertEquals(date, expected);
|
||||
assertEquals(fieldValues.size(), 0);
|
||||
assertEquals(expected, date);
|
||||
assertEquals(0, fieldValues.size());
|
||||
}
|
||||
|
||||
@Test(dataProvider = "resolve_ymaa")
|
||||
@ParameterizedTest
|
||||
@MethodSource("data_resolve_ymaa")
|
||||
public void test_resolve_ymaa_smart(int y, int m, int w, int d, ThaiBuddhistDate expected, boolean smart, boolean strict) {
|
||||
Map<TemporalField, Long> fieldValues = new HashMap<>();
|
||||
fieldValues.put(ChronoField.YEAR, (long) y);
|
||||
@ -891,8 +905,8 @@ public class TCKThaiBuddhistChronology {
|
||||
fieldValues.put(ChronoField.ALIGNED_DAY_OF_WEEK_IN_MONTH, (long) d);
|
||||
if (smart) {
|
||||
ThaiBuddhistDate date = ThaiBuddhistChronology.INSTANCE.resolveDate(fieldValues, ResolverStyle.SMART);
|
||||
assertEquals(date, expected);
|
||||
assertEquals(fieldValues.size(), 0);
|
||||
assertEquals(expected, date);
|
||||
assertEquals(0, fieldValues.size());
|
||||
} else {
|
||||
try {
|
||||
ThaiBuddhistChronology.INSTANCE.resolveDate(fieldValues, ResolverStyle.SMART);
|
||||
@ -903,7 +917,8 @@ public class TCKThaiBuddhistChronology {
|
||||
}
|
||||
}
|
||||
|
||||
@Test(dataProvider = "resolve_ymaa")
|
||||
@ParameterizedTest
|
||||
@MethodSource("data_resolve_ymaa")
|
||||
public void test_resolve_ymaa_strict(int y, int m, int w, int d, ThaiBuddhistDate expected, boolean smart, boolean strict) {
|
||||
Map<TemporalField, Long> fieldValues = new HashMap<>();
|
||||
fieldValues.put(ChronoField.YEAR, (long) y);
|
||||
@ -912,8 +927,8 @@ public class TCKThaiBuddhistChronology {
|
||||
fieldValues.put(ChronoField.ALIGNED_DAY_OF_WEEK_IN_MONTH, (long) d);
|
||||
if (strict) {
|
||||
ThaiBuddhistDate date = ThaiBuddhistChronology.INSTANCE.resolveDate(fieldValues, ResolverStyle.STRICT);
|
||||
assertEquals(date, expected);
|
||||
assertEquals(fieldValues.size(), 0);
|
||||
assertEquals(expected, date);
|
||||
assertEquals(0, fieldValues.size());
|
||||
} else {
|
||||
try {
|
||||
ThaiBuddhistChronology.INSTANCE.resolveDate(fieldValues, ResolverStyle.STRICT);
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2012, 2013, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2012, 2025, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
@ -55,8 +55,9 @@
|
||||
package tck.java.time.chrono;
|
||||
|
||||
import static java.time.temporal.ChronoField.ERA;
|
||||
import static org.testng.Assert.assertEquals;
|
||||
import static org.testng.Assert.assertTrue;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
import java.time.chrono.Era;
|
||||
import java.time.chrono.ThaiBuddhistChronology;
|
||||
@ -64,16 +65,17 @@ import java.time.chrono.ThaiBuddhistEra;
|
||||
import java.time.temporal.ValueRange;
|
||||
import java.util.List;
|
||||
|
||||
import org.testng.annotations.DataProvider;
|
||||
import org.testng.annotations.Test;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.TestInstance;
|
||||
import org.junit.jupiter.params.ParameterizedTest;
|
||||
import org.junit.jupiter.params.provider.MethodSource;
|
||||
|
||||
/**
|
||||
* Test.
|
||||
*/
|
||||
@Test
|
||||
@TestInstance(TestInstance.Lifecycle.PER_CLASS)
|
||||
public class TCKThaiBuddhistEra {
|
||||
|
||||
@DataProvider(name = "ThaiBuddhistEras")
|
||||
Object[][] data_of_eras() {
|
||||
return new Object[][] {
|
||||
{ThaiBuddhistEra.BEFORE_BE, "BEFORE_BE", 0},
|
||||
@ -85,11 +87,12 @@ public class TCKThaiBuddhistEra {
|
||||
//-----------------------------------------------------------------------
|
||||
// valueOf()
|
||||
//-----------------------------------------------------------------------
|
||||
@Test(dataProvider="ThaiBuddhistEras")
|
||||
@ParameterizedTest
|
||||
@MethodSource("data_of_eras")
|
||||
public void test_valueOf(ThaiBuddhistEra era , String eraName, int eraValue) {
|
||||
assertEquals(era.getValue(), eraValue);
|
||||
assertEquals(ThaiBuddhistEra.of(eraValue), era);
|
||||
assertEquals(ThaiBuddhistEra.valueOf(eraName), era);
|
||||
assertEquals(eraValue, era.getValue());
|
||||
assertEquals(era, ThaiBuddhistEra.of(eraValue));
|
||||
assertEquals(era, ThaiBuddhistEra.valueOf(eraName));
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
@ -99,7 +102,7 @@ public class TCKThaiBuddhistEra {
|
||||
public void test_values() {
|
||||
List<Era> eraList = ThaiBuddhistChronology.INSTANCE.eras();
|
||||
ThaiBuddhistEra[] eras = ThaiBuddhistEra.values();
|
||||
assertEquals(eraList.size(), eras.length);
|
||||
assertEquals(eras.length, eraList.size());
|
||||
for (ThaiBuddhistEra era : eras) {
|
||||
assertTrue(eraList.contains(era));
|
||||
}
|
||||
@ -111,7 +114,7 @@ public class TCKThaiBuddhistEra {
|
||||
@Test
|
||||
public void test_range() {
|
||||
for (ThaiBuddhistEra era : ThaiBuddhistEra.values()) {
|
||||
assertEquals(era.range(ERA), ValueRange.of(0, 1));
|
||||
assertEquals(ValueRange.of(0, 1), era.range(ERA));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2012, 2013, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2012, 2025, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
@ -69,17 +69,17 @@ import java.time.chrono.JapaneseEra;
|
||||
import java.time.chrono.MinguoDate;
|
||||
import java.time.chrono.ThaiBuddhistDate;
|
||||
|
||||
import org.testng.annotations.DataProvider;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.TestInstance;
|
||||
import org.junit.jupiter.params.ParameterizedTest;
|
||||
import org.junit.jupiter.params.provider.MethodSource;
|
||||
|
||||
import tck.java.time.AbstractTCKTest;
|
||||
|
||||
/**
|
||||
* Test serialization of built-in chronologies.
|
||||
*/
|
||||
@Test
|
||||
@TestInstance(TestInstance.Lifecycle.PER_CLASS)
|
||||
public class TCKChronoLocalDateSerialization extends AbstractTCKTest {
|
||||
|
||||
static final int CHRONO_TYPE = 1; // java.time.chrono.Ser.CHRONO_TYPE
|
||||
@ -91,7 +91,6 @@ public class TCKChronoLocalDateSerialization extends AbstractTCKTest {
|
||||
//-----------------------------------------------------------------------
|
||||
// Regular data factory for names and descriptions of available calendars
|
||||
//-----------------------------------------------------------------------
|
||||
@DataProvider(name = "calendars")
|
||||
Object[][] data_of_calendars() {
|
||||
return new Object[][]{
|
||||
{JapaneseDate.of(JapaneseEra.HEISEI, 25, 01, 05), JAPANESE_DATE_TYPE},
|
||||
@ -104,7 +103,8 @@ public class TCKChronoLocalDateSerialization extends AbstractTCKTest {
|
||||
//-----------------------------------------------------------------------
|
||||
// Test Serialization of Calendars
|
||||
//-----------------------------------------------------------------------
|
||||
@Test( dataProvider="calendars")
|
||||
@ParameterizedTest
|
||||
@MethodSource("data_of_calendars")
|
||||
public void test_ChronoSerialization(ChronoLocalDate date, int dateType) throws Exception {
|
||||
assertSerializable(date);
|
||||
}
|
||||
@ -112,8 +112,9 @@ public class TCKChronoLocalDateSerialization extends AbstractTCKTest {
|
||||
//-----------------------------------------------------------------------
|
||||
// Test that serialization produces exact sequence of bytes
|
||||
//-----------------------------------------------------------------------
|
||||
@Test(dataProvider="calendars")
|
||||
private void test_serialization_format(ChronoLocalDate date, int dateType) throws Exception {
|
||||
@ParameterizedTest
|
||||
@MethodSource("data_of_calendars")
|
||||
void test_serialization_format(ChronoLocalDate date, int dateType) throws Exception {
|
||||
ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
||||
try (DataOutputStream dos = new DataOutputStream(baos) ) {
|
||||
dos.writeByte(dateType);
|
||||
@ -164,7 +165,6 @@ public class TCKChronoLocalDateSerialization extends AbstractTCKTest {
|
||||
//-----------------------------------------------------------------------
|
||||
// Regular data factory for names and descriptions of available calendars
|
||||
//-----------------------------------------------------------------------
|
||||
@DataProvider(name = "invalidSerialformClasses")
|
||||
Object[][] invalid_serial_classes() {
|
||||
return new Object[][]{
|
||||
{JapaneseEra.class},
|
||||
@ -175,7 +175,8 @@ public class TCKChronoLocalDateSerialization extends AbstractTCKTest {
|
||||
};
|
||||
}
|
||||
|
||||
@Test(dataProvider="invalidSerialformClasses")
|
||||
@ParameterizedTest
|
||||
@MethodSource("invalid_serial_classes")
|
||||
public void test_invalid_serialform(Class<?> clazz) throws Exception {
|
||||
assertNotSerializable(clazz);
|
||||
}
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2012, 2013, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2012, 2025, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
@ -54,8 +54,6 @@
|
||||
*/
|
||||
package tck.java.time.chrono.serial;
|
||||
|
||||
import org.testng.annotations.DataProvider;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
import java.time.LocalDate;
|
||||
import java.time.LocalDateTime;
|
||||
@ -67,18 +65,21 @@ import java.time.chrono.JapaneseChronology;
|
||||
import java.time.chrono.MinguoChronology;
|
||||
import java.time.chrono.ThaiBuddhistChronology;
|
||||
|
||||
import org.junit.jupiter.api.TestInstance;
|
||||
import org.junit.jupiter.params.ParameterizedTest;
|
||||
import org.junit.jupiter.params.provider.MethodSource;
|
||||
|
||||
import tck.java.time.AbstractTCKTest;
|
||||
|
||||
/**
|
||||
* Test serialization of ChronoLocalDateTime for all built-in chronologies.
|
||||
*/
|
||||
@Test
|
||||
@TestInstance(TestInstance.Lifecycle.PER_CLASS)
|
||||
public class TCKChronoLocalDateTimeSerialization extends AbstractTCKTest {
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
// regular data factory for available calendars
|
||||
//-----------------------------------------------------------------------
|
||||
@DataProvider(name = "calendars")
|
||||
Chronology[][] data_of_calendars() {
|
||||
return new Chronology[][]{
|
||||
{HijrahChronology.INSTANCE},
|
||||
@ -91,7 +92,8 @@ public class TCKChronoLocalDateTimeSerialization extends AbstractTCKTest {
|
||||
//-----------------------------------------------------------------------
|
||||
// Test Serialization of ChronoLocalDateTime
|
||||
//-----------------------------------------------------------------------
|
||||
@Test(dataProvider="calendars")
|
||||
@ParameterizedTest
|
||||
@MethodSource("data_of_calendars")
|
||||
public void test_ChronoLocalDateTimeSerialization(Chronology chrono) throws Exception {
|
||||
LocalDateTime ref = LocalDate.of(2013, 1, 5).atTime(12, 1, 2, 3);
|
||||
ChronoLocalDateTime<?> original = chrono.date(ref).atTime(ref.toLocalTime());
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2012, 2013, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2012, 2025, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
@ -64,20 +64,22 @@ import java.time.chrono.IsoChronology;
|
||||
import java.time.chrono.JapaneseChronology;
|
||||
import java.time.chrono.MinguoChronology;
|
||||
import java.time.chrono.ThaiBuddhistChronology;
|
||||
import org.testng.annotations.DataProvider;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
import org.junit.jupiter.api.TestInstance;
|
||||
import org.junit.jupiter.params.ParameterizedTest;
|
||||
import org.junit.jupiter.params.provider.MethodSource;
|
||||
|
||||
import tck.java.time.AbstractTCKTest;
|
||||
|
||||
/**
|
||||
* Test assertions that must be true for all built-in chronologies.
|
||||
*/
|
||||
@Test
|
||||
@TestInstance(TestInstance.Lifecycle.PER_CLASS)
|
||||
public class TCKChronoZonedDateTimeSerialization extends AbstractTCKTest {
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
// regular data factory for names and descriptions of available calendars
|
||||
//-----------------------------------------------------------------------
|
||||
@DataProvider(name = "calendars")
|
||||
Chronology[][] data_of_calendars() {
|
||||
return new Chronology[][]{
|
||||
{HijrahChronology.INSTANCE},
|
||||
@ -91,7 +93,8 @@ public class TCKChronoZonedDateTimeSerialization extends AbstractTCKTest {
|
||||
//-----------------------------------------------------------------------
|
||||
// Test Serialization of ISO via chrono API
|
||||
//-----------------------------------------------------------------------
|
||||
@Test( dataProvider="calendars")
|
||||
@ParameterizedTest
|
||||
@MethodSource("data_of_calendars")
|
||||
public void test_ChronoZonedDateTimeSerialization(Chronology chrono) throws Exception {
|
||||
ZonedDateTime ref = LocalDate.of(2013, 1, 5).atTime(12, 1, 2, 3).atZone(ZoneId.of("GMT+01:23"));
|
||||
ChronoZonedDateTime<?> original = chrono.date(ref).atTime(ref.toLocalTime()).atZone(ref.getZone());
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2013, 2025, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
@ -64,12 +64,13 @@ import java.time.chrono.JapaneseChronology;
|
||||
import java.time.chrono.MinguoChronology;
|
||||
import java.time.chrono.ThaiBuddhistChronology;
|
||||
|
||||
import org.testng.annotations.DataProvider;
|
||||
import org.testng.annotations.Test;
|
||||
import org.junit.jupiter.api.TestInstance;
|
||||
import org.junit.jupiter.params.ParameterizedTest;
|
||||
import org.junit.jupiter.params.provider.MethodSource;
|
||||
|
||||
import tck.java.time.AbstractTCKTest;
|
||||
|
||||
@Test
|
||||
@TestInstance(TestInstance.Lifecycle.PER_CLASS)
|
||||
public class TCKChronologySerialization extends AbstractTCKTest {
|
||||
|
||||
static final int CHRONO_TYPE = 1; // java.time.chrono.Ser.CHRONO_TYPE
|
||||
@ -77,7 +78,6 @@ public class TCKChronologySerialization extends AbstractTCKTest {
|
||||
//-----------------------------------------------------------------------
|
||||
// Regular data factory for available calendars
|
||||
//-----------------------------------------------------------------------
|
||||
@DataProvider(name = "calendars")
|
||||
Chronology[][] data_of_calendars() {
|
||||
return new Chronology[][]{
|
||||
{HijrahChronology.INSTANCE},
|
||||
@ -90,7 +90,8 @@ public class TCKChronologySerialization extends AbstractTCKTest {
|
||||
//-----------------------------------------------------------------------
|
||||
// Test Serialization of Calendars
|
||||
//-----------------------------------------------------------------------
|
||||
@Test(dataProvider="calendars")
|
||||
@ParameterizedTest
|
||||
@MethodSource("data_of_calendars")
|
||||
public void test_chronoSerialization(Chronology chrono) throws Exception {
|
||||
assertSerializable(chrono);
|
||||
}
|
||||
@ -98,8 +99,9 @@ public class TCKChronologySerialization extends AbstractTCKTest {
|
||||
//-----------------------------------------------------------------------
|
||||
// Test that serialization produces exact sequence of bytes
|
||||
//-----------------------------------------------------------------------
|
||||
@Test(dataProvider="calendars")
|
||||
private void test_serializationBytes(Chronology chrono) throws Exception {
|
||||
@ParameterizedTest
|
||||
@MethodSource("data_of_calendars")
|
||||
void test_serializationBytes(Chronology chrono) throws Exception {
|
||||
ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
||||
try (DataOutputStream dos = new DataOutputStream(baos) ) {
|
||||
dos.writeByte(CHRONO_TYPE);
|
||||
@ -113,7 +115,6 @@ public class TCKChronologySerialization extends AbstractTCKTest {
|
||||
//-----------------------------------------------------------------------
|
||||
// Regular data factory for names and descriptions of available calendars
|
||||
//-----------------------------------------------------------------------
|
||||
@DataProvider(name = "invalidSerialformClasses")
|
||||
Object[][] invalid_serial_classes() {
|
||||
return new Object[][]{
|
||||
{IsoChronology.class},
|
||||
@ -124,7 +125,8 @@ public class TCKChronologySerialization extends AbstractTCKTest {
|
||||
};
|
||||
}
|
||||
|
||||
@Test(dataProvider="invalidSerialformClasses")
|
||||
@ParameterizedTest
|
||||
@MethodSource("invalid_serial_classes")
|
||||
public void test_invalid_serialform(Class<?> clazz) throws Exception {
|
||||
assertNotSerializable(clazz);
|
||||
}
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2013, 2025, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
@ -63,13 +63,13 @@ import java.io.IOException;
|
||||
import java.time.chrono.ChronoLocalDate;
|
||||
import java.time.chrono.Chronology;
|
||||
|
||||
import org.testng.annotations.Test;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import tck.java.time.AbstractTCKTest;
|
||||
|
||||
/**
|
||||
* Tests the serialization of ChronoLocalDate using a CopticDate.
|
||||
*/
|
||||
@Test
|
||||
public class TCKCopticSerialization extends AbstractTCKTest {
|
||||
|
||||
@Test
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2013, 2025, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
@ -75,8 +75,10 @@ import java.time.chrono.JapaneseEra;
|
||||
import java.time.chrono.MinguoEra;
|
||||
import java.time.chrono.ThaiBuddhistEra;
|
||||
|
||||
import org.testng.annotations.DataProvider;
|
||||
import org.testng.annotations.Test;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.TestInstance;
|
||||
import org.junit.jupiter.params.ParameterizedTest;
|
||||
import org.junit.jupiter.params.provider.MethodSource;
|
||||
|
||||
import tck.java.time.AbstractTCKTest;
|
||||
|
||||
@ -87,7 +89,7 @@ import tck.java.time.AbstractTCKTest;
|
||||
* The serialized form of these types are not tested, only that they are
|
||||
* serializable.
|
||||
*/
|
||||
@Test
|
||||
@TestInstance(TestInstance.Lifecycle.PER_CLASS)
|
||||
public class TCKEraSerialization extends AbstractTCKTest {
|
||||
|
||||
static final int JAPANESE_ERA_TYPE = 5; // java.time.chrono.Ser.JAPANESE_ERA
|
||||
@ -96,7 +98,6 @@ public class TCKEraSerialization extends AbstractTCKTest {
|
||||
//-----------------------------------------------------------------------
|
||||
// Regular data factory for the available Eras
|
||||
//-----------------------------------------------------------------------
|
||||
@DataProvider(name = "Eras")
|
||||
Era[][] data_of_calendars() {
|
||||
return new Era[][] {
|
||||
{HijrahEra.AH},
|
||||
@ -109,7 +110,8 @@ public class TCKEraSerialization extends AbstractTCKTest {
|
||||
};
|
||||
}
|
||||
|
||||
@Test(dataProvider="Eras")
|
||||
@ParameterizedTest
|
||||
@MethodSource("data_of_calendars")
|
||||
public void test_eraSerialization(Era era) throws IOException, ClassNotFoundException {
|
||||
assertSerializableSame(era);
|
||||
}
|
||||
@ -118,7 +120,7 @@ public class TCKEraSerialization extends AbstractTCKTest {
|
||||
// Test JapaneseEra serialization produces exact sequence of bytes
|
||||
//-----------------------------------------------------------------------
|
||||
@Test
|
||||
private void test_JapaneseErasSerialization() throws Exception {
|
||||
void test_JapaneseErasSerialization() throws Exception {
|
||||
for (JapaneseEra era : JapaneseEra.values()) {
|
||||
assertSerializableSame(era);
|
||||
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2012, 2013, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2012, 2025, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
@ -59,7 +59,7 @@
|
||||
*/
|
||||
package tck.java.time.format;
|
||||
|
||||
import static org.testng.Assert.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
|
||||
import java.text.ParsePosition;
|
||||
import java.time.chrono.Chronology;
|
||||
@ -72,39 +72,41 @@ import java.time.temporal.TemporalQueries;
|
||||
import java.time.temporal.TemporalQuery;
|
||||
import java.util.Locale;
|
||||
|
||||
import org.testng.annotations.BeforeMethod;
|
||||
import org.testng.annotations.DataProvider;
|
||||
import org.testng.annotations.Test;
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.TestInstance;
|
||||
import org.junit.jupiter.params.ParameterizedTest;
|
||||
import org.junit.jupiter.params.provider.MethodSource;
|
||||
|
||||
/**
|
||||
* Test formatter chrono.
|
||||
*/
|
||||
@Test
|
||||
@TestInstance(TestInstance.Lifecycle.PER_CLASS)
|
||||
public class TCKChronoPrinterParser {
|
||||
// this test assumes ISO, ThaiBuddhist and Japanese are available
|
||||
|
||||
private DateTimeFormatterBuilder builder;
|
||||
private ParsePosition pos;
|
||||
|
||||
@BeforeMethod
|
||||
@BeforeEach
|
||||
public void setUp() {
|
||||
builder = new DateTimeFormatterBuilder();
|
||||
pos = new ParsePosition(0);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
@Test(expectedExceptions=IndexOutOfBoundsException.class)
|
||||
@Test
|
||||
public void test_parse_negativePosition() {
|
||||
builder.appendChronologyId().toFormatter().parseUnresolved("ISO", new ParsePosition(-1));
|
||||
Assertions.assertThrows(IndexOutOfBoundsException.class, () -> builder.appendChronologyId().toFormatter().parseUnresolved("ISO", new ParsePosition(-1)));
|
||||
}
|
||||
|
||||
@Test(expectedExceptions=IndexOutOfBoundsException.class)
|
||||
@Test
|
||||
public void test_parse_offEndPosition() {
|
||||
builder.appendChronologyId().toFormatter().parseUnresolved("ISO", new ParsePosition(4));
|
||||
Assertions.assertThrows(IndexOutOfBoundsException.class, () -> builder.appendChronologyId().toFormatter().parseUnresolved("ISO", new ParsePosition(4)));
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
@DataProvider(name="parseValid")
|
||||
Object[][] data_parseValid() {
|
||||
return new Object[][] {
|
||||
{"ISO", IsoChronology.INSTANCE},
|
||||
@ -117,35 +119,37 @@ public class TCKChronoPrinterParser {
|
||||
};
|
||||
}
|
||||
|
||||
@Test(dataProvider="parseValid")
|
||||
@ParameterizedTest
|
||||
@MethodSource("data_parseValid")
|
||||
public void test_parseValid_caseSensitive(String text, Chronology expected) {
|
||||
builder.appendChronologyId();
|
||||
TemporalAccessor parsed = builder.toFormatter().parseUnresolved(text, pos);
|
||||
assertEquals(pos.getIndex(), expected.getId().length());
|
||||
assertEquals(pos.getErrorIndex(), -1);
|
||||
assertEquals(parsed.query(TemporalQueries.chronology()), expected);
|
||||
assertEquals(expected.getId().length(), pos.getIndex());
|
||||
assertEquals(-1, pos.getErrorIndex());
|
||||
assertEquals(expected, parsed.query(TemporalQueries.chronology()));
|
||||
}
|
||||
|
||||
@Test(dataProvider="parseValid")
|
||||
@ParameterizedTest
|
||||
@MethodSource("data_parseValid")
|
||||
public void test_parseValid_caseSensitive_lowercaseRejected(String text, Chronology expected) {
|
||||
builder.appendChronologyId();
|
||||
TemporalAccessor parsed = builder.toFormatter().parseUnresolved(text.toLowerCase(Locale.ENGLISH), pos);
|
||||
assertEquals(pos.getIndex(), 0);
|
||||
assertEquals(pos.getErrorIndex(), 0);
|
||||
assertEquals(parsed, null);
|
||||
assertEquals(0, pos.getIndex());
|
||||
assertEquals(0, pos.getErrorIndex());
|
||||
assertEquals(null, parsed);
|
||||
}
|
||||
|
||||
@Test(dataProvider="parseValid")
|
||||
@ParameterizedTest
|
||||
@MethodSource("data_parseValid")
|
||||
public void test_parseValid_caseInsensitive(String text, Chronology expected) {
|
||||
builder.parseCaseInsensitive().appendChronologyId();
|
||||
TemporalAccessor parsed = builder.toFormatter().parseUnresolved(text.toLowerCase(Locale.ENGLISH), pos);
|
||||
assertEquals(pos.getIndex(), expected.getId().length());
|
||||
assertEquals(pos.getErrorIndex(), -1);
|
||||
assertEquals(parsed.query(TemporalQueries.chronology()), expected);
|
||||
assertEquals(expected.getId().length(), pos.getIndex());
|
||||
assertEquals(-1, pos.getErrorIndex());
|
||||
assertEquals(expected, parsed.query(TemporalQueries.chronology()));
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
@DataProvider(name="parseInvalid")
|
||||
Object[][] data_parseInvalid() {
|
||||
return new Object[][] {
|
||||
{"Rubbish"},
|
||||
@ -155,13 +159,14 @@ public class TCKChronoPrinterParser {
|
||||
};
|
||||
}
|
||||
|
||||
@Test(dataProvider="parseInvalid")
|
||||
@ParameterizedTest
|
||||
@MethodSource("data_parseInvalid")
|
||||
public void test_parseInvalid(String text) {
|
||||
builder.appendChronologyId();
|
||||
TemporalAccessor parsed = builder.toFormatter().parseUnresolved(text, pos);
|
||||
assertEquals(pos.getIndex(), 0);
|
||||
assertEquals(pos.getErrorIndex(), 0);
|
||||
assertEquals(parsed, null);
|
||||
assertEquals(0, pos.getIndex());
|
||||
assertEquals(0, pos.getErrorIndex());
|
||||
assertEquals(null, parsed);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2015, 2016, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2015, 2025, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
@ -22,7 +22,6 @@
|
||||
*/
|
||||
package tck.java.time.format;
|
||||
|
||||
import static org.testng.AssertJUnit.assertEquals;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.OffsetDateTime;
|
||||
@ -32,9 +31,11 @@ import java.time.ZonedDateTime;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.util.Locale;
|
||||
|
||||
import org.testng.annotations.BeforeMethod;
|
||||
import org.testng.annotations.DataProvider;
|
||||
import org.testng.annotations.Test;
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.TestInstance;
|
||||
import org.junit.jupiter.params.ParameterizedTest;
|
||||
import org.junit.jupiter.params.provider.MethodSource;
|
||||
|
||||
/**
|
||||
* Testing DateTimeFormatter Parsing with 4 different test conditions:
|
||||
@ -44,7 +45,7 @@ import org.testng.annotations.Test;
|
||||
* 4. When Zone is not provided and Offset is provided
|
||||
*/
|
||||
|
||||
@Test
|
||||
@TestInstance(TestInstance.Lifecycle.PER_CLASS)
|
||||
public class TCKDTFParsedInstant {
|
||||
|
||||
private static final ZoneId EUROPE_BERLIN = ZoneId.of("Europe/Berlin");
|
||||
@ -55,12 +56,11 @@ public class TCKDTFParsedInstant {
|
||||
private LocalDateTime ldt1;
|
||||
private OffsetDateTime odt1;
|
||||
|
||||
@BeforeMethod
|
||||
@BeforeEach
|
||||
public void setUp() throws Exception {
|
||||
dtFormatter = DateTimeFormatter.ISO_ZONED_DATE_TIME;
|
||||
}
|
||||
|
||||
@DataProvider(name="parseWithoutZoneWithoutOffset")
|
||||
Object[][] data_parse_WithoutOffset_WithoutZone() {
|
||||
return new Object[][] {
|
||||
{"1966-12-31T00:01:10", LocalDateTime.of(1966, 12, 31, 0, 1, 10)},
|
||||
@ -70,14 +70,14 @@ public class TCKDTFParsedInstant {
|
||||
};
|
||||
}
|
||||
|
||||
@Test(dataProvider="parseWithoutZoneWithoutOffset")
|
||||
@ParameterizedTest
|
||||
@MethodSource("data_parse_WithoutOffset_WithoutZone")
|
||||
public void testWithoutZoneWithoutOffset(String ldtString, LocalDateTime expectedLDT) {
|
||||
dtFormatter = DateTimeFormatter.ISO_LOCAL_DATE_TIME;
|
||||
ldt1 = LocalDateTime.parse(ldtString, dtFormatter);
|
||||
assertEquals(expectedLDT, ldt1);
|
||||
Assertions.assertEquals(expectedLDT, ldt1);
|
||||
}
|
||||
|
||||
@DataProvider(name="parseWithZoneWithOffset")
|
||||
Object[][] data_parse_WithZone_WithOffset() {
|
||||
return new Object[][] {
|
||||
{"2012-10-28T01:45:00-02:30[Europe/Berlin]",
|
||||
@ -168,15 +168,15 @@ public class TCKDTFParsedInstant {
|
||||
};
|
||||
}
|
||||
|
||||
@Test(dataProvider="parseWithZoneWithOffset")
|
||||
@ParameterizedTest
|
||||
@MethodSource("data_parse_WithZone_WithOffset")
|
||||
public void testWithZoneWithOffset(String zdtString, LocalDateTime ldt, ZoneOffset offset, ZoneId zone) {
|
||||
dtFormatter = DateTimeFormatter.ISO_ZONED_DATE_TIME;
|
||||
zdt1 = ZonedDateTime.ofInstant(ldt, offset, zone);
|
||||
zdt2 = ZonedDateTime.parse(zdtString, dtFormatter);
|
||||
assertEquals(zdt1, zdt2);
|
||||
Assertions.assertEquals(zdt1, zdt2);
|
||||
}
|
||||
|
||||
@DataProvider(name="parseWithZoneWithoutOffset")
|
||||
Object[][] data_parse_WithZone_WithoutOffset() {
|
||||
return new Object[][] {
|
||||
{"28 Oct 00:45:00 2012 Europe/Berlin", ZonedDateTime.of(2012, 10, 28, 0, 45, 0, 0, EUROPE_BERLIN)},
|
||||
@ -193,14 +193,14 @@ public class TCKDTFParsedInstant {
|
||||
};
|
||||
}
|
||||
|
||||
@Test(dataProvider="parseWithZoneWithoutOffset")
|
||||
@ParameterizedTest
|
||||
@MethodSource("data_parse_WithZone_WithoutOffset")
|
||||
public void testWithZoneWithoutOffset(String withZoneWithoutOffset, ZonedDateTime expectedZDT) {
|
||||
dtFormatter = DateTimeFormatter.ofPattern("d MMM HH:mm:ss uuuu VV").withLocale(Locale.ENGLISH);
|
||||
zdt1 = ZonedDateTime.parse(withZoneWithoutOffset, dtFormatter);
|
||||
assertEquals(expectedZDT, zdt1);
|
||||
Assertions.assertEquals(expectedZDT, zdt1);
|
||||
}
|
||||
|
||||
@DataProvider(name="parseWithOffsetWithoutZone")
|
||||
Object[][] data_parse_WithOffset_WithoutZone() {
|
||||
return new Object[][] {
|
||||
{"2015-12-14T00:45:00-11:30", OffsetDateTime.of(2015, 12, 14, 0, 45, 0, 0, ZoneOffset.of("-11:30"))},
|
||||
@ -212,10 +212,11 @@ public class TCKDTFParsedInstant {
|
||||
};
|
||||
}
|
||||
|
||||
@Test(dataProvider="parseWithOffsetWithoutZone")
|
||||
@ParameterizedTest
|
||||
@MethodSource("data_parse_WithOffset_WithoutZone")
|
||||
public void testWithOffsetWithoutZone(String odtString, OffsetDateTime expectedOTD) {
|
||||
dtFormatter = DateTimeFormatter.ISO_OFFSET_DATE_TIME;
|
||||
odt1 = OffsetDateTime.parse(odtString, dtFormatter);
|
||||
assertEquals(expectedOTD, odt1);
|
||||
Assertions.assertEquals(expectedOTD, odt1);
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2012, 2013, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2012, 2026, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
@ -65,10 +65,11 @@ import static java.time.temporal.ChronoField.DAY_OF_YEAR;
|
||||
import static java.time.temporal.ChronoField.HOUR_OF_DAY;
|
||||
import static java.time.temporal.ChronoField.MONTH_OF_YEAR;
|
||||
import static java.time.temporal.ChronoField.YEAR;
|
||||
import static org.testng.Assert.assertEquals;
|
||||
import static org.testng.Assert.assertNull;
|
||||
import static org.testng.Assert.assertTrue;
|
||||
import static org.testng.Assert.fail;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertNull;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
import static org.junit.jupiter.api.Assertions.fail;
|
||||
|
||||
import java.text.Format;
|
||||
import java.text.ParseException;
|
||||
@ -105,14 +106,17 @@ import java.util.HashSet;
|
||||
import java.util.Locale;
|
||||
import java.util.Set;
|
||||
|
||||
import org.testng.annotations.BeforeMethod;
|
||||
import org.testng.annotations.DataProvider;
|
||||
import org.testng.annotations.Test;
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.TestInstance;
|
||||
import org.junit.jupiter.params.ParameterizedTest;
|
||||
import org.junit.jupiter.params.provider.MethodSource;
|
||||
|
||||
/**
|
||||
* Test DateTimeFormatter.
|
||||
*/
|
||||
@Test
|
||||
@TestInstance(TestInstance.Lifecycle.PER_CLASS)
|
||||
public class TCKDateTimeFormatter {
|
||||
|
||||
private static final ZoneOffset OFFSET_PONE = ZoneOffset.ofHours(1);
|
||||
@ -124,7 +128,7 @@ public class TCKDateTimeFormatter {
|
||||
|
||||
private DateTimeFormatter fmt;
|
||||
|
||||
@BeforeMethod
|
||||
@BeforeEach
|
||||
public void setUp() {
|
||||
fmt = new DateTimeFormatterBuilder().appendLiteral("ONE")
|
||||
.appendValue(DAY_OF_MONTH, 1, 2, SignStyle.NOT_NEGATIVE)
|
||||
@ -136,37 +140,39 @@ public class TCKDateTimeFormatter {
|
||||
public void test_withLocale() {
|
||||
DateTimeFormatter base = fmt.withLocale(Locale.ENGLISH).withDecimalStyle(DecimalStyle.STANDARD);
|
||||
DateTimeFormatter test = base.withLocale(Locale.GERMAN);
|
||||
assertEquals(test.getLocale(), Locale.GERMAN);
|
||||
assertEquals(Locale.GERMAN, test.getLocale());
|
||||
}
|
||||
|
||||
@Test(expectedExceptions=NullPointerException.class)
|
||||
@Test
|
||||
public void test_withLocale_null() {
|
||||
DateTimeFormatter base = fmt.withLocale(Locale.ENGLISH).withDecimalStyle(DecimalStyle.STANDARD);
|
||||
base.withLocale((Locale) null);
|
||||
Assertions.assertThrows(NullPointerException.class, () -> {
|
||||
DateTimeFormatter base = fmt.withLocale(Locale.ENGLISH).withDecimalStyle(DecimalStyle.STANDARD);
|
||||
base.withLocale((Locale) null);
|
||||
});
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
@Test
|
||||
public void test_withChronology() {
|
||||
DateTimeFormatter test = fmt;
|
||||
assertEquals(test.getChronology(), null);
|
||||
assertEquals(null, test.getChronology());
|
||||
test = test.withChronology(IsoChronology.INSTANCE);
|
||||
assertEquals(test.getChronology(), IsoChronology.INSTANCE);
|
||||
assertEquals(IsoChronology.INSTANCE, test.getChronology());
|
||||
test = test.withChronology(null);
|
||||
assertEquals(test.getChronology(), null);
|
||||
assertEquals(null, test.getChronology());
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
@Test
|
||||
public void test_withZone() {
|
||||
DateTimeFormatter test = fmt;
|
||||
assertEquals(test.getZone(), null);
|
||||
assertEquals(null, test.getZone());
|
||||
test = test.withZone(ZoneId.of("Europe/Paris"));
|
||||
assertEquals(test.getZone(), ZoneId.of("Europe/Paris"));
|
||||
assertEquals(ZoneId.of("Europe/Paris"), test.getZone());
|
||||
test = test.withZone(ZoneOffset.UTC);
|
||||
assertEquals(test.getZone(), ZoneOffset.UTC);
|
||||
assertEquals(ZoneOffset.UTC, test.getZone());
|
||||
test = test.withZone(null);
|
||||
assertEquals(test.getZone(), null);
|
||||
assertEquals(null, test.getZone());
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
@ -183,7 +189,7 @@ public class TCKDateTimeFormatter {
|
||||
// expected, fails as it produces two different dates
|
||||
}
|
||||
LocalDate parsed = f.parse("2012-6-30-321", LocalDate::from); // ignored day-of-year
|
||||
assertEquals(parsed, LocalDate.of(2012, 6, 30));
|
||||
assertEquals(LocalDate.of(2012, 6, 30), parsed);
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -193,8 +199,7 @@ public class TCKDateTimeFormatter {
|
||||
.appendValue(DAY_OF_MONTH).appendLiteral('-').appendValue(DAY_OF_YEAR).toFormatter();
|
||||
DateTimeFormatter f = base.withResolverFields(YEAR, DAY_OF_YEAR);
|
||||
Set<TemporalField> expected = new HashSet<>(Arrays.asList(YEAR, DAY_OF_YEAR));
|
||||
// Use set.equals(); testNG comparison of Collections is ordered
|
||||
assertTrue(f.getResolverFields().equals(expected), "ResolveFields: " + f.getResolverFields());
|
||||
assertEquals(expected, f.getResolverFields(), "ResolveFields: " + f.getResolverFields());
|
||||
try {
|
||||
base.parse("2012-6-30-321", LocalDate::from); // wrong month/day-of-month
|
||||
fail();
|
||||
@ -202,7 +207,7 @@ public class TCKDateTimeFormatter {
|
||||
// expected, fails as it produces two different dates
|
||||
}
|
||||
LocalDate parsed = f.parse("2012-6-30-321", LocalDate::from); // ignored month/day-of-month
|
||||
assertEquals(parsed, LocalDate.of(2012, 11, 16));
|
||||
assertEquals(LocalDate.of(2012, 11, 16), parsed);
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -218,7 +223,7 @@ public class TCKDateTimeFormatter {
|
||||
// expected, should fail in cross-check of day-of-week
|
||||
}
|
||||
LocalDate parsed = f.parse("2012-321-1", LocalDate::from); // ignored wrong day-of-week
|
||||
assertEquals(parsed, LocalDate.of(2012, 11, 16));
|
||||
assertEquals(LocalDate.of(2012, 11, 16), parsed);
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -226,7 +231,7 @@ public class TCKDateTimeFormatter {
|
||||
DateTimeFormatter f = new DateTimeFormatterBuilder()
|
||||
.appendValue(YEAR).toFormatter().withResolverFields();
|
||||
TemporalAccessor parsed = f.parse("2012");
|
||||
assertEquals(parsed.isSupported(YEAR), false); // not in the list of resolverFields
|
||||
assertEquals(false, parsed.isSupported(YEAR)); // not in the list of resolverFields
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -234,7 +239,7 @@ public class TCKDateTimeFormatter {
|
||||
DateTimeFormatter f = new DateTimeFormatterBuilder()
|
||||
.appendValue(YEAR).toFormatter().withResolverFields(YEAR);
|
||||
TemporalAccessor parsed = f.parse("2012");
|
||||
assertEquals(parsed.isSupported(YEAR), true);
|
||||
assertEquals(true, parsed.isSupported(YEAR));
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -242,8 +247,8 @@ public class TCKDateTimeFormatter {
|
||||
DateTimeFormatter f = new DateTimeFormatterBuilder()
|
||||
.appendValue(YEAR).toFormatter().withResolverFields(MONTH_OF_YEAR);
|
||||
TemporalAccessor parsed = f.parse("2012");
|
||||
assertEquals(parsed.isSupported(YEAR), false); // not in the list of resolverFields
|
||||
assertEquals(parsed.isSupported(MONTH_OF_YEAR), false);
|
||||
assertEquals(false, parsed.isSupported(YEAR)); // not in the list of resolverFields
|
||||
assertEquals(false, parsed.isSupported(MONTH_OF_YEAR));
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -251,29 +256,28 @@ public class TCKDateTimeFormatter {
|
||||
DateTimeFormatter f = new DateTimeFormatterBuilder()
|
||||
.appendValue(YEAR).toFormatter().withResolverFields((TemporalField) null);
|
||||
TemporalAccessor parsed = f.parse("2012");
|
||||
assertEquals(parsed.isSupported(YEAR), false); // not in the list of resolverFields
|
||||
assertEquals(false, parsed.isSupported(YEAR)); // not in the list of resolverFields
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test_resolverFields_Array_null() throws Exception {
|
||||
DateTimeFormatter f = DateTimeFormatter.ISO_DATE.withResolverFields(MONTH_OF_YEAR);
|
||||
assertEquals(f.getResolverFields().size(), 1);
|
||||
assertEquals(1, f.getResolverFields().size());
|
||||
f = f.withResolverFields((TemporalField[]) null);
|
||||
assertEquals(f.getResolverFields(), null);
|
||||
assertEquals(null, f.getResolverFields());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test_resolverFields_Set_null() throws Exception {
|
||||
DateTimeFormatter f = DateTimeFormatter.ISO_DATE.withResolverFields(MONTH_OF_YEAR);
|
||||
assertEquals(f.getResolverFields().size(), 1);
|
||||
assertEquals(1, f.getResolverFields().size());
|
||||
f = f.withResolverFields((Set<TemporalField>) null);
|
||||
assertEquals(f.getResolverFields(), null);
|
||||
assertEquals(null, f.getResolverFields());
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
// format
|
||||
//-----------------------------------------------------------------------
|
||||
@DataProvider(name="formatWithZoneWithChronology")
|
||||
Object[][] data_format_withZone_withChronology() {
|
||||
YearMonth ym = YearMonth.of(2008, 6);
|
||||
LocalDate ld = LocalDate.of(2008, 6, 30);
|
||||
@ -351,7 +355,8 @@ public class TCKDateTimeFormatter {
|
||||
};
|
||||
}
|
||||
|
||||
@Test(dataProvider="formatWithZoneWithChronology")
|
||||
@ParameterizedTest
|
||||
@MethodSource("data_format_withZone_withChronology")
|
||||
public void test_format_withZone_withChronology(Chronology overrideChrono, ZoneId overrideZone, TemporalAccessor temporal, String expected) {
|
||||
DateTimeFormatter test = new DateTimeFormatterBuilder()
|
||||
.optionalStart().appendValue(YEAR, 4).optionalEnd()
|
||||
@ -363,7 +368,7 @@ public class TCKDateTimeFormatter {
|
||||
.withChronology(overrideChrono).withZone(overrideZone);
|
||||
if (expected != null) {
|
||||
String result = test.format(temporal);
|
||||
assertEquals(result, expected);
|
||||
assertEquals(expected, result);
|
||||
} else {
|
||||
try {
|
||||
test.format(temporal);
|
||||
@ -394,7 +399,7 @@ public class TCKDateTimeFormatter {
|
||||
.toFormatter(Locale.ENGLISH)
|
||||
.withChronology(IsoChronology.INSTANCE);
|
||||
String result = test.format(temporal);
|
||||
assertEquals(result, "2345");
|
||||
assertEquals("2345", result);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
@ -402,19 +407,23 @@ public class TCKDateTimeFormatter {
|
||||
public void test_format_TemporalAccessor_simple() {
|
||||
DateTimeFormatter test = fmt.withLocale(Locale.ENGLISH).withDecimalStyle(DecimalStyle.STANDARD);
|
||||
String result = test.format(LocalDate.of(2008, 6, 30));
|
||||
assertEquals(result, "ONE30");
|
||||
assertEquals("ONE30", result);
|
||||
}
|
||||
|
||||
@Test(expectedExceptions = DateTimeException.class)
|
||||
@Test
|
||||
public void test_format_TemporalAccessor_noSuchField() {
|
||||
DateTimeFormatter test = fmt.withLocale(Locale.ENGLISH).withDecimalStyle(DecimalStyle.STANDARD);
|
||||
test.format(LocalTime.of(11, 30));
|
||||
Assertions.assertThrows(DateTimeException.class, () -> {
|
||||
DateTimeFormatter test = fmt.withLocale(Locale.ENGLISH).withDecimalStyle(DecimalStyle.STANDARD);
|
||||
test.format(LocalTime.of(11, 30));
|
||||
});
|
||||
}
|
||||
|
||||
@Test(expectedExceptions = NullPointerException.class)
|
||||
@Test
|
||||
public void test_format_TemporalAccessor_null() {
|
||||
DateTimeFormatter test = fmt.withLocale(Locale.ENGLISH).withDecimalStyle(DecimalStyle.STANDARD);
|
||||
test.format((TemporalAccessor) null);
|
||||
Assertions.assertThrows(NullPointerException.class, () -> {
|
||||
DateTimeFormatter test = fmt.withLocale(Locale.ENGLISH).withDecimalStyle(DecimalStyle.STANDARD);
|
||||
test.format((TemporalAccessor) null);
|
||||
});
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
@ -423,27 +432,33 @@ public class TCKDateTimeFormatter {
|
||||
DateTimeFormatter test = fmt.withLocale(Locale.ENGLISH).withDecimalStyle(DecimalStyle.STANDARD);
|
||||
StringBuilder buf = new StringBuilder();
|
||||
test.formatTo(LocalDate.of(2008, 6, 30), buf);
|
||||
assertEquals(buf.toString(), "ONE30");
|
||||
assertEquals("ONE30", buf.toString());
|
||||
}
|
||||
|
||||
@Test(expectedExceptions=DateTimeException.class)
|
||||
@Test
|
||||
public void test_print_TemporalAppendable_noSuchField() throws Exception {
|
||||
DateTimeFormatter test = fmt.withLocale(Locale.ENGLISH).withDecimalStyle(DecimalStyle.STANDARD);
|
||||
StringBuilder buf = new StringBuilder();
|
||||
test.formatTo(LocalTime.of(11, 30), buf);
|
||||
Assertions.assertThrows(DateTimeException.class, () -> {
|
||||
DateTimeFormatter test = fmt.withLocale(Locale.ENGLISH).withDecimalStyle(DecimalStyle.STANDARD);
|
||||
StringBuilder buf = new StringBuilder();
|
||||
test.formatTo(LocalTime.of(11, 30), buf);
|
||||
});
|
||||
}
|
||||
|
||||
@Test(expectedExceptions=NullPointerException.class)
|
||||
@Test
|
||||
public void test_print_TemporalAppendable_nullTemporal() throws Exception {
|
||||
DateTimeFormatter test = fmt.withLocale(Locale.ENGLISH).withDecimalStyle(DecimalStyle.STANDARD);
|
||||
StringBuilder buf = new StringBuilder();
|
||||
test.formatTo((TemporalAccessor) null, buf);
|
||||
Assertions.assertThrows(NullPointerException.class, () -> {
|
||||
DateTimeFormatter test = fmt.withLocale(Locale.ENGLISH).withDecimalStyle(DecimalStyle.STANDARD);
|
||||
StringBuilder buf = new StringBuilder();
|
||||
test.formatTo((TemporalAccessor) null, buf);
|
||||
});
|
||||
}
|
||||
|
||||
@Test(expectedExceptions=NullPointerException.class)
|
||||
@Test
|
||||
public void test_print_TemporalAppendable_nullAppendable() throws Exception {
|
||||
DateTimeFormatter test = fmt.withLocale(Locale.ENGLISH).withDecimalStyle(DecimalStyle.STANDARD);
|
||||
test.formatTo(LocalDate.of(2008, 6, 30), (Appendable) null);
|
||||
Assertions.assertThrows(NullPointerException.class, () -> {
|
||||
DateTimeFormatter test = fmt.withLocale(Locale.ENGLISH).withDecimalStyle(DecimalStyle.STANDARD);
|
||||
test.formatTo(LocalDate.of(2008, 6, 30), (Appendable) null);
|
||||
});
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
@ -453,29 +468,31 @@ public class TCKDateTimeFormatter {
|
||||
public void test_parse_CharSequence() {
|
||||
DateTimeFormatter test = fmt.withLocale(Locale.ENGLISH).withDecimalStyle(DecimalStyle.STANDARD);
|
||||
TemporalAccessor result = test.parse("ONE30");
|
||||
assertEquals(result.isSupported(DAY_OF_MONTH), true);
|
||||
assertEquals(result.getLong(DAY_OF_MONTH), 30L);
|
||||
assertEquals(result.isSupported(HOUR_OF_DAY), false);
|
||||
assertEquals(true, result.isSupported(DAY_OF_MONTH));
|
||||
assertEquals(30L, result.getLong(DAY_OF_MONTH));
|
||||
assertEquals(false, result.isSupported(HOUR_OF_DAY));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test_parse_CharSequence_resolved() {
|
||||
DateTimeFormatter test = DateTimeFormatter.ISO_DATE;
|
||||
TemporalAccessor result = test.parse("2012-06-30");
|
||||
assertEquals(result.isSupported(YEAR), true);
|
||||
assertEquals(result.isSupported(MONTH_OF_YEAR), true);
|
||||
assertEquals(result.isSupported(DAY_OF_MONTH), true);
|
||||
assertEquals(result.isSupported(HOUR_OF_DAY), false);
|
||||
assertEquals(result.getLong(YEAR), 2012L);
|
||||
assertEquals(result.getLong(MONTH_OF_YEAR), 6L);
|
||||
assertEquals(result.getLong(DAY_OF_MONTH), 30L);
|
||||
assertEquals(result.query(LocalDate::from), LocalDate.of(2012, 6, 30));
|
||||
assertEquals(true, result.isSupported(YEAR));
|
||||
assertEquals(true, result.isSupported(MONTH_OF_YEAR));
|
||||
assertEquals(true, result.isSupported(DAY_OF_MONTH));
|
||||
assertEquals(false, result.isSupported(HOUR_OF_DAY));
|
||||
assertEquals(2012L, result.getLong(YEAR));
|
||||
assertEquals(6L, result.getLong(MONTH_OF_YEAR));
|
||||
assertEquals(30L, result.getLong(DAY_OF_MONTH));
|
||||
assertEquals(LocalDate.of(2012, 6, 30), result.query(LocalDate::from));
|
||||
}
|
||||
|
||||
@Test(expectedExceptions=NullPointerException.class)
|
||||
@Test
|
||||
public void test_parse_CharSequence_null() {
|
||||
DateTimeFormatter test = fmt.withLocale(Locale.ENGLISH).withDecimalStyle(DecimalStyle.STANDARD);
|
||||
test.parse((String) null);
|
||||
Assertions.assertThrows(NullPointerException.class, () -> {
|
||||
DateTimeFormatter test = fmt.withLocale(Locale.ENGLISH).withDecimalStyle(DecimalStyle.STANDARD);
|
||||
test.parse((String) null);
|
||||
});
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
@ -486,11 +503,11 @@ public class TCKDateTimeFormatter {
|
||||
DateTimeFormatter test = fmt.withLocale(Locale.ENGLISH).withDecimalStyle(DecimalStyle.STANDARD);
|
||||
ParsePosition pos = new ParsePosition(3);
|
||||
TemporalAccessor result = test.parse("XXXONE30XXX", pos);
|
||||
assertEquals(pos.getIndex(), 8);
|
||||
assertEquals(pos.getErrorIndex(), -1);
|
||||
assertEquals(result.isSupported(DAY_OF_MONTH), true);
|
||||
assertEquals(result.getLong(DAY_OF_MONTH), 30L);
|
||||
assertEquals(result.isSupported(HOUR_OF_DAY), false);
|
||||
assertEquals(8, pos.getIndex());
|
||||
assertEquals(-1, pos.getErrorIndex());
|
||||
assertEquals(true, result.isSupported(DAY_OF_MONTH));
|
||||
assertEquals(30L, result.getLong(DAY_OF_MONTH));
|
||||
assertEquals(false, result.isSupported(HOUR_OF_DAY));
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -498,47 +515,55 @@ public class TCKDateTimeFormatter {
|
||||
DateTimeFormatter test = DateTimeFormatter.ISO_DATE;
|
||||
ParsePosition pos = new ParsePosition(3);
|
||||
TemporalAccessor result = test.parse("XXX2012-06-30XXX", pos);
|
||||
assertEquals(pos.getIndex(), 13);
|
||||
assertEquals(pos.getErrorIndex(), -1);
|
||||
assertEquals(result.isSupported(YEAR), true);
|
||||
assertEquals(result.isSupported(MONTH_OF_YEAR), true);
|
||||
assertEquals(result.isSupported(DAY_OF_MONTH), true);
|
||||
assertEquals(result.isSupported(HOUR_OF_DAY), false);
|
||||
assertEquals(result.getLong(YEAR), 2012L);
|
||||
assertEquals(result.getLong(MONTH_OF_YEAR), 6L);
|
||||
assertEquals(result.getLong(DAY_OF_MONTH), 30L);
|
||||
assertEquals(result.query(LocalDate::from), LocalDate.of(2012, 6, 30));
|
||||
assertEquals(13, pos.getIndex());
|
||||
assertEquals(-1, pos.getErrorIndex());
|
||||
assertEquals(true, result.isSupported(YEAR));
|
||||
assertEquals(true, result.isSupported(MONTH_OF_YEAR));
|
||||
assertEquals(true, result.isSupported(DAY_OF_MONTH));
|
||||
assertEquals(false, result.isSupported(HOUR_OF_DAY));
|
||||
assertEquals(2012L, result.getLong(YEAR));
|
||||
assertEquals(6L, result.getLong(MONTH_OF_YEAR));
|
||||
assertEquals(30L, result.getLong(DAY_OF_MONTH));
|
||||
assertEquals(LocalDate.of(2012, 6, 30), result.query(LocalDate::from));
|
||||
}
|
||||
|
||||
@Test(expectedExceptions=DateTimeParseException.class)
|
||||
@Test
|
||||
public void test_parse_CharSequence_ParsePosition_parseError() {
|
||||
DateTimeFormatter test = DateTimeFormatter.ISO_DATE;
|
||||
ParsePosition pos = new ParsePosition(3);
|
||||
try {
|
||||
test.parse("XXX2012XXX", pos);
|
||||
fail();
|
||||
} catch (DateTimeParseException ex) {
|
||||
assertEquals(ex.getErrorIndex(), 7);
|
||||
throw ex;
|
||||
}
|
||||
Assertions.assertThrows(DateTimeParseException.class, () -> {
|
||||
DateTimeFormatter test = DateTimeFormatter.ISO_DATE;
|
||||
ParsePosition pos = new ParsePosition(3);
|
||||
try {
|
||||
test.parse("XXX2012XXX", pos);
|
||||
fail();
|
||||
} catch (DateTimeParseException ex) {
|
||||
assertEquals(7, ex.getErrorIndex());
|
||||
throw ex;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Test(expectedExceptions=IndexOutOfBoundsException.class)
|
||||
@Test
|
||||
public void test_parse_CharSequence_ParsePosition_indexTooBig() {
|
||||
DateTimeFormatter test = DateTimeFormatter.ISO_DATE;
|
||||
test.parse("Text", new ParsePosition(5));
|
||||
Assertions.assertThrows(IndexOutOfBoundsException.class, () -> {
|
||||
DateTimeFormatter test = DateTimeFormatter.ISO_DATE;
|
||||
test.parse("Text", new ParsePosition(5));
|
||||
});
|
||||
}
|
||||
|
||||
@Test(expectedExceptions=NullPointerException.class)
|
||||
@Test
|
||||
public void test_parse_CharSequence_ParsePosition_nullText() {
|
||||
DateTimeFormatter test = fmt.withLocale(Locale.ENGLISH).withDecimalStyle(DecimalStyle.STANDARD);
|
||||
test.parse((CharSequence) null, new ParsePosition(0));
|
||||
Assertions.assertThrows(NullPointerException.class, () -> {
|
||||
DateTimeFormatter test = fmt.withLocale(Locale.ENGLISH).withDecimalStyle(DecimalStyle.STANDARD);
|
||||
test.parse((CharSequence) null, new ParsePosition(0));
|
||||
});
|
||||
}
|
||||
|
||||
@Test(expectedExceptions=NullPointerException.class)
|
||||
@Test
|
||||
public void test_parse_CharSequence_ParsePosition_nullParsePosition() {
|
||||
DateTimeFormatter test = fmt.withLocale(Locale.ENGLISH).withDecimalStyle(DecimalStyle.STANDARD);
|
||||
test.parse("Text", (ParsePosition) null);
|
||||
Assertions.assertThrows(NullPointerException.class, () -> {
|
||||
DateTimeFormatter test = fmt.withLocale(Locale.ENGLISH).withDecimalStyle(DecimalStyle.STANDARD);
|
||||
test.parse("Text", (ParsePosition) null);
|
||||
});
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
@ -547,63 +572,71 @@ public class TCKDateTimeFormatter {
|
||||
@Test
|
||||
public void test_parse_Query_String() throws Exception {
|
||||
LocalDate result = DATE_FORMATTER.parse("ONE2012 07 27", LocalDate::from);
|
||||
assertEquals(result, LocalDate.of(2012, 7, 27));
|
||||
assertEquals(LocalDate.of(2012, 7, 27), result);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test_parse_Query_CharSequence() throws Exception {
|
||||
LocalDate result = DATE_FORMATTER.parse(new StringBuilder("ONE2012 07 27"), LocalDate::from);
|
||||
assertEquals(result, LocalDate.of(2012, 7, 27));
|
||||
assertEquals(LocalDate.of(2012, 7, 27), result);
|
||||
}
|
||||
|
||||
@Test(expectedExceptions=DateTimeParseException.class)
|
||||
@Test
|
||||
public void test_parse_Query_String_parseError() throws Exception {
|
||||
try {
|
||||
DATE_FORMATTER.parse("ONE2012 07 XX", LocalDate::from);
|
||||
} catch (DateTimeParseException ex) {
|
||||
assertEquals(ex.getMessage().contains("could not be parsed"), true);
|
||||
assertEquals(ex.getMessage().contains("ONE2012 07 XX"), true);
|
||||
assertEquals(ex.getParsedString(), "ONE2012 07 XX");
|
||||
assertEquals(ex.getErrorIndex(), 11);
|
||||
throw ex;
|
||||
}
|
||||
Assertions.assertThrows(DateTimeParseException.class, () -> {
|
||||
try {
|
||||
DATE_FORMATTER.parse("ONE2012 07 XX", LocalDate::from);
|
||||
} catch (DateTimeParseException ex) {
|
||||
assertEquals(true, ex.getMessage().contains("could not be parsed"));
|
||||
assertEquals(true, ex.getMessage().contains("ONE2012 07 XX"));
|
||||
assertEquals("ONE2012 07 XX", ex.getParsedString());
|
||||
assertEquals(11, ex.getErrorIndex());
|
||||
throw ex;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Test(expectedExceptions=DateTimeParseException.class)
|
||||
@Test
|
||||
public void test_parse_Query_String_parseErrorLongText() throws Exception {
|
||||
try {
|
||||
DATE_FORMATTER.parse("ONEXXX67890123456789012345678901234567890123456789012345678901234567890123456789", LocalDate::from);
|
||||
} catch (DateTimeParseException ex) {
|
||||
assertEquals(ex.getMessage().contains("could not be parsed"), true);
|
||||
assertEquals(ex.getMessage().contains("ONEXXX6789012345678901234567890123456789012345678901234567890123..."), true);
|
||||
assertEquals(ex.getParsedString(), "ONEXXX67890123456789012345678901234567890123456789012345678901234567890123456789");
|
||||
assertEquals(ex.getErrorIndex(), 3);
|
||||
throw ex;
|
||||
}
|
||||
Assertions.assertThrows(DateTimeParseException.class, () -> {
|
||||
try {
|
||||
DATE_FORMATTER.parse("ONEXXX67890123456789012345678901234567890123456789012345678901234567890123456789", LocalDate::from);
|
||||
} catch (DateTimeParseException ex) {
|
||||
assertEquals(true, ex.getMessage().contains("could not be parsed"));
|
||||
assertEquals(true, ex.getMessage().contains("ONEXXX6789012345678901234567890123456789012345678901234567890123..."));
|
||||
assertEquals("ONEXXX67890123456789012345678901234567890123456789012345678901234567890123456789", ex.getParsedString());
|
||||
assertEquals(3, ex.getErrorIndex());
|
||||
throw ex;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Test(expectedExceptions=DateTimeParseException.class)
|
||||
@Test
|
||||
public void test_parse_Query_String_parseIncomplete() throws Exception {
|
||||
try {
|
||||
DATE_FORMATTER.parse("ONE2012 07 27SomethingElse", LocalDate::from);
|
||||
} catch (DateTimeParseException ex) {
|
||||
assertEquals(ex.getMessage().contains("could not be parsed"), true);
|
||||
assertEquals(ex.getMessage().contains("ONE2012 07 27SomethingElse"), true);
|
||||
assertEquals(ex.getParsedString(), "ONE2012 07 27SomethingElse");
|
||||
assertEquals(ex.getErrorIndex(), 13);
|
||||
throw ex;
|
||||
}
|
||||
Assertions.assertThrows(DateTimeParseException.class, () -> {
|
||||
try {
|
||||
DATE_FORMATTER.parse("ONE2012 07 27SomethingElse", LocalDate::from);
|
||||
} catch (DateTimeParseException ex) {
|
||||
assertEquals(true, ex.getMessage().contains("could not be parsed"));
|
||||
assertEquals(true, ex.getMessage().contains("ONE2012 07 27SomethingElse"));
|
||||
assertEquals("ONE2012 07 27SomethingElse", ex.getParsedString());
|
||||
assertEquals(13, ex.getErrorIndex());
|
||||
throw ex;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Test(expectedExceptions=NullPointerException.class)
|
||||
@Test
|
||||
public void test_parse_Query_String_nullText() throws Exception {
|
||||
DATE_FORMATTER.parse((String) null, LocalDate::from);
|
||||
Assertions.assertThrows(NullPointerException.class, () -> DATE_FORMATTER.parse((String) null, LocalDate::from));
|
||||
}
|
||||
|
||||
@Test(expectedExceptions=NullPointerException.class)
|
||||
@Test
|
||||
public void test_parse_Query_String_nullRule() throws Exception {
|
||||
DateTimeFormatter test = fmt.withLocale(Locale.ENGLISH).withDecimalStyle(DecimalStyle.STANDARD);
|
||||
test.parse("30", (TemporalQuery<?>) null);
|
||||
Assertions.assertThrows(NullPointerException.class, () -> {
|
||||
DateTimeFormatter test = fmt.withLocale(Locale.ENGLISH).withDecimalStyle(DecimalStyle.STANDARD);
|
||||
test.parse("30", (TemporalQuery<?>) null);
|
||||
});
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
@ -612,80 +645,94 @@ public class TCKDateTimeFormatter {
|
||||
DateTimeFormatter test = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm[XXX]");
|
||||
TemporalAccessor result = test.parseBest("2011-06-30 12:30+03:00", ZonedDateTime::from, LocalDateTime::from);
|
||||
LocalDateTime ldt = LocalDateTime.of(2011, 6, 30, 12, 30);
|
||||
assertEquals(result, ZonedDateTime.of(ldt, ZoneOffset.ofHours(3)));
|
||||
assertEquals(ZonedDateTime.of(ldt, ZoneOffset.ofHours(3)), result);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test_parseBest_secondOption() throws Exception {
|
||||
DateTimeFormatter test = DateTimeFormatter.ofPattern("yyyy-MM-dd[ HH:mm[XXX]]");
|
||||
TemporalAccessor result = test.parseBest("2011-06-30", ZonedDateTime::from, LocalDate::from);
|
||||
assertEquals(result, LocalDate.of(2011, 6, 30));
|
||||
assertEquals(LocalDate.of(2011, 6, 30), result);
|
||||
}
|
||||
|
||||
@Test(expectedExceptions=DateTimeParseException.class)
|
||||
@Test
|
||||
public void test_parseBest_String_parseError() throws Exception {
|
||||
DateTimeFormatter test = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm[XXX]");
|
||||
try {
|
||||
test.parseBest("2011-06-XX", ZonedDateTime::from, LocalDateTime::from);
|
||||
} catch (DateTimeParseException ex) {
|
||||
assertEquals(ex.getMessage().contains("could not be parsed"), true);
|
||||
assertEquals(ex.getMessage().contains("XX"), true);
|
||||
assertEquals(ex.getParsedString(), "2011-06-XX");
|
||||
assertEquals(ex.getErrorIndex(), 8);
|
||||
throw ex;
|
||||
}
|
||||
Assertions.assertThrows(DateTimeParseException.class, () -> {
|
||||
DateTimeFormatter test = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm[XXX]");
|
||||
try {
|
||||
test.parseBest("2011-06-XX", ZonedDateTime::from, LocalDateTime::from);
|
||||
} catch (DateTimeParseException ex) {
|
||||
assertEquals(true, ex.getMessage().contains("could not be parsed"));
|
||||
assertEquals(true, ex.getMessage().contains("XX"));
|
||||
assertEquals("2011-06-XX", ex.getParsedString());
|
||||
assertEquals(8, ex.getErrorIndex());
|
||||
throw ex;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Test(expectedExceptions=DateTimeParseException.class)
|
||||
@Test
|
||||
public void test_parseBest_String_parseErrorLongText() throws Exception {
|
||||
DateTimeFormatter test = fmt.withLocale(Locale.ENGLISH).withDecimalStyle(DecimalStyle.STANDARD);
|
||||
try {
|
||||
test.parseBest("ONEXXX67890123456789012345678901234567890123456789012345678901234567890123456789", ZonedDateTime::from, LocalDate::from);
|
||||
} catch (DateTimeParseException ex) {
|
||||
assertEquals(ex.getMessage().contains("could not be parsed"), true);
|
||||
assertEquals(ex.getMessage().contains("ONEXXX6789012345678901234567890123456789012345678901234567890123..."), true);
|
||||
assertEquals(ex.getParsedString(), "ONEXXX67890123456789012345678901234567890123456789012345678901234567890123456789");
|
||||
assertEquals(ex.getErrorIndex(), 3);
|
||||
throw ex;
|
||||
}
|
||||
Assertions.assertThrows(DateTimeParseException.class, () -> {
|
||||
DateTimeFormatter test = fmt.withLocale(Locale.ENGLISH).withDecimalStyle(DecimalStyle.STANDARD);
|
||||
try {
|
||||
test.parseBest("ONEXXX67890123456789012345678901234567890123456789012345678901234567890123456789", ZonedDateTime::from, LocalDate::from);
|
||||
} catch (DateTimeParseException ex) {
|
||||
assertEquals(true, ex.getMessage().contains("could not be parsed"));
|
||||
assertEquals(true, ex.getMessage().contains("ONEXXX6789012345678901234567890123456789012345678901234567890123..."));
|
||||
assertEquals("ONEXXX67890123456789012345678901234567890123456789012345678901234567890123456789", ex.getParsedString());
|
||||
assertEquals(3, ex.getErrorIndex());
|
||||
throw ex;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Test(expectedExceptions=DateTimeParseException.class)
|
||||
@Test
|
||||
public void test_parseBest_String_parseIncomplete() throws Exception {
|
||||
DateTimeFormatter test = fmt.withLocale(Locale.ENGLISH).withDecimalStyle(DecimalStyle.STANDARD);
|
||||
try {
|
||||
test.parseBest("ONE30SomethingElse", ZonedDateTime::from, LocalDate::from);
|
||||
} catch (DateTimeParseException ex) {
|
||||
assertEquals(ex.getMessage().contains("could not be parsed"), true);
|
||||
assertEquals(ex.getMessage().contains("ONE30SomethingElse"), true);
|
||||
assertEquals(ex.getParsedString(), "ONE30SomethingElse");
|
||||
assertEquals(ex.getErrorIndex(), 5);
|
||||
throw ex;
|
||||
}
|
||||
Assertions.assertThrows(DateTimeParseException.class, () -> {
|
||||
DateTimeFormatter test = fmt.withLocale(Locale.ENGLISH).withDecimalStyle(DecimalStyle.STANDARD);
|
||||
try {
|
||||
test.parseBest("ONE30SomethingElse", ZonedDateTime::from, LocalDate::from);
|
||||
} catch (DateTimeParseException ex) {
|
||||
assertEquals(true, ex.getMessage().contains("could not be parsed"));
|
||||
assertEquals(true, ex.getMessage().contains("ONE30SomethingElse"));
|
||||
assertEquals("ONE30SomethingElse", ex.getParsedString());
|
||||
assertEquals(5, ex.getErrorIndex());
|
||||
throw ex;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Test(expectedExceptions=NullPointerException.class)
|
||||
@Test
|
||||
public void test_parseBest_String_nullText() throws Exception {
|
||||
DateTimeFormatter test = fmt.withLocale(Locale.ENGLISH).withDecimalStyle(DecimalStyle.STANDARD);
|
||||
test.parseBest((String) null, ZonedDateTime::from, LocalDate::from);
|
||||
Assertions.assertThrows(NullPointerException.class, () -> {
|
||||
DateTimeFormatter test = fmt.withLocale(Locale.ENGLISH).withDecimalStyle(DecimalStyle.STANDARD);
|
||||
test.parseBest((String) null, ZonedDateTime::from, LocalDate::from);
|
||||
});
|
||||
}
|
||||
|
||||
@Test(expectedExceptions=NullPointerException.class)
|
||||
@Test
|
||||
public void test_parseBest_String_nullRules() throws Exception {
|
||||
DateTimeFormatter test = fmt.withLocale(Locale.ENGLISH).withDecimalStyle(DecimalStyle.STANDARD);
|
||||
test.parseBest("30", (TemporalQuery<?>[]) null);
|
||||
Assertions.assertThrows(NullPointerException.class, () -> {
|
||||
DateTimeFormatter test = fmt.withLocale(Locale.ENGLISH).withDecimalStyle(DecimalStyle.STANDARD);
|
||||
test.parseBest("30", (TemporalQuery<?>[]) null);
|
||||
});
|
||||
}
|
||||
|
||||
@Test(expectedExceptions=IllegalArgumentException.class)
|
||||
@Test
|
||||
public void test_parseBest_String_zeroRules() throws Exception {
|
||||
DateTimeFormatter test = fmt.withLocale(Locale.ENGLISH).withDecimalStyle(DecimalStyle.STANDARD);
|
||||
test.parseBest("30", new TemporalQuery<?>[0]);
|
||||
Assertions.assertThrows(IllegalArgumentException.class, () -> {
|
||||
DateTimeFormatter test = fmt.withLocale(Locale.ENGLISH).withDecimalStyle(DecimalStyle.STANDARD);
|
||||
test.parseBest("30", new TemporalQuery<?>[0]);
|
||||
});
|
||||
}
|
||||
|
||||
@Test(expectedExceptions=IllegalArgumentException.class)
|
||||
@Test
|
||||
public void test_parseBest_String_oneRule() throws Exception {
|
||||
DateTimeFormatter test = fmt.withLocale(Locale.ENGLISH).withDecimalStyle(DecimalStyle.STANDARD);
|
||||
test.parseBest("30", LocalDate::from);
|
||||
Assertions.assertThrows(IllegalArgumentException.class, () -> {
|
||||
DateTimeFormatter test = fmt.withLocale(Locale.ENGLISH).withDecimalStyle(DecimalStyle.STANDARD);
|
||||
test.parseBest("30", LocalDate::from);
|
||||
});
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
@ -694,9 +741,9 @@ public class TCKDateTimeFormatter {
|
||||
DateTimeFormatter test = fmt.withLocale(Locale.ENGLISH).withDecimalStyle(DecimalStyle.STANDARD);
|
||||
ParsePosition pos = new ParsePosition(0);
|
||||
TemporalAccessor result = test.parseUnresolved("ONE30XXX", pos);
|
||||
assertEquals(pos.getIndex(), 5);
|
||||
assertEquals(pos.getErrorIndex(), -1);
|
||||
assertEquals(result.getLong(DAY_OF_MONTH), 30L);
|
||||
assertEquals(5, pos.getIndex());
|
||||
assertEquals(-1, pos.getErrorIndex());
|
||||
assertEquals(30L, result.getLong(DAY_OF_MONTH));
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -704,9 +751,9 @@ public class TCKDateTimeFormatter {
|
||||
DateTimeFormatter test = fmt.withLocale(Locale.ENGLISH).withDecimalStyle(DecimalStyle.STANDARD);
|
||||
ParsePosition pos = new ParsePosition(0);
|
||||
TemporalAccessor result = test.parseUnresolved("ONEXXX", pos);
|
||||
assertEquals(pos.getIndex(), 0);
|
||||
assertEquals(pos.getErrorIndex(), 3);
|
||||
assertEquals(result, null);
|
||||
assertEquals(0, pos.getIndex());
|
||||
assertEquals(3, pos.getErrorIndex());
|
||||
assertEquals(null, result);
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -715,9 +762,9 @@ public class TCKDateTimeFormatter {
|
||||
.appendValue(MONTH_OF_YEAR).appendLiteral('-').appendValue(MONTH_OF_YEAR).toFormatter();
|
||||
ParsePosition pos = new ParsePosition(3);
|
||||
TemporalAccessor result = test.parseUnresolved("XXX6-6", pos);
|
||||
assertEquals(pos.getIndex(), 6);
|
||||
assertEquals(pos.getErrorIndex(), -1);
|
||||
assertEquals(result.getLong(MONTH_OF_YEAR), 6);
|
||||
assertEquals(6, pos.getIndex());
|
||||
assertEquals(-1, pos.getErrorIndex());
|
||||
assertEquals(6, result.getLong(MONTH_OF_YEAR));
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -726,29 +773,35 @@ public class TCKDateTimeFormatter {
|
||||
.appendValue(MONTH_OF_YEAR).appendLiteral('-').appendValue(MONTH_OF_YEAR).toFormatter();
|
||||
ParsePosition pos = new ParsePosition(3);
|
||||
TemporalAccessor result = test.parseUnresolved("XXX6-7", pos);
|
||||
assertEquals(pos.getIndex(), 3);
|
||||
assertEquals(pos.getErrorIndex(), 5);
|
||||
assertEquals(result, null);
|
||||
assertEquals(3, pos.getIndex());
|
||||
assertEquals(5, pos.getErrorIndex());
|
||||
assertEquals(null, result);
|
||||
}
|
||||
|
||||
@Test(expectedExceptions=NullPointerException.class)
|
||||
@Test
|
||||
public void test_parseUnresolved_StringParsePosition_nullString() {
|
||||
DateTimeFormatter test = fmt.withLocale(Locale.ENGLISH).withDecimalStyle(DecimalStyle.STANDARD);
|
||||
ParsePosition pos = new ParsePosition(0);
|
||||
test.parseUnresolved((String) null, pos);
|
||||
Assertions.assertThrows(NullPointerException.class, () -> {
|
||||
DateTimeFormatter test = fmt.withLocale(Locale.ENGLISH).withDecimalStyle(DecimalStyle.STANDARD);
|
||||
ParsePosition pos = new ParsePosition(0);
|
||||
test.parseUnresolved((String) null, pos);
|
||||
});
|
||||
}
|
||||
|
||||
@Test(expectedExceptions=NullPointerException.class)
|
||||
@Test
|
||||
public void test_parseUnresolved_StringParsePosition_nullParsePosition() {
|
||||
DateTimeFormatter test = fmt.withLocale(Locale.ENGLISH).withDecimalStyle(DecimalStyle.STANDARD);
|
||||
test.parseUnresolved("ONE30", (ParsePosition) null);
|
||||
Assertions.assertThrows(NullPointerException.class, () -> {
|
||||
DateTimeFormatter test = fmt.withLocale(Locale.ENGLISH).withDecimalStyle(DecimalStyle.STANDARD);
|
||||
test.parseUnresolved("ONE30", (ParsePosition) null);
|
||||
});
|
||||
}
|
||||
|
||||
@Test(expectedExceptions=IndexOutOfBoundsException.class)
|
||||
@Test
|
||||
public void test_parseUnresolved_StringParsePosition_invalidPosition() {
|
||||
DateTimeFormatter test = fmt.withLocale(Locale.ENGLISH).withDecimalStyle(DecimalStyle.STANDARD);
|
||||
ParsePosition pos = new ParsePosition(6);
|
||||
test.parseUnresolved("ONE30", pos);
|
||||
Assertions.assertThrows(IndexOutOfBoundsException.class, () -> {
|
||||
DateTimeFormatter test = fmt.withLocale(Locale.ENGLISH).withDecimalStyle(DecimalStyle.STANDARD);
|
||||
ParsePosition pos = new ParsePosition(6);
|
||||
test.parseUnresolved("ONE30", pos);
|
||||
});
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
@ -758,21 +811,25 @@ public class TCKDateTimeFormatter {
|
||||
DateTimeFormatter test = fmt.withLocale(Locale.ENGLISH).withDecimalStyle(DecimalStyle.STANDARD);
|
||||
Format format = test.toFormat();
|
||||
String result = format.format(LocalDate.of(2008, 6, 30));
|
||||
assertEquals(result, "ONE30");
|
||||
assertEquals("ONE30", result);
|
||||
}
|
||||
|
||||
@Test(expectedExceptions=NullPointerException.class)
|
||||
@Test
|
||||
public void test_toFormat_format_null() throws Exception {
|
||||
DateTimeFormatter test = fmt.withLocale(Locale.ENGLISH).withDecimalStyle(DecimalStyle.STANDARD);
|
||||
Format format = test.toFormat();
|
||||
format.format(null);
|
||||
Assertions.assertThrows(NullPointerException.class, () -> {
|
||||
DateTimeFormatter test = fmt.withLocale(Locale.ENGLISH).withDecimalStyle(DecimalStyle.STANDARD);
|
||||
Format format = test.toFormat();
|
||||
format.format(null);
|
||||
});
|
||||
}
|
||||
|
||||
@Test(expectedExceptions=IllegalArgumentException.class)
|
||||
@Test
|
||||
public void test_toFormat_format_notTemporal() throws Exception {
|
||||
DateTimeFormatter test = fmt.withLocale(Locale.ENGLISH).withDecimalStyle(DecimalStyle.STANDARD);
|
||||
Format format = test.toFormat();
|
||||
format.format("Not a Temporal");
|
||||
Assertions.assertThrows(IllegalArgumentException.class, () -> {
|
||||
DateTimeFormatter test = fmt.withLocale(Locale.ENGLISH).withDecimalStyle(DecimalStyle.STANDARD);
|
||||
Format format = test.toFormat();
|
||||
format.format("Not a Temporal");
|
||||
});
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
@ -781,42 +838,48 @@ public class TCKDateTimeFormatter {
|
||||
DateTimeFormatter test = fmt.withLocale(Locale.ENGLISH).withDecimalStyle(DecimalStyle.STANDARD);
|
||||
Format format = test.toFormat();
|
||||
TemporalAccessor result = (TemporalAccessor) format.parseObject("ONE30");
|
||||
assertEquals(result.isSupported(DAY_OF_MONTH), true);
|
||||
assertEquals(result.getLong(DAY_OF_MONTH), 30L);
|
||||
assertEquals(true, result.isSupported(DAY_OF_MONTH));
|
||||
assertEquals(30L, result.getLong(DAY_OF_MONTH));
|
||||
}
|
||||
|
||||
@Test(expectedExceptions=ParseException.class)
|
||||
@Test
|
||||
public void test_toFormat_parseObject_String_parseError() throws Exception {
|
||||
DateTimeFormatter test = fmt.withLocale(Locale.ENGLISH).withDecimalStyle(DecimalStyle.STANDARD);
|
||||
Format format = test.toFormat();
|
||||
try {
|
||||
format.parseObject("ONEXXX");
|
||||
} catch (ParseException ex) {
|
||||
assertEquals(ex.getMessage().contains("ONEXXX"), true);
|
||||
assertEquals(ex.getErrorOffset(), 3);
|
||||
throw ex;
|
||||
}
|
||||
Assertions.assertThrows(ParseException.class, () -> {
|
||||
DateTimeFormatter test = fmt.withLocale(Locale.ENGLISH).withDecimalStyle(DecimalStyle.STANDARD);
|
||||
Format format = test.toFormat();
|
||||
try {
|
||||
format.parseObject("ONEXXX");
|
||||
} catch (ParseException ex) {
|
||||
assertEquals(true, ex.getMessage().contains("ONEXXX"));
|
||||
assertEquals(3, ex.getErrorOffset());
|
||||
throw ex;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Test(expectedExceptions=ParseException.class)
|
||||
@Test
|
||||
public void test_toFormat_parseObject_String_parseErrorLongText() throws Exception {
|
||||
DateTimeFormatter test = fmt.withLocale(Locale.ENGLISH).withDecimalStyle(DecimalStyle.STANDARD);
|
||||
Format format = test.toFormat();
|
||||
try {
|
||||
format.parseObject("ONEXXX67890123456789012345678901234567890123456789012345678901234567890123456789");
|
||||
} catch (DateTimeParseException ex) {
|
||||
assertEquals(ex.getMessage().contains("ONEXXX6789012345678901234567890123456789012345678901234567890123..."), true);
|
||||
assertEquals(ex.getParsedString(), "ONEXXX67890123456789012345678901234567890123456789012345678901234567890123456789");
|
||||
assertEquals(ex.getErrorIndex(), 3);
|
||||
throw ex;
|
||||
}
|
||||
Assertions.assertThrows(ParseException.class, () -> {
|
||||
DateTimeFormatter test = fmt.withLocale(Locale.ENGLISH).withDecimalStyle(DecimalStyle.STANDARD);
|
||||
Format format = test.toFormat();
|
||||
try {
|
||||
format.parseObject("ONEXXX67890123456789012345678901234567890123456789012345678901234567890123456789");
|
||||
} catch (DateTimeParseException ex) {
|
||||
assertEquals(true, ex.getMessage().contains("ONEXXX6789012345678901234567890123456789012345678901234567890123..."));
|
||||
assertEquals("ONEXXX67890123456789012345678901234567890123456789012345678901234567890123456789", ex.getParsedString());
|
||||
assertEquals(3, ex.getErrorIndex());
|
||||
throw ex;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Test(expectedExceptions=NullPointerException.class)
|
||||
@Test
|
||||
public void test_toFormat_parseObject_String_null() throws Exception {
|
||||
DateTimeFormatter test = fmt.withLocale(Locale.ENGLISH).withDecimalStyle(DecimalStyle.STANDARD);
|
||||
Format format = test.toFormat();
|
||||
format.parseObject((String) null);
|
||||
Assertions.assertThrows(NullPointerException.class, () -> {
|
||||
DateTimeFormatter test = fmt.withLocale(Locale.ENGLISH).withDecimalStyle(DecimalStyle.STANDARD);
|
||||
Format format = test.toFormat();
|
||||
format.parseObject((String) null);
|
||||
});
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
@ -826,10 +889,10 @@ public class TCKDateTimeFormatter {
|
||||
Format format = test.toFormat();
|
||||
ParsePosition pos = new ParsePosition(0);
|
||||
TemporalAccessor result = (TemporalAccessor) format.parseObject("ONE30XXX", pos);
|
||||
assertEquals(pos.getIndex(), 5);
|
||||
assertEquals(pos.getErrorIndex(), -1);
|
||||
assertEquals(result.isSupported(DAY_OF_MONTH), true);
|
||||
assertEquals(result.getLong(DAY_OF_MONTH), 30L);
|
||||
assertEquals(5, pos.getIndex());
|
||||
assertEquals(-1, pos.getErrorIndex());
|
||||
assertEquals(true, result.isSupported(DAY_OF_MONTH));
|
||||
assertEquals(30L, result.getLong(DAY_OF_MONTH));
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -838,26 +901,30 @@ public class TCKDateTimeFormatter {
|
||||
Format format = test.toFormat();
|
||||
ParsePosition pos = new ParsePosition(0);
|
||||
TemporalAccessor result = (TemporalAccessor) format.parseObject("ONEXXX", pos);
|
||||
assertEquals(pos.getIndex(), 0); // TODO: is this right?
|
||||
assertEquals(pos.getErrorIndex(), 3);
|
||||
assertEquals(result, null);
|
||||
assertEquals(0, pos.getIndex()); // TODO: is this right?
|
||||
assertEquals(3, pos.getErrorIndex());
|
||||
assertEquals(null, result);
|
||||
}
|
||||
|
||||
@Test(expectedExceptions=NullPointerException.class)
|
||||
@Test
|
||||
public void test_toFormat_parseObject_StringParsePosition_nullString() throws Exception {
|
||||
// SimpleDateFormat has this behavior
|
||||
DateTimeFormatter test = fmt.withLocale(Locale.ENGLISH).withDecimalStyle(DecimalStyle.STANDARD);
|
||||
Format format = test.toFormat();
|
||||
ParsePosition pos = new ParsePosition(0);
|
||||
format.parseObject((String) null, pos);
|
||||
Assertions.assertThrows(NullPointerException.class, () -> {
|
||||
// SimpleDateFormat has this behavior
|
||||
DateTimeFormatter test = fmt.withLocale(Locale.ENGLISH).withDecimalStyle(DecimalStyle.STANDARD);
|
||||
Format format = test.toFormat();
|
||||
ParsePosition pos = new ParsePosition(0);
|
||||
format.parseObject((String) null, pos);
|
||||
});
|
||||
}
|
||||
|
||||
@Test(expectedExceptions=NullPointerException.class)
|
||||
@Test
|
||||
public void test_toFormat_parseObject_StringParsePosition_nullParsePosition() throws Exception {
|
||||
// SimpleDateFormat has this behavior
|
||||
DateTimeFormatter test = fmt.withLocale(Locale.ENGLISH).withDecimalStyle(DecimalStyle.STANDARD);
|
||||
Format format = test.toFormat();
|
||||
format.parseObject("ONE30", (ParsePosition) null);
|
||||
Assertions.assertThrows(NullPointerException.class, () -> {
|
||||
// SimpleDateFormat has this behavior
|
||||
DateTimeFormatter test = fmt.withLocale(Locale.ENGLISH).withDecimalStyle(DecimalStyle.STANDARD);
|
||||
Format format = test.toFormat();
|
||||
format.parseObject("ONE30", (ParsePosition) null);
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -885,25 +952,27 @@ public class TCKDateTimeFormatter {
|
||||
public void test_toFormat_Query_format() throws Exception {
|
||||
Format format = BASIC_FORMATTER.toFormat();
|
||||
String result = format.format(LocalDate.of(2008, 6, 30));
|
||||
assertEquals(result, "ONE30");
|
||||
assertEquals("ONE30", result);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test_toFormat_Query_parseObject_String() throws Exception {
|
||||
Format format = DATE_FORMATTER.toFormat(LocalDate::from);
|
||||
LocalDate result = (LocalDate) format.parseObject("ONE2012 07 27");
|
||||
assertEquals(result, LocalDate.of(2012, 7, 27));
|
||||
assertEquals(LocalDate.of(2012, 7, 27), result);
|
||||
}
|
||||
|
||||
@Test(expectedExceptions=ParseException.class)
|
||||
@Test
|
||||
public void test_toFormat_parseObject_StringParsePosition_dateTimeError() throws Exception {
|
||||
Format format = DATE_FORMATTER.toFormat(LocalDate::from);
|
||||
format.parseObject("ONE2012 07 32");
|
||||
Assertions.assertThrows(ParseException.class, () -> {
|
||||
Format format = DATE_FORMATTER.toFormat(LocalDate::from);
|
||||
format.parseObject("ONE2012 07 32");
|
||||
});
|
||||
}
|
||||
|
||||
@Test(expectedExceptions=NullPointerException.class)
|
||||
@Test
|
||||
public void test_toFormat_Query() throws Exception {
|
||||
BASIC_FORMATTER.toFormat(null);
|
||||
Assertions.assertThrows(NullPointerException.class, () -> BASIC_FORMATTER.toFormat(null));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2012, 2013, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2012, 2025, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
@ -70,9 +70,10 @@ import static java.time.temporal.ChronoField.NANO_OF_SECOND;
|
||||
import static java.time.temporal.ChronoField.OFFSET_SECONDS;
|
||||
import static java.time.temporal.ChronoField.SECOND_OF_MINUTE;
|
||||
import static java.time.temporal.ChronoField.YEAR;
|
||||
import static org.testng.Assert.assertEquals;
|
||||
import static org.testng.Assert.assertTrue;
|
||||
import static org.testng.Assert.fail;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
import static org.junit.jupiter.api.Assertions.fail;
|
||||
|
||||
import java.text.ParsePosition;
|
||||
import java.time.DateTimeException;
|
||||
@ -101,24 +102,27 @@ import java.util.Iterator;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
|
||||
import org.testng.annotations.BeforeMethod;
|
||||
import org.testng.annotations.DataProvider;
|
||||
import org.testng.annotations.Test;
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.TestInstance;
|
||||
import org.junit.jupiter.params.ParameterizedTest;
|
||||
import org.junit.jupiter.params.provider.MethodSource;
|
||||
|
||||
/**
|
||||
* Test DateTimeFormatter.
|
||||
*/
|
||||
@Test
|
||||
@TestInstance(TestInstance.Lifecycle.PER_CLASS)
|
||||
public class TCKDateTimeFormatters {
|
||||
|
||||
@BeforeMethod
|
||||
@BeforeEach
|
||||
public void setUp() {
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
@Test(expectedExceptions=NullPointerException.class)
|
||||
@Test
|
||||
public void test_format_nullTemporalAccessor() {
|
||||
DateTimeFormatter.ISO_DATE.format((TemporalAccessor) null);
|
||||
Assertions.assertThrows(NullPointerException.class, () -> DateTimeFormatter.ISO_DATE.format((TemporalAccessor) null));
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
@ -128,19 +132,19 @@ public class TCKDateTimeFormatters {
|
||||
public void test_pattern_String() {
|
||||
DateTimeFormatter test = DateTimeFormatter.ofPattern("d MMM yyyy");
|
||||
Locale fmtLocale = Locale.getDefault(Locale.Category.FORMAT);
|
||||
assertEquals(test.format(LocalDate.of(2012, 6, 30)), "30 " +
|
||||
Month.JUNE.getDisplayName(TextStyle.SHORT, fmtLocale) + " 2012");
|
||||
assertEquals(test.getLocale(), fmtLocale, "Locale.Category.FORMAT");
|
||||
assertEquals("30 " +
|
||||
Month.JUNE.getDisplayName(TextStyle.SHORT, fmtLocale) + " 2012", test.format(LocalDate.of(2012, 6, 30)));
|
||||
assertEquals(fmtLocale, test.getLocale(), "Locale.Category.FORMAT");
|
||||
}
|
||||
|
||||
@Test(expectedExceptions=IllegalArgumentException.class)
|
||||
@Test
|
||||
public void test_pattern_String_invalid() {
|
||||
DateTimeFormatter.ofPattern("p");
|
||||
Assertions.assertThrows(IllegalArgumentException.class, () -> DateTimeFormatter.ofPattern("p"));
|
||||
}
|
||||
|
||||
@Test(expectedExceptions=NullPointerException.class)
|
||||
@Test
|
||||
public void test_pattern_String_null() {
|
||||
DateTimeFormatter.ofPattern(null);
|
||||
Assertions.assertThrows(NullPointerException.class, () -> DateTimeFormatter.ofPattern(null));
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
@ -149,23 +153,23 @@ public class TCKDateTimeFormatters {
|
||||
@Test
|
||||
public void test_pattern_StringLocale() {
|
||||
DateTimeFormatter test = DateTimeFormatter.ofPattern("d MMM yyyy", Locale.UK);
|
||||
assertEquals(test.format(LocalDate.of(2012, 6, 30)), "30 Jun 2012");
|
||||
assertEquals(test.getLocale(), Locale.UK);
|
||||
assertEquals("30 Jun 2012", test.format(LocalDate.of(2012, 6, 30)));
|
||||
assertEquals(Locale.UK, test.getLocale());
|
||||
}
|
||||
|
||||
@Test(expectedExceptions=IllegalArgumentException.class)
|
||||
@Test
|
||||
public void test_pattern_StringLocale_invalid() {
|
||||
DateTimeFormatter.ofPattern("p", Locale.UK);
|
||||
Assertions.assertThrows(IllegalArgumentException.class, () -> DateTimeFormatter.ofPattern("p", Locale.UK));
|
||||
}
|
||||
|
||||
@Test(expectedExceptions=NullPointerException.class)
|
||||
@Test
|
||||
public void test_pattern_StringLocale_nullPattern() {
|
||||
DateTimeFormatter.ofPattern(null, Locale.UK);
|
||||
Assertions.assertThrows(NullPointerException.class, () -> DateTimeFormatter.ofPattern(null, Locale.UK));
|
||||
}
|
||||
|
||||
@Test(expectedExceptions=NullPointerException.class)
|
||||
@Test
|
||||
public void test_pattern_StringLocale_nullLocale() {
|
||||
DateTimeFormatter.ofPattern("yyyy", null);
|
||||
Assertions.assertThrows(NullPointerException.class, () -> DateTimeFormatter.ofPattern("yyyy", null));
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
@ -173,36 +177,35 @@ public class TCKDateTimeFormatters {
|
||||
//-----------------------------------------------------------------------
|
||||
@Test
|
||||
public void test_ofLocalizedDate_basics() {
|
||||
assertEquals(DateTimeFormatter.ofLocalizedDate(FormatStyle.FULL).getChronology(), IsoChronology.INSTANCE);
|
||||
assertEquals(DateTimeFormatter.ofLocalizedDate(FormatStyle.FULL).getZone(), null);
|
||||
assertEquals(DateTimeFormatter.ofLocalizedDate(FormatStyle.FULL).getResolverStyle(), ResolverStyle.SMART);
|
||||
assertEquals(IsoChronology.INSTANCE, DateTimeFormatter.ofLocalizedDate(FormatStyle.FULL).getChronology());
|
||||
assertEquals(null, DateTimeFormatter.ofLocalizedDate(FormatStyle.FULL).getZone());
|
||||
assertEquals(ResolverStyle.SMART, DateTimeFormatter.ofLocalizedDate(FormatStyle.FULL).getResolverStyle());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test_ofLocalizedTime_basics() {
|
||||
assertEquals(DateTimeFormatter.ofLocalizedTime(FormatStyle.FULL).getChronology(), IsoChronology.INSTANCE);
|
||||
assertEquals(DateTimeFormatter.ofLocalizedTime(FormatStyle.FULL).getZone(), null);
|
||||
assertEquals(DateTimeFormatter.ofLocalizedTime(FormatStyle.FULL).getResolverStyle(), ResolverStyle.SMART);
|
||||
assertEquals(IsoChronology.INSTANCE, DateTimeFormatter.ofLocalizedTime(FormatStyle.FULL).getChronology());
|
||||
assertEquals(null, DateTimeFormatter.ofLocalizedTime(FormatStyle.FULL).getZone());
|
||||
assertEquals(ResolverStyle.SMART, DateTimeFormatter.ofLocalizedTime(FormatStyle.FULL).getResolverStyle());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test_ofLocalizedDateTime1_basics() {
|
||||
assertEquals(DateTimeFormatter.ofLocalizedDateTime(FormatStyle.FULL).getChronology(), IsoChronology.INSTANCE);
|
||||
assertEquals(DateTimeFormatter.ofLocalizedDateTime(FormatStyle.FULL).getZone(), null);
|
||||
assertEquals(DateTimeFormatter.ofLocalizedDateTime(FormatStyle.FULL).getResolverStyle(), ResolverStyle.SMART);
|
||||
assertEquals(IsoChronology.INSTANCE, DateTimeFormatter.ofLocalizedDateTime(FormatStyle.FULL).getChronology());
|
||||
assertEquals(null, DateTimeFormatter.ofLocalizedDateTime(FormatStyle.FULL).getZone());
|
||||
assertEquals(ResolverStyle.SMART, DateTimeFormatter.ofLocalizedDateTime(FormatStyle.FULL).getResolverStyle());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test_ofLocalizedDateTime2_basics() {
|
||||
assertEquals(DateTimeFormatter.ofLocalizedDateTime(FormatStyle.FULL, FormatStyle.MEDIUM).getChronology(), IsoChronology.INSTANCE);
|
||||
assertEquals(DateTimeFormatter.ofLocalizedDateTime(FormatStyle.FULL, FormatStyle.MEDIUM).getZone(), null);
|
||||
assertEquals(DateTimeFormatter.ofLocalizedDateTime(FormatStyle.FULL, FormatStyle.MEDIUM).getResolverStyle(), ResolverStyle.SMART);
|
||||
assertEquals(IsoChronology.INSTANCE, DateTimeFormatter.ofLocalizedDateTime(FormatStyle.FULL, FormatStyle.MEDIUM).getChronology());
|
||||
assertEquals(null, DateTimeFormatter.ofLocalizedDateTime(FormatStyle.FULL, FormatStyle.MEDIUM).getZone());
|
||||
assertEquals(ResolverStyle.SMART, DateTimeFormatter.ofLocalizedDateTime(FormatStyle.FULL, FormatStyle.MEDIUM).getResolverStyle());
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------
|
||||
@DataProvider(name="sample_isoLocalDate")
|
||||
Object[][] provider_sample_isoLocalDate() {
|
||||
return new Object[][]{
|
||||
{2008, null, null, null, null, null, DateTimeException.class},
|
||||
@ -222,13 +225,14 @@ public class TCKDateTimeFormatters {
|
||||
};
|
||||
}
|
||||
|
||||
@Test(dataProvider="sample_isoLocalDate")
|
||||
@ParameterizedTest
|
||||
@MethodSource("provider_sample_isoLocalDate")
|
||||
public void test_print_isoLocalDate(
|
||||
Integer year, Integer month, Integer day, String offsetId, String zoneId,
|
||||
String expected, Class<?> expectedEx) {
|
||||
TemporalAccessor test = buildAccessor(year, month, day, null, null, null, null, offsetId, zoneId);
|
||||
if (expectedEx == null) {
|
||||
assertEquals(DateTimeFormatter.ISO_LOCAL_DATE.format(test), expected);
|
||||
assertEquals(expected, DateTimeFormatter.ISO_LOCAL_DATE.format(test));
|
||||
} else {
|
||||
try {
|
||||
DateTimeFormatter.ISO_LOCAL_DATE.format(test);
|
||||
@ -239,7 +243,8 @@ public class TCKDateTimeFormatters {
|
||||
}
|
||||
}
|
||||
|
||||
@Test(dataProvider="sample_isoLocalDate")
|
||||
@ParameterizedTest
|
||||
@MethodSource("provider_sample_isoLocalDate")
|
||||
public void test_parse_isoLocalDate(
|
||||
Integer year, Integer month, Integer day, String offsetId, String zoneId,
|
||||
String input, Class<?> invalid) {
|
||||
@ -254,7 +259,7 @@ public class TCKDateTimeFormatters {
|
||||
public void test_parse_isoLocalDate_999999999() {
|
||||
Expected expected = createDate(999999999, 8, 6);
|
||||
assertParseMatch(DateTimeFormatter.ISO_LOCAL_DATE.parseUnresolved("+999999999-08-06", new ParsePosition(0)), expected);
|
||||
assertEquals(LocalDate.parse("+999999999-08-06"), LocalDate.of(999999999, 8, 6));
|
||||
assertEquals(LocalDate.of(999999999, 8, 6), LocalDate.parse("+999999999-08-06"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -263,16 +268,16 @@ public class TCKDateTimeFormatters {
|
||||
assertParseMatch(DateTimeFormatter.ISO_LOCAL_DATE.parseUnresolved("+1000000000-08-06", new ParsePosition(0)), expected);
|
||||
}
|
||||
|
||||
@Test(expectedExceptions = DateTimeException.class)
|
||||
@Test
|
||||
public void test_parse_isoLocalDate_1000000000_failedCreate() {
|
||||
LocalDate.parse("+1000000000-08-06");
|
||||
Assertions.assertThrows(DateTimeException.class, () -> LocalDate.parse("+1000000000-08-06"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test_parse_isoLocalDate_M999999999() {
|
||||
Expected expected = createDate(-999999999, 8, 6);
|
||||
assertParseMatch(DateTimeFormatter.ISO_LOCAL_DATE.parseUnresolved("-999999999-08-06", new ParsePosition(0)), expected);
|
||||
assertEquals(LocalDate.parse("-999999999-08-06"), LocalDate.of(-999999999, 8, 6));
|
||||
assertEquals(LocalDate.of(-999999999, 8, 6), LocalDate.parse("-999999999-08-06"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -281,22 +286,21 @@ public class TCKDateTimeFormatters {
|
||||
assertParseMatch(DateTimeFormatter.ISO_LOCAL_DATE.parseUnresolved("-1000000000-08-06", new ParsePosition(0)), expected);
|
||||
}
|
||||
|
||||
@Test(expectedExceptions = DateTimeException.class)
|
||||
@Test
|
||||
public void test_parse_isoLocalDate_M1000000000_failedCreate() {
|
||||
LocalDate.parse("-1000000000-08-06");
|
||||
Assertions.assertThrows(DateTimeException.class, () -> LocalDate.parse("-1000000000-08-06"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test_isoLocalDate_basics() {
|
||||
assertEquals(DateTimeFormatter.ISO_LOCAL_DATE.getChronology(), IsoChronology.INSTANCE);
|
||||
assertEquals(DateTimeFormatter.ISO_LOCAL_DATE.getZone(), null);
|
||||
assertEquals(DateTimeFormatter.ISO_LOCAL_DATE.getResolverStyle(), ResolverStyle.STRICT);
|
||||
assertEquals(IsoChronology.INSTANCE, DateTimeFormatter.ISO_LOCAL_DATE.getChronology());
|
||||
assertEquals(null, DateTimeFormatter.ISO_LOCAL_DATE.getZone());
|
||||
assertEquals(ResolverStyle.STRICT, DateTimeFormatter.ISO_LOCAL_DATE.getResolverStyle());
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------
|
||||
@DataProvider(name="sample_isoOffsetDate")
|
||||
Object[][] provider_sample_isoOffsetDate() {
|
||||
return new Object[][]{
|
||||
{2008, null, null, null, null, null, DateTimeException.class},
|
||||
@ -316,13 +320,14 @@ public class TCKDateTimeFormatters {
|
||||
};
|
||||
}
|
||||
|
||||
@Test(dataProvider="sample_isoOffsetDate")
|
||||
@ParameterizedTest
|
||||
@MethodSource("provider_sample_isoOffsetDate")
|
||||
public void test_print_isoOffsetDate(
|
||||
Integer year, Integer month, Integer day, String offsetId, String zoneId,
|
||||
String expected, Class<?> expectedEx) {
|
||||
TemporalAccessor test = buildAccessor(year, month, day, null, null, null, null, offsetId, zoneId);
|
||||
if (expectedEx == null) {
|
||||
assertEquals(DateTimeFormatter.ISO_OFFSET_DATE.format(test), expected);
|
||||
assertEquals(expected, DateTimeFormatter.ISO_OFFSET_DATE.format(test));
|
||||
} else {
|
||||
try {
|
||||
DateTimeFormatter.ISO_OFFSET_DATE.format(test);
|
||||
@ -333,7 +338,8 @@ public class TCKDateTimeFormatters {
|
||||
}
|
||||
}
|
||||
|
||||
@Test(dataProvider="sample_isoOffsetDate")
|
||||
@ParameterizedTest
|
||||
@MethodSource("provider_sample_isoOffsetDate")
|
||||
public void test_parse_isoOffsetDate(
|
||||
Integer year, Integer month, Integer day, String offsetId, String zoneId,
|
||||
String input, Class<?> invalid) {
|
||||
@ -346,15 +352,14 @@ public class TCKDateTimeFormatters {
|
||||
|
||||
@Test
|
||||
public void test_isoOffsetDate_basics() {
|
||||
assertEquals(DateTimeFormatter.ISO_OFFSET_DATE.getChronology(), IsoChronology.INSTANCE);
|
||||
assertEquals(DateTimeFormatter.ISO_OFFSET_DATE.getZone(), null);
|
||||
assertEquals(DateTimeFormatter.ISO_OFFSET_DATE.getResolverStyle(), ResolverStyle.STRICT);
|
||||
assertEquals(IsoChronology.INSTANCE, DateTimeFormatter.ISO_OFFSET_DATE.getChronology());
|
||||
assertEquals(null, DateTimeFormatter.ISO_OFFSET_DATE.getZone());
|
||||
assertEquals(ResolverStyle.STRICT, DateTimeFormatter.ISO_OFFSET_DATE.getResolverStyle());
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------
|
||||
@DataProvider(name="sample_isoDate")
|
||||
Object[][] provider_sample_isoDate() {
|
||||
return new Object[][]{
|
||||
{2008, null, null, null, null, null, DateTimeException.class},
|
||||
@ -374,13 +379,14 @@ public class TCKDateTimeFormatters {
|
||||
};
|
||||
}
|
||||
|
||||
@Test(dataProvider="sample_isoDate")
|
||||
@ParameterizedTest
|
||||
@MethodSource("provider_sample_isoDate")
|
||||
public void test_print_isoDate(
|
||||
Integer year, Integer month, Integer day, String offsetId, String zoneId,
|
||||
String expected, Class<?> expectedEx) {
|
||||
TemporalAccessor test = buildAccessor(year, month, day, null, null, null, null, offsetId, zoneId);
|
||||
if (expectedEx == null) {
|
||||
assertEquals(DateTimeFormatter.ISO_DATE.format(test), expected);
|
||||
assertEquals(expected, DateTimeFormatter.ISO_DATE.format(test));
|
||||
} else {
|
||||
try {
|
||||
DateTimeFormatter.ISO_DATE.format(test);
|
||||
@ -391,7 +397,8 @@ public class TCKDateTimeFormatters {
|
||||
}
|
||||
}
|
||||
|
||||
@Test(dataProvider="sample_isoDate")
|
||||
@ParameterizedTest
|
||||
@MethodSource("provider_sample_isoDate")
|
||||
public void test_parse_isoDate(
|
||||
Integer year, Integer month, Integer day, String offsetId, String zoneId,
|
||||
String input, Class<?> invalid) {
|
||||
@ -406,15 +413,14 @@ public class TCKDateTimeFormatters {
|
||||
|
||||
@Test
|
||||
public void test_isoDate_basics() {
|
||||
assertEquals(DateTimeFormatter.ISO_DATE.getChronology(), IsoChronology.INSTANCE);
|
||||
assertEquals(DateTimeFormatter.ISO_DATE.getZone(), null);
|
||||
assertEquals(DateTimeFormatter.ISO_DATE.getResolverStyle(), ResolverStyle.STRICT);
|
||||
assertEquals(IsoChronology.INSTANCE, DateTimeFormatter.ISO_DATE.getChronology());
|
||||
assertEquals(null, DateTimeFormatter.ISO_DATE.getZone());
|
||||
assertEquals(ResolverStyle.STRICT, DateTimeFormatter.ISO_DATE.getResolverStyle());
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------
|
||||
@DataProvider(name="sample_isoLocalTime")
|
||||
Object[][] provider_sample_isoLocalTime() {
|
||||
return new Object[][]{
|
||||
{11, null, null, null, null, null, null, DateTimeException.class},
|
||||
@ -446,13 +452,14 @@ public class TCKDateTimeFormatters {
|
||||
};
|
||||
}
|
||||
|
||||
@Test(dataProvider="sample_isoLocalTime")
|
||||
@ParameterizedTest
|
||||
@MethodSource("provider_sample_isoLocalTime")
|
||||
public void test_print_isoLocalTime(
|
||||
Integer hour, Integer min, Integer sec, Integer nano, String offsetId, String zoneId,
|
||||
String expected, Class<?> expectedEx) {
|
||||
TemporalAccessor test = buildAccessor(null, null, null, hour, min, sec, nano, offsetId, zoneId);
|
||||
if (expectedEx == null) {
|
||||
assertEquals(DateTimeFormatter.ISO_LOCAL_TIME.format(test), expected);
|
||||
assertEquals(expected, DateTimeFormatter.ISO_LOCAL_TIME.format(test));
|
||||
} else {
|
||||
try {
|
||||
DateTimeFormatter.ISO_LOCAL_TIME.format(test);
|
||||
@ -463,7 +470,8 @@ public class TCKDateTimeFormatters {
|
||||
}
|
||||
}
|
||||
|
||||
@Test(dataProvider="sample_isoLocalTime")
|
||||
@ParameterizedTest
|
||||
@MethodSource("provider_sample_isoLocalTime")
|
||||
public void test_parse_isoLocalTime(
|
||||
Integer hour, Integer min, Integer sec, Integer nano, String offsetId, String zoneId,
|
||||
String input, Class<?> invalid) {
|
||||
@ -476,15 +484,14 @@ public class TCKDateTimeFormatters {
|
||||
|
||||
@Test
|
||||
public void test_isoLocalTime_basics() {
|
||||
assertEquals(DateTimeFormatter.ISO_LOCAL_TIME.getChronology(), null);
|
||||
assertEquals(DateTimeFormatter.ISO_LOCAL_TIME.getZone(), null);
|
||||
assertEquals(DateTimeFormatter.ISO_LOCAL_TIME.getResolverStyle(), ResolverStyle.STRICT);
|
||||
assertEquals(null, DateTimeFormatter.ISO_LOCAL_TIME.getChronology());
|
||||
assertEquals(null, DateTimeFormatter.ISO_LOCAL_TIME.getZone());
|
||||
assertEquals(ResolverStyle.STRICT, DateTimeFormatter.ISO_LOCAL_TIME.getResolverStyle());
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------
|
||||
@DataProvider(name="sample_isoOffsetTime")
|
||||
Object[][] provider_sample_isoOffsetTime() {
|
||||
return new Object[][]{
|
||||
{11, null, null, null, null, null, null, DateTimeException.class},
|
||||
@ -516,13 +523,14 @@ public class TCKDateTimeFormatters {
|
||||
};
|
||||
}
|
||||
|
||||
@Test(dataProvider="sample_isoOffsetTime")
|
||||
@ParameterizedTest
|
||||
@MethodSource("provider_sample_isoOffsetTime")
|
||||
public void test_print_isoOffsetTime(
|
||||
Integer hour, Integer min, Integer sec, Integer nano, String offsetId, String zoneId,
|
||||
String expected, Class<?> expectedEx) {
|
||||
TemporalAccessor test = buildAccessor(null, null, null, hour, min, sec, nano, offsetId, zoneId);
|
||||
if (expectedEx == null) {
|
||||
assertEquals(DateTimeFormatter.ISO_OFFSET_TIME.format(test), expected);
|
||||
assertEquals(expected, DateTimeFormatter.ISO_OFFSET_TIME.format(test));
|
||||
} else {
|
||||
try {
|
||||
DateTimeFormatter.ISO_OFFSET_TIME.format(test);
|
||||
@ -533,7 +541,8 @@ public class TCKDateTimeFormatters {
|
||||
}
|
||||
}
|
||||
|
||||
@Test(dataProvider="sample_isoOffsetTime")
|
||||
@ParameterizedTest
|
||||
@MethodSource("provider_sample_isoOffsetTime")
|
||||
public void test_parse_isoOffsetTime(
|
||||
Integer hour, Integer min, Integer sec, Integer nano, String offsetId, String zoneId,
|
||||
String input, Class<?> invalid) {
|
||||
@ -546,15 +555,14 @@ public class TCKDateTimeFormatters {
|
||||
|
||||
@Test
|
||||
public void test_isoOffsetTime_basics() {
|
||||
assertEquals(DateTimeFormatter.ISO_OFFSET_TIME.getChronology(), null);
|
||||
assertEquals(DateTimeFormatter.ISO_OFFSET_TIME.getZone(), null);
|
||||
assertEquals(DateTimeFormatter.ISO_OFFSET_TIME.getResolverStyle(), ResolverStyle.STRICT);
|
||||
assertEquals(null, DateTimeFormatter.ISO_OFFSET_TIME.getChronology());
|
||||
assertEquals(null, DateTimeFormatter.ISO_OFFSET_TIME.getZone());
|
||||
assertEquals(ResolverStyle.STRICT, DateTimeFormatter.ISO_OFFSET_TIME.getResolverStyle());
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------
|
||||
@DataProvider(name="sample_isoTime")
|
||||
Object[][] provider_sample_isoTime() {
|
||||
return new Object[][]{
|
||||
{11, null, null, null, null, null, null, DateTimeException.class},
|
||||
@ -586,13 +594,14 @@ public class TCKDateTimeFormatters {
|
||||
};
|
||||
}
|
||||
|
||||
@Test(dataProvider="sample_isoTime")
|
||||
@ParameterizedTest
|
||||
@MethodSource("provider_sample_isoTime")
|
||||
public void test_print_isoTime(
|
||||
Integer hour, Integer min, Integer sec, Integer nano, String offsetId, String zoneId,
|
||||
String expected, Class<?> expectedEx) {
|
||||
TemporalAccessor test = buildAccessor(null, null, null, hour, min, sec, nano, offsetId, zoneId);
|
||||
if (expectedEx == null) {
|
||||
assertEquals(DateTimeFormatter.ISO_TIME.format(test), expected);
|
||||
assertEquals(expected, DateTimeFormatter.ISO_TIME.format(test));
|
||||
} else {
|
||||
try {
|
||||
DateTimeFormatter.ISO_TIME.format(test);
|
||||
@ -603,7 +612,8 @@ public class TCKDateTimeFormatters {
|
||||
}
|
||||
}
|
||||
|
||||
@Test(dataProvider="sample_isoTime")
|
||||
@ParameterizedTest
|
||||
@MethodSource("provider_sample_isoTime")
|
||||
public void test_parse_isoTime(
|
||||
Integer hour, Integer min, Integer sec, Integer nano, String offsetId, String zoneId,
|
||||
String input, Class<?> invalid) {
|
||||
@ -618,15 +628,14 @@ public class TCKDateTimeFormatters {
|
||||
|
||||
@Test
|
||||
public void test_isoTime_basics() {
|
||||
assertEquals(DateTimeFormatter.ISO_TIME.getChronology(), null);
|
||||
assertEquals(DateTimeFormatter.ISO_TIME.getZone(), null);
|
||||
assertEquals(DateTimeFormatter.ISO_TIME.getResolverStyle(), ResolverStyle.STRICT);
|
||||
assertEquals(null, DateTimeFormatter.ISO_TIME.getChronology());
|
||||
assertEquals(null, DateTimeFormatter.ISO_TIME.getZone());
|
||||
assertEquals(ResolverStyle.STRICT, DateTimeFormatter.ISO_TIME.getResolverStyle());
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------
|
||||
@DataProvider(name="sample_isoLocalDateTime")
|
||||
Object[][] provider_sample_isoLocalDateTime() {
|
||||
return new Object[][]{
|
||||
{2008, null, null, null, null, null, null, null, null, null, DateTimeException.class},
|
||||
@ -666,14 +675,15 @@ public class TCKDateTimeFormatters {
|
||||
};
|
||||
}
|
||||
|
||||
@Test(dataProvider="sample_isoLocalDateTime")
|
||||
@ParameterizedTest
|
||||
@MethodSource("provider_sample_isoLocalDateTime")
|
||||
public void test_print_isoLocalDateTime(
|
||||
Integer year, Integer month, Integer day,
|
||||
Integer hour, Integer min, Integer sec, Integer nano, String offsetId, String zoneId,
|
||||
String expected, Class<?> expectedEx) {
|
||||
TemporalAccessor test = buildAccessor(year, month, day, hour, min, sec, nano, offsetId, zoneId);
|
||||
if (expectedEx == null) {
|
||||
assertEquals(DateTimeFormatter.ISO_LOCAL_DATE_TIME.format(test), expected);
|
||||
assertEquals(expected, DateTimeFormatter.ISO_LOCAL_DATE_TIME.format(test));
|
||||
} else {
|
||||
try {
|
||||
DateTimeFormatter.ISO_LOCAL_DATE_TIME.format(test);
|
||||
@ -684,7 +694,8 @@ public class TCKDateTimeFormatters {
|
||||
}
|
||||
}
|
||||
|
||||
@Test(dataProvider="sample_isoLocalDateTime")
|
||||
@ParameterizedTest
|
||||
@MethodSource("provider_sample_isoLocalDateTime")
|
||||
public void test_parse_isoLocalDateTime(
|
||||
Integer year, Integer month, Integer day,
|
||||
Integer hour, Integer min, Integer sec, Integer nano, String offsetId, String zoneId,
|
||||
@ -697,15 +708,14 @@ public class TCKDateTimeFormatters {
|
||||
|
||||
@Test
|
||||
public void test_isoLocalDateTime_basics() {
|
||||
assertEquals(DateTimeFormatter.ISO_LOCAL_DATE_TIME.getChronology(), IsoChronology.INSTANCE);
|
||||
assertEquals(DateTimeFormatter.ISO_LOCAL_DATE_TIME.getZone(), null);
|
||||
assertEquals(DateTimeFormatter.ISO_LOCAL_DATE_TIME.getResolverStyle(), ResolverStyle.STRICT);
|
||||
assertEquals(IsoChronology.INSTANCE, DateTimeFormatter.ISO_LOCAL_DATE_TIME.getChronology());
|
||||
assertEquals(null, DateTimeFormatter.ISO_LOCAL_DATE_TIME.getZone());
|
||||
assertEquals(ResolverStyle.STRICT, DateTimeFormatter.ISO_LOCAL_DATE_TIME.getResolverStyle());
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------
|
||||
@DataProvider(name="sample_isoOffsetDateTime")
|
||||
Object[][] provider_sample_isoOffsetDateTime() {
|
||||
return new Object[][]{
|
||||
{2008, null, null, null, null, null, null, null, null, null, DateTimeException.class},
|
||||
@ -745,14 +755,15 @@ public class TCKDateTimeFormatters {
|
||||
};
|
||||
}
|
||||
|
||||
@Test(dataProvider="sample_isoOffsetDateTime")
|
||||
@ParameterizedTest
|
||||
@MethodSource("provider_sample_isoOffsetDateTime")
|
||||
public void test_print_isoOffsetDateTime(
|
||||
Integer year, Integer month, Integer day,
|
||||
Integer hour, Integer min, Integer sec, Integer nano, String offsetId, String zoneId,
|
||||
String expected, Class<?> expectedEx) {
|
||||
TemporalAccessor test = buildAccessor(year, month, day, hour, min, sec, nano, offsetId, zoneId);
|
||||
if (expectedEx == null) {
|
||||
assertEquals(DateTimeFormatter.ISO_OFFSET_DATE_TIME.format(test), expected);
|
||||
assertEquals(expected, DateTimeFormatter.ISO_OFFSET_DATE_TIME.format(test));
|
||||
} else {
|
||||
try {
|
||||
DateTimeFormatter.ISO_OFFSET_DATE_TIME.format(test);
|
||||
@ -763,7 +774,8 @@ public class TCKDateTimeFormatters {
|
||||
}
|
||||
}
|
||||
|
||||
@Test(dataProvider="sample_isoOffsetDateTime")
|
||||
@ParameterizedTest
|
||||
@MethodSource("provider_sample_isoOffsetDateTime")
|
||||
public void test_parse_isoOffsetDateTime(
|
||||
Integer year, Integer month, Integer day,
|
||||
Integer hour, Integer min, Integer sec, Integer nano, String offsetId, String zoneId,
|
||||
@ -777,15 +789,14 @@ public class TCKDateTimeFormatters {
|
||||
|
||||
@Test
|
||||
public void test_isoOffsetDateTime_basics() {
|
||||
assertEquals(DateTimeFormatter.ISO_OFFSET_DATE_TIME.getChronology(), IsoChronology.INSTANCE);
|
||||
assertEquals(DateTimeFormatter.ISO_OFFSET_DATE_TIME.getZone(), null);
|
||||
assertEquals(DateTimeFormatter.ISO_OFFSET_DATE_TIME.getResolverStyle(), ResolverStyle.STRICT);
|
||||
assertEquals(IsoChronology.INSTANCE, DateTimeFormatter.ISO_OFFSET_DATE_TIME.getChronology());
|
||||
assertEquals(null, DateTimeFormatter.ISO_OFFSET_DATE_TIME.getZone());
|
||||
assertEquals(ResolverStyle.STRICT, DateTimeFormatter.ISO_OFFSET_DATE_TIME.getResolverStyle());
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------
|
||||
@DataProvider(name="sample_isoZonedDateTime")
|
||||
Object[][] provider_sample_isoZonedDateTime() {
|
||||
return new Object[][]{
|
||||
{2008, null, null, null, null, null, null, null, null, null, DateTimeException.class},
|
||||
@ -834,14 +845,15 @@ public class TCKDateTimeFormatters {
|
||||
};
|
||||
}
|
||||
|
||||
@Test(dataProvider="sample_isoZonedDateTime")
|
||||
@ParameterizedTest
|
||||
@MethodSource("provider_sample_isoZonedDateTime")
|
||||
public void test_print_isoZonedDateTime(
|
||||
Integer year, Integer month, Integer day,
|
||||
Integer hour, Integer min, Integer sec, Integer nano, String offsetId, String zoneId,
|
||||
String expected, Class<?> expectedEx) {
|
||||
TemporalAccessor test = buildAccessor(year, month, day, hour, min, sec, nano, offsetId, zoneId);
|
||||
if (expectedEx == null) {
|
||||
assertEquals(DateTimeFormatter.ISO_ZONED_DATE_TIME.format(test), expected);
|
||||
assertEquals(expected, DateTimeFormatter.ISO_ZONED_DATE_TIME.format(test));
|
||||
} else {
|
||||
try {
|
||||
DateTimeFormatter.ISO_ZONED_DATE_TIME.format(test);
|
||||
@ -852,7 +864,8 @@ public class TCKDateTimeFormatters {
|
||||
}
|
||||
}
|
||||
|
||||
@Test(dataProvider="sample_isoZonedDateTime")
|
||||
@ParameterizedTest
|
||||
@MethodSource("provider_sample_isoZonedDateTime")
|
||||
public void test_parse_isoZonedDateTime(
|
||||
Integer year, Integer month, Integer day,
|
||||
Integer hour, Integer min, Integer sec, Integer nano, String offsetId, String zoneId,
|
||||
@ -870,15 +883,14 @@ public class TCKDateTimeFormatters {
|
||||
|
||||
@Test
|
||||
public void test_isoZonedDateTime_basics() {
|
||||
assertEquals(DateTimeFormatter.ISO_ZONED_DATE_TIME.getChronology(), IsoChronology.INSTANCE);
|
||||
assertEquals(DateTimeFormatter.ISO_ZONED_DATE_TIME.getZone(), null);
|
||||
assertEquals(DateTimeFormatter.ISO_ZONED_DATE_TIME.getResolverStyle(), ResolverStyle.STRICT);
|
||||
assertEquals(IsoChronology.INSTANCE, DateTimeFormatter.ISO_ZONED_DATE_TIME.getChronology());
|
||||
assertEquals(null, DateTimeFormatter.ISO_ZONED_DATE_TIME.getZone());
|
||||
assertEquals(ResolverStyle.STRICT, DateTimeFormatter.ISO_ZONED_DATE_TIME.getResolverStyle());
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------
|
||||
@DataProvider(name="sample_isoDateTime")
|
||||
Object[][] provider_sample_isoDateTime() {
|
||||
return new Object[][]{
|
||||
{2008, null, null, null, null, null, null, null, null, null, DateTimeException.class},
|
||||
@ -918,14 +930,15 @@ public class TCKDateTimeFormatters {
|
||||
};
|
||||
}
|
||||
|
||||
@Test(dataProvider="sample_isoDateTime")
|
||||
@ParameterizedTest
|
||||
@MethodSource("provider_sample_isoDateTime")
|
||||
public void test_print_isoDateTime(
|
||||
Integer year, Integer month, Integer day,
|
||||
Integer hour, Integer min, Integer sec, Integer nano, String offsetId, String zoneId,
|
||||
String expected, Class<?> expectedEx) {
|
||||
TemporalAccessor test = buildAccessor(year, month, day, hour, min, sec, nano, offsetId, zoneId);
|
||||
if (expectedEx == null) {
|
||||
assertEquals(DateTimeFormatter.ISO_DATE_TIME.format(test), expected);
|
||||
assertEquals(expected, DateTimeFormatter.ISO_DATE_TIME.format(test));
|
||||
} else {
|
||||
try {
|
||||
DateTimeFormatter.ISO_DATE_TIME.format(test);
|
||||
@ -936,7 +949,8 @@ public class TCKDateTimeFormatters {
|
||||
}
|
||||
}
|
||||
|
||||
@Test(dataProvider="sample_isoDateTime")
|
||||
@ParameterizedTest
|
||||
@MethodSource("provider_sample_isoDateTime")
|
||||
public void test_parse_isoDateTime(
|
||||
Integer year, Integer month, Integer day,
|
||||
Integer hour, Integer min, Integer sec, Integer nano, String offsetId, String zoneId,
|
||||
@ -955,9 +969,9 @@ public class TCKDateTimeFormatters {
|
||||
|
||||
@Test
|
||||
public void test_isoDateTime_basics() {
|
||||
assertEquals(DateTimeFormatter.ISO_DATE_TIME.getChronology(), IsoChronology.INSTANCE);
|
||||
assertEquals(DateTimeFormatter.ISO_DATE_TIME.getZone(), null);
|
||||
assertEquals(DateTimeFormatter.ISO_DATE_TIME.getResolverStyle(), ResolverStyle.STRICT);
|
||||
assertEquals(IsoChronology.INSTANCE, DateTimeFormatter.ISO_DATE_TIME.getChronology());
|
||||
assertEquals(null, DateTimeFormatter.ISO_DATE_TIME.getZone());
|
||||
assertEquals(ResolverStyle.STRICT, DateTimeFormatter.ISO_DATE_TIME.getResolverStyle());
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
@ -966,25 +980,25 @@ public class TCKDateTimeFormatters {
|
||||
@Test
|
||||
public void test_print_isoOrdinalDate() {
|
||||
TemporalAccessor test = buildAccessor(LocalDateTime.of(2008, 6, 3, 11, 5, 30), null, null);
|
||||
assertEquals(DateTimeFormatter.ISO_ORDINAL_DATE.format(test), "2008-155");
|
||||
assertEquals("2008-155", DateTimeFormatter.ISO_ORDINAL_DATE.format(test));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test_print_isoOrdinalDate_offset() {
|
||||
TemporalAccessor test = buildAccessor(LocalDateTime.of(2008, 6, 3, 11, 5, 30), "Z", null);
|
||||
assertEquals(DateTimeFormatter.ISO_ORDINAL_DATE.format(test), "2008-155Z");
|
||||
assertEquals("2008-155Z", DateTimeFormatter.ISO_ORDINAL_DATE.format(test));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test_print_isoOrdinalDate_zoned() {
|
||||
TemporalAccessor test = buildAccessor(LocalDateTime.of(2008, 6, 3, 11, 5, 30), "+02:00", "Europe/Paris");
|
||||
assertEquals(DateTimeFormatter.ISO_ORDINAL_DATE.format(test), "2008-155+02:00");
|
||||
assertEquals("2008-155+02:00", DateTimeFormatter.ISO_ORDINAL_DATE.format(test));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test_print_isoOrdinalDate_zoned_largeYear() {
|
||||
TemporalAccessor test = buildAccessor(LocalDateTime.of(123456, 6, 3, 11, 5, 30), "Z", null);
|
||||
assertEquals(DateTimeFormatter.ISO_ORDINAL_DATE.format(test), "+123456-155Z");
|
||||
assertEquals("+123456-155Z", DateTimeFormatter.ISO_ORDINAL_DATE.format(test));
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -1006,13 +1020,15 @@ public class TCKDateTimeFormatters {
|
||||
throw new DateTimeException("Unsupported");
|
||||
}
|
||||
};
|
||||
assertEquals(DateTimeFormatter.ISO_ORDINAL_DATE.format(test), "2008-231");
|
||||
assertEquals("2008-231", DateTimeFormatter.ISO_ORDINAL_DATE.format(test));
|
||||
}
|
||||
|
||||
@Test(expectedExceptions=DateTimeException.class)
|
||||
@Test
|
||||
public void test_print_isoOrdinalDate_missingField() {
|
||||
TemporalAccessor test = Year.of(2008);
|
||||
DateTimeFormatter.ISO_ORDINAL_DATE.format(test);
|
||||
Assertions.assertThrows(DateTimeException.class, () -> {
|
||||
TemporalAccessor test = Year.of(2008);
|
||||
DateTimeFormatter.ISO_ORDINAL_DATE.format(test);
|
||||
});
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
@ -1030,9 +1046,9 @@ public class TCKDateTimeFormatters {
|
||||
|
||||
@Test
|
||||
public void test_isoOrdinalDate_basics() {
|
||||
assertEquals(DateTimeFormatter.ISO_ORDINAL_DATE.getChronology(), IsoChronology.INSTANCE);
|
||||
assertEquals(DateTimeFormatter.ISO_ORDINAL_DATE.getZone(), null);
|
||||
assertEquals(DateTimeFormatter.ISO_ORDINAL_DATE.getResolverStyle(), ResolverStyle.STRICT);
|
||||
assertEquals(IsoChronology.INSTANCE, DateTimeFormatter.ISO_ORDINAL_DATE.getChronology());
|
||||
assertEquals(null, DateTimeFormatter.ISO_ORDINAL_DATE.getZone());
|
||||
assertEquals(ResolverStyle.STRICT, DateTimeFormatter.ISO_ORDINAL_DATE.getResolverStyle());
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
@ -1041,69 +1057,74 @@ public class TCKDateTimeFormatters {
|
||||
@Test
|
||||
public void test_print_basicIsoDate() {
|
||||
TemporalAccessor test = buildAccessor(LocalDateTime.of(2008, 6, 3, 11, 5, 30), null, null);
|
||||
assertEquals(DateTimeFormatter.BASIC_ISO_DATE.format(test), "20080603");
|
||||
assertEquals("20080603", DateTimeFormatter.BASIC_ISO_DATE.format(test));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test_print_basicIsoDate_offset() {
|
||||
TemporalAccessor test = buildAccessor(LocalDateTime.of(2008, 6, 3, 11, 5, 30), "Z", null);
|
||||
assertEquals(DateTimeFormatter.BASIC_ISO_DATE.format(test), "20080603Z");
|
||||
assertEquals("20080603Z", DateTimeFormatter.BASIC_ISO_DATE.format(test));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test_print_basicIsoDate_zoned() {
|
||||
TemporalAccessor test = buildAccessor(LocalDateTime.of(2008, 6, 3, 11, 5, 30), "+02:00", "Europe/Paris");
|
||||
assertEquals(DateTimeFormatter.BASIC_ISO_DATE.format(test), "20080603+0200");
|
||||
assertEquals("20080603+0200", DateTimeFormatter.BASIC_ISO_DATE.format(test));
|
||||
}
|
||||
|
||||
@Test(expectedExceptions=DateTimeException.class)
|
||||
@Test
|
||||
public void test_print_basicIsoDate_largeYear() {
|
||||
TemporalAccessor test = buildAccessor(LocalDateTime.of(123456, 6, 3, 11, 5, 30), "Z", null);
|
||||
DateTimeFormatter.BASIC_ISO_DATE.format(test);
|
||||
Assertions.assertThrows(DateTimeException.class, () -> {
|
||||
TemporalAccessor test = buildAccessor(LocalDateTime.of(123456, 6, 3, 11, 5, 30), "Z", null);
|
||||
DateTimeFormatter.BASIC_ISO_DATE.format(test);
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test_print_basicIsoDate_fields() {
|
||||
TemporalAccessor test = buildAccessor(LocalDate.of(2008, 6, 3), null, null);
|
||||
assertEquals(DateTimeFormatter.BASIC_ISO_DATE.format(test), "20080603");
|
||||
assertEquals("20080603", DateTimeFormatter.BASIC_ISO_DATE.format(test));
|
||||
}
|
||||
|
||||
@Test(expectedExceptions=DateTimeException.class)
|
||||
@Test
|
||||
public void test_print_basicIsoDate_missingField() {
|
||||
TemporalAccessor test = YearMonth.of(2008, 6);
|
||||
DateTimeFormatter.BASIC_ISO_DATE.format(test);
|
||||
Assertions.assertThrows(DateTimeException.class, () -> {
|
||||
TemporalAccessor test = YearMonth.of(2008, 6);
|
||||
DateTimeFormatter.BASIC_ISO_DATE.format(test);
|
||||
});
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
@Test
|
||||
public void test_parse_basicIsoDate() {
|
||||
LocalDate expected = LocalDate.of(2008, 6, 3);
|
||||
assertEquals(DateTimeFormatter.BASIC_ISO_DATE.parse("20080603", LocalDate::from), expected);
|
||||
assertEquals(expected, DateTimeFormatter.BASIC_ISO_DATE.parse("20080603", LocalDate::from));
|
||||
}
|
||||
|
||||
@Test(expectedExceptions=DateTimeParseException.class)
|
||||
@Test
|
||||
public void test_parse_basicIsoDate_largeYear() {
|
||||
try {
|
||||
LocalDate expected = LocalDate.of(123456, 6, 3);
|
||||
assertEquals(DateTimeFormatter.BASIC_ISO_DATE.parse("+1234560603", LocalDate::from), expected);
|
||||
} catch (DateTimeParseException ex) {
|
||||
assertEquals(ex.getErrorIndex(), 0);
|
||||
assertEquals(ex.getParsedString(), "+1234560603");
|
||||
throw ex;
|
||||
}
|
||||
Assertions.assertThrows(DateTimeParseException.class, () -> {
|
||||
try {
|
||||
LocalDate expected = LocalDate.of(123456, 6, 3);
|
||||
assertEquals(expected, DateTimeFormatter.BASIC_ISO_DATE.parse("+1234560603", LocalDate::from));
|
||||
} catch (DateTimeParseException ex) {
|
||||
assertEquals(0, ex.getErrorIndex());
|
||||
assertEquals("+1234560603", ex.getParsedString());
|
||||
throw ex;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test_basicIsoDate_basics() {
|
||||
assertEquals(DateTimeFormatter.BASIC_ISO_DATE.getChronology(), IsoChronology.INSTANCE);
|
||||
assertEquals(DateTimeFormatter.BASIC_ISO_DATE.getZone(), null);
|
||||
assertEquals(DateTimeFormatter.BASIC_ISO_DATE.getResolverStyle(), ResolverStyle.STRICT);
|
||||
assertEquals(IsoChronology.INSTANCE, DateTimeFormatter.BASIC_ISO_DATE.getChronology());
|
||||
assertEquals(null, DateTimeFormatter.BASIC_ISO_DATE.getZone());
|
||||
assertEquals(ResolverStyle.STRICT, DateTimeFormatter.BASIC_ISO_DATE.getResolverStyle());
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------
|
||||
@DataProvider(name="weekDate")
|
||||
Iterator<Object[]> weekDate() {
|
||||
return new Iterator<Object[]>() {
|
||||
private ZonedDateTime date = ZonedDateTime.of(LocalDateTime.of(2003, 12, 29, 11, 5, 30), ZoneId.of("Europe/Paris"));
|
||||
@ -1135,55 +1156,57 @@ public class TCKDateTimeFormatters {
|
||||
};
|
||||
}
|
||||
|
||||
@Test(dataProvider="weekDate")
|
||||
@ParameterizedTest
|
||||
@MethodSource("weekDate")
|
||||
public void test_print_isoWeekDate(TemporalAccessor test, String expected) {
|
||||
assertEquals(DateTimeFormatter.ISO_WEEK_DATE.format(test), expected);
|
||||
assertEquals(expected, DateTimeFormatter.ISO_WEEK_DATE.format(test));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test_print_isoWeekDate_zoned_largeYear() {
|
||||
TemporalAccessor test = buildAccessor(LocalDateTime.of(123456, 6, 3, 11, 5, 30), "Z", null);
|
||||
assertEquals(DateTimeFormatter.ISO_WEEK_DATE.format(test), "+123456-W23-2Z");
|
||||
assertEquals("+123456-W23-2Z", DateTimeFormatter.ISO_WEEK_DATE.format(test));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test_print_isoWeekDate_fields() {
|
||||
TemporalAccessor test = buildAccessor(LocalDate.of(2004, 1, 27), null, null);
|
||||
assertEquals(DateTimeFormatter.ISO_WEEK_DATE.format(test), "2004-W05-2");
|
||||
assertEquals("2004-W05-2", DateTimeFormatter.ISO_WEEK_DATE.format(test));
|
||||
}
|
||||
|
||||
@Test(expectedExceptions=DateTimeException.class)
|
||||
@Test
|
||||
public void test_print_isoWeekDate_missingField() {
|
||||
TemporalAccessor test = YearMonth.of(2008, 6);
|
||||
DateTimeFormatter.ISO_WEEK_DATE.format(test);
|
||||
Assertions.assertThrows(DateTimeException.class, () -> {
|
||||
TemporalAccessor test = YearMonth.of(2008, 6);
|
||||
DateTimeFormatter.ISO_WEEK_DATE.format(test);
|
||||
});
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
@Test
|
||||
public void test_parse_weekDate() {
|
||||
LocalDate expected = LocalDate.of(2004, 1, 28);
|
||||
assertEquals(DateTimeFormatter.ISO_WEEK_DATE.parse("2004-W05-3", LocalDate::from), expected);
|
||||
assertEquals(expected, DateTimeFormatter.ISO_WEEK_DATE.parse("2004-W05-3", LocalDate::from));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test_parse_weekDate_largeYear() {
|
||||
TemporalAccessor parsed = DateTimeFormatter.ISO_WEEK_DATE.parseUnresolved("+123456-W04-5", new ParsePosition(0));
|
||||
assertEquals(parsed.getLong(IsoFields.WEEK_BASED_YEAR), 123456L);
|
||||
assertEquals(parsed.getLong(IsoFields.WEEK_OF_WEEK_BASED_YEAR), 4L);
|
||||
assertEquals(parsed.getLong(DAY_OF_WEEK), 5L);
|
||||
assertEquals(123456L, parsed.getLong(IsoFields.WEEK_BASED_YEAR));
|
||||
assertEquals(4L, parsed.getLong(IsoFields.WEEK_OF_WEEK_BASED_YEAR));
|
||||
assertEquals(5L, parsed.getLong(DAY_OF_WEEK));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test_isoWeekDate_basics() {
|
||||
assertEquals(DateTimeFormatter.ISO_WEEK_DATE.getChronology(), IsoChronology.INSTANCE);
|
||||
assertEquals(DateTimeFormatter.ISO_WEEK_DATE.getZone(), null);
|
||||
assertEquals(DateTimeFormatter.ISO_WEEK_DATE.getResolverStyle(), ResolverStyle.STRICT);
|
||||
assertEquals(IsoChronology.INSTANCE, DateTimeFormatter.ISO_WEEK_DATE.getChronology());
|
||||
assertEquals(null, DateTimeFormatter.ISO_WEEK_DATE.getZone());
|
||||
assertEquals(ResolverStyle.STRICT, DateTimeFormatter.ISO_WEEK_DATE.getResolverStyle());
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------
|
||||
@DataProvider(name="sample_isoInstant")
|
||||
Object[][] provider_sample_isoInstant() {
|
||||
return new Object[][]{
|
||||
{0, 0, "1970-01-01T00:00:00Z", null},
|
||||
@ -1203,12 +1226,13 @@ public class TCKDateTimeFormatters {
|
||||
};
|
||||
}
|
||||
|
||||
@Test(dataProvider="sample_isoInstant")
|
||||
@ParameterizedTest
|
||||
@MethodSource("provider_sample_isoInstant")
|
||||
public void test_print_isoInstant(
|
||||
long instantSecs, Integer nano, String expected, Class<?> expectedEx) {
|
||||
TemporalAccessor test = buildAccessorInstant(instantSecs, nano);
|
||||
if (expectedEx == null) {
|
||||
assertEquals(DateTimeFormatter.ISO_INSTANT.format(test), expected);
|
||||
assertEquals(expected, DateTimeFormatter.ISO_INSTANT.format(test));
|
||||
} else {
|
||||
try {
|
||||
DateTimeFormatter.ISO_INSTANT.format(test);
|
||||
@ -1219,27 +1243,27 @@ public class TCKDateTimeFormatters {
|
||||
}
|
||||
}
|
||||
|
||||
@Test(dataProvider="sample_isoInstant")
|
||||
@ParameterizedTest
|
||||
@MethodSource("provider_sample_isoInstant")
|
||||
public void test_parse_isoInstant(
|
||||
long instantSecs, Integer nano, String input, Class<?> invalid) {
|
||||
if (input != null) {
|
||||
TemporalAccessor parsed = DateTimeFormatter.ISO_INSTANT.parseUnresolved(input, new ParsePosition(0));
|
||||
assertEquals(parsed.getLong(INSTANT_SECONDS), instantSecs);
|
||||
assertEquals(parsed.getLong(NANO_OF_SECOND), (nano == null ? 0 : nano));
|
||||
assertEquals(instantSecs, parsed.getLong(INSTANT_SECONDS));
|
||||
assertEquals((nano == null ? 0 : nano), parsed.getLong(NANO_OF_SECOND));
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test_isoInstant_basics() {
|
||||
assertEquals(DateTimeFormatter.ISO_INSTANT.getChronology(), null);
|
||||
assertEquals(DateTimeFormatter.ISO_INSTANT.getZone(), null);
|
||||
assertEquals(DateTimeFormatter.ISO_INSTANT.getResolverStyle(), ResolverStyle.STRICT);
|
||||
assertEquals(null, DateTimeFormatter.ISO_INSTANT.getChronology());
|
||||
assertEquals(null, DateTimeFormatter.ISO_INSTANT.getZone());
|
||||
assertEquals(ResolverStyle.STRICT, DateTimeFormatter.ISO_INSTANT.getResolverStyle());
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------
|
||||
@DataProvider(name="rfc")
|
||||
Object[][] data_rfc() {
|
||||
return new Object[][] {
|
||||
{LocalDateTime.of(2008, 6, 3, 11, 5, 30), "Z", "Tue, 3 Jun 2008 11:05:30 GMT"},
|
||||
@ -1249,29 +1273,33 @@ public class TCKDateTimeFormatters {
|
||||
};
|
||||
}
|
||||
|
||||
@Test(dataProvider="rfc")
|
||||
@ParameterizedTest
|
||||
@MethodSource("data_rfc")
|
||||
public void test_print_rfc1123(LocalDateTime base, String offsetId, String expected) {
|
||||
TemporalAccessor test = buildAccessor(base, offsetId, null);
|
||||
assertEquals(DateTimeFormatter.RFC_1123_DATE_TIME.format(test), expected);
|
||||
assertEquals(expected, DateTimeFormatter.RFC_1123_DATE_TIME.format(test));
|
||||
}
|
||||
|
||||
@Test(dataProvider="rfc")
|
||||
@ParameterizedTest
|
||||
@MethodSource("data_rfc")
|
||||
public void test_print_rfc1123_french(LocalDateTime base, String offsetId, String expected) {
|
||||
TemporalAccessor test = buildAccessor(base, offsetId, null);
|
||||
assertEquals(DateTimeFormatter.RFC_1123_DATE_TIME.withLocale(Locale.FRENCH).format(test), expected);
|
||||
assertEquals(expected, DateTimeFormatter.RFC_1123_DATE_TIME.withLocale(Locale.FRENCH).format(test));
|
||||
}
|
||||
|
||||
@Test(expectedExceptions=DateTimeException.class)
|
||||
@Test
|
||||
public void test_print_rfc1123_missingField() {
|
||||
TemporalAccessor test = YearMonth.of(2008, 6);
|
||||
DateTimeFormatter.RFC_1123_DATE_TIME.format(test);
|
||||
Assertions.assertThrows(DateTimeException.class, () -> {
|
||||
TemporalAccessor test = YearMonth.of(2008, 6);
|
||||
DateTimeFormatter.RFC_1123_DATE_TIME.format(test);
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test_rfc1123_basics() {
|
||||
assertEquals(DateTimeFormatter.RFC_1123_DATE_TIME.getChronology(), IsoChronology.INSTANCE);
|
||||
assertEquals(DateTimeFormatter.RFC_1123_DATE_TIME.getZone(), null);
|
||||
assertEquals(DateTimeFormatter.RFC_1123_DATE_TIME.getResolverStyle(), ResolverStyle.SMART);
|
||||
assertEquals(IsoChronology.INSTANCE, DateTimeFormatter.RFC_1123_DATE_TIME.getChronology());
|
||||
assertEquals(null, DateTimeFormatter.RFC_1123_DATE_TIME.getZone());
|
||||
assertEquals(ResolverStyle.SMART, DateTimeFormatter.RFC_1123_DATE_TIME.getResolverStyle());
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
@ -1403,11 +1431,11 @@ public class TCKDateTimeFormatters {
|
||||
|
||||
private void assertParseMatch(TemporalAccessor parsed, Expected expected) {
|
||||
for (TemporalField field : expected.fieldValues.keySet()) {
|
||||
assertEquals(parsed.isSupported(field), true);
|
||||
assertEquals(true, parsed.isSupported(field));
|
||||
parsed.getLong(field);
|
||||
}
|
||||
assertEquals(parsed.query(TemporalQueries.chronology()), expected.chrono);
|
||||
assertEquals(parsed.query(TemporalQueries.zoneId()), expected.zone);
|
||||
assertEquals(expected.chrono, parsed.query(TemporalQueries.chronology()));
|
||||
assertEquals(expected.zone, parsed.query(TemporalQueries.zoneId()));
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------------
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2013, 2020, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2013, 2025, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
@ -91,8 +91,9 @@ import static java.time.temporal.ChronoField.SECOND_OF_DAY;
|
||||
import static java.time.temporal.ChronoField.SECOND_OF_MINUTE;
|
||||
import static java.time.temporal.ChronoField.YEAR;
|
||||
import static java.time.temporal.ChronoField.YEAR_OF_ERA;
|
||||
import static org.testng.Assert.assertEquals;
|
||||
import static org.testng.Assert.fail;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.fail;
|
||||
|
||||
import java.time.Instant;
|
||||
import java.time.LocalDate;
|
||||
@ -122,13 +123,16 @@ import java.time.temporal.TemporalUnit;
|
||||
import java.time.temporal.ValueRange;
|
||||
import java.util.Map;
|
||||
|
||||
import org.testng.annotations.DataProvider;
|
||||
import org.testng.annotations.Test;
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.TestInstance;
|
||||
import org.junit.jupiter.params.ParameterizedTest;
|
||||
import org.junit.jupiter.params.provider.MethodSource;
|
||||
|
||||
/**
|
||||
* Test parse resolving.
|
||||
*/
|
||||
@Test
|
||||
@TestInstance(TestInstance.Lifecycle.PER_CLASS)
|
||||
public class TCKDateTimeParseResolver {
|
||||
// TODO: tests with weird TenporalField implementations
|
||||
// TODO: tests with non-ISO chronologies
|
||||
@ -137,7 +141,6 @@ public class TCKDateTimeParseResolver {
|
||||
private static final ZoneId EUROPE_PARIS = ZoneId.of("Europe/Paris");
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
@DataProvider(name="resolveOneNoChange")
|
||||
Object[][] data_resolveOneNoChange() {
|
||||
return new Object[][]{
|
||||
{YEAR, 2012},
|
||||
@ -148,20 +151,20 @@ public class TCKDateTimeParseResolver {
|
||||
};
|
||||
}
|
||||
|
||||
@Test(dataProvider="resolveOneNoChange")
|
||||
@ParameterizedTest
|
||||
@MethodSource("data_resolveOneNoChange")
|
||||
public void test_resolveOneNoChange(TemporalField field1, long value1) {
|
||||
String str = Long.toString(value1);
|
||||
DateTimeFormatter f = new DateTimeFormatterBuilder().appendValue(field1).toFormatter();
|
||||
|
||||
TemporalAccessor accessor = f.parse(str);
|
||||
assertEquals(accessor.query(TemporalQueries.localDate()), null);
|
||||
assertEquals(accessor.query(TemporalQueries.localTime()), null);
|
||||
assertEquals(accessor.isSupported(field1), true);
|
||||
assertEquals(accessor.getLong(field1), value1);
|
||||
assertEquals(null, accessor.query(TemporalQueries.localDate()));
|
||||
assertEquals(null, accessor.query(TemporalQueries.localTime()));
|
||||
assertEquals(true, accessor.isSupported(field1));
|
||||
assertEquals(value1, accessor.getLong(field1));
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
@DataProvider(name="resolveTwoNoChange")
|
||||
Object[][] data_resolveTwoNoChange() {
|
||||
return new Object[][]{
|
||||
{YEAR, 2012, MONTH_OF_YEAR, 5},
|
||||
@ -185,7 +188,8 @@ public class TCKDateTimeParseResolver {
|
||||
};
|
||||
}
|
||||
|
||||
@Test(dataProvider="resolveTwoNoChange")
|
||||
@ParameterizedTest
|
||||
@MethodSource("data_resolveTwoNoChange")
|
||||
public void test_resolveTwoNoChange(TemporalField field1, long value1, TemporalField field2, long value2) {
|
||||
String str = value1 + " " + value2;
|
||||
DateTimeFormatter f = new DateTimeFormatterBuilder()
|
||||
@ -193,16 +197,15 @@ public class TCKDateTimeParseResolver {
|
||||
.appendValue(field2).toFormatter();
|
||||
TemporalAccessor accessor = f.parse(str);
|
||||
|
||||
assertEquals(accessor.query(TemporalQueries.localDate()), null);
|
||||
assertEquals(accessor.query(TemporalQueries.localTime()), null);
|
||||
assertEquals(accessor.isSupported(field1), true);
|
||||
assertEquals(accessor.isSupported(field2), true);
|
||||
assertEquals(accessor.getLong(field1), value1);
|
||||
assertEquals(accessor.getLong(field2), value2);
|
||||
assertEquals(null, accessor.query(TemporalQueries.localDate()));
|
||||
assertEquals(null, accessor.query(TemporalQueries.localTime()));
|
||||
assertEquals(true, accessor.isSupported(field1));
|
||||
assertEquals(true, accessor.isSupported(field2));
|
||||
assertEquals(value1, accessor.getLong(field1));
|
||||
assertEquals(value2, accessor.getLong(field2));
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
@DataProvider(name="resolveThreeNoChange")
|
||||
Object[][] data_resolveThreeNoChange() {
|
||||
return new Object[][]{
|
||||
{YEAR, 2012, MONTH_OF_YEAR, 5, DAY_OF_WEEK, 5},
|
||||
@ -216,7 +219,8 @@ public class TCKDateTimeParseResolver {
|
||||
};
|
||||
}
|
||||
|
||||
@Test(dataProvider="resolveThreeNoChange")
|
||||
@ParameterizedTest
|
||||
@MethodSource("data_resolveThreeNoChange")
|
||||
public void test_resolveThreeNoChange(TemporalField field1, long value1, TemporalField field2, long value2, TemporalField field3, long value3) {
|
||||
String str = value1 + " " + value2 + " " + value3;
|
||||
DateTimeFormatter f = new DateTimeFormatterBuilder()
|
||||
@ -225,20 +229,19 @@ public class TCKDateTimeParseResolver {
|
||||
.appendValue(field3).toFormatter();
|
||||
TemporalAccessor accessor = f.parse(str);
|
||||
|
||||
assertEquals(accessor.query(TemporalQueries.localDate()), null);
|
||||
assertEquals(accessor.query(TemporalQueries.localTime()), null);
|
||||
assertEquals(accessor.isSupported(field1), true);
|
||||
assertEquals(accessor.isSupported(field2), true);
|
||||
assertEquals(accessor.isSupported(field3), true);
|
||||
assertEquals(accessor.getLong(field1), value1);
|
||||
assertEquals(accessor.getLong(field2), value2);
|
||||
assertEquals(accessor.getLong(field3), value3);
|
||||
assertEquals(null, accessor.query(TemporalQueries.localDate()));
|
||||
assertEquals(null, accessor.query(TemporalQueries.localTime()));
|
||||
assertEquals(true, accessor.isSupported(field1));
|
||||
assertEquals(true, accessor.isSupported(field2));
|
||||
assertEquals(true, accessor.isSupported(field3));
|
||||
assertEquals(value1, accessor.getLong(field1));
|
||||
assertEquals(value2, accessor.getLong(field2));
|
||||
assertEquals(value3, accessor.getLong(field3));
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------
|
||||
@DataProvider(name="resolveOneToField")
|
||||
Object[][] data_resolveOneToField() {
|
||||
return new Object[][]{
|
||||
{YEAR_OF_ERA, 2012, YEAR, 2012L, null, null},
|
||||
@ -251,7 +254,8 @@ public class TCKDateTimeParseResolver {
|
||||
};
|
||||
}
|
||||
|
||||
@Test(dataProvider="resolveOneToField")
|
||||
@ParameterizedTest
|
||||
@MethodSource("data_resolveOneToField")
|
||||
public void test_resolveOneToField(TemporalField field1, long value1,
|
||||
TemporalField expectedField1, Long expectedValue1,
|
||||
TemporalField expectedField2, Long expectedValue2) {
|
||||
@ -259,38 +263,37 @@ public class TCKDateTimeParseResolver {
|
||||
DateTimeFormatter f = new DateTimeFormatterBuilder().appendValue(field1).toFormatter();
|
||||
|
||||
TemporalAccessor accessor = f.parse(str);
|
||||
assertEquals(accessor.query(TemporalQueries.localDate()), null);
|
||||
assertEquals(accessor.query(TemporalQueries.localTime()), null);
|
||||
assertEquals(null, accessor.query(TemporalQueries.localDate()));
|
||||
assertEquals(null, accessor.query(TemporalQueries.localTime()));
|
||||
if (expectedField1 != null) {
|
||||
assertEquals(accessor.isSupported(expectedField1), true);
|
||||
assertEquals(accessor.getLong(expectedField1), expectedValue1.longValue());
|
||||
assertEquals(true, accessor.isSupported(expectedField1));
|
||||
assertEquals(expectedValue1.longValue(), accessor.getLong(expectedField1));
|
||||
}
|
||||
if (expectedField2 != null) {
|
||||
assertEquals(accessor.isSupported(expectedField2), true);
|
||||
assertEquals(accessor.getLong(expectedField2), expectedValue2.longValue());
|
||||
assertEquals(true, accessor.isSupported(expectedField2));
|
||||
assertEquals(expectedValue2.longValue(), accessor.getLong(expectedField2));
|
||||
}
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
@DataProvider(name="resolveOneToDate")
|
||||
Object[][] data_resolveOneToDate() {
|
||||
return new Object[][]{
|
||||
{EPOCH_DAY, 32, LocalDate.of(1970, 2, 2)},
|
||||
};
|
||||
}
|
||||
|
||||
@Test(dataProvider="resolveOneToDate")
|
||||
@ParameterizedTest
|
||||
@MethodSource("data_resolveOneToDate")
|
||||
public void test_resolveOneToDate(TemporalField field1, long value1, LocalDate expectedDate) {
|
||||
String str = Long.toString(value1);
|
||||
DateTimeFormatter f = new DateTimeFormatterBuilder().appendValue(field1).toFormatter();
|
||||
|
||||
TemporalAccessor accessor = f.parse(str);
|
||||
assertEquals(accessor.query(TemporalQueries.localDate()), expectedDate);
|
||||
assertEquals(accessor.query(TemporalQueries.localTime()), null);
|
||||
assertEquals(expectedDate, accessor.query(TemporalQueries.localDate()));
|
||||
assertEquals(null, accessor.query(TemporalQueries.localTime()));
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
@DataProvider(name="resolveOneToTime")
|
||||
Object[][] data_resolveOneToTime() {
|
||||
return new Object[][]{
|
||||
{HOUR_OF_DAY, 8, LocalTime.of(8, 0)},
|
||||
@ -304,20 +307,20 @@ public class TCKDateTimeParseResolver {
|
||||
};
|
||||
}
|
||||
|
||||
@Test(dataProvider="resolveOneToTime")
|
||||
@ParameterizedTest
|
||||
@MethodSource("data_resolveOneToTime")
|
||||
public void test_resolveOneToTime(TemporalField field1, long value1, LocalTime expectedTime) {
|
||||
String str = Long.toString(value1);
|
||||
DateTimeFormatter f = new DateTimeFormatterBuilder().appendValue(field1).toFormatter();
|
||||
|
||||
TemporalAccessor accessor = f.parse(str);
|
||||
assertEquals(accessor.query(TemporalQueries.localDate()), null);
|
||||
assertEquals(accessor.query(TemporalQueries.localTime()), expectedTime);
|
||||
assertEquals(null, accessor.query(TemporalQueries.localDate()));
|
||||
assertEquals(expectedTime, accessor.query(TemporalQueries.localTime()));
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------
|
||||
@DataProvider(name="resolveTwoToField")
|
||||
Object[][] data_resolveTwoToField() {
|
||||
return new Object[][]{
|
||||
// cross-check
|
||||
@ -330,7 +333,8 @@ public class TCKDateTimeParseResolver {
|
||||
};
|
||||
}
|
||||
|
||||
@Test(dataProvider="resolveTwoToField")
|
||||
@ParameterizedTest
|
||||
@MethodSource("data_resolveTwoToField")
|
||||
public void test_resolveTwoToField(TemporalField field1, long value1,
|
||||
TemporalField field2, long value2,
|
||||
TemporalField expectedField1, Long expectedValue1,
|
||||
@ -341,20 +345,19 @@ public class TCKDateTimeParseResolver {
|
||||
.appendValue(field2).toFormatter();
|
||||
|
||||
TemporalAccessor accessor = f.parse(str);
|
||||
assertEquals(accessor.query(TemporalQueries.localDate()), null);
|
||||
assertEquals(accessor.query(TemporalQueries.localTime()), null);
|
||||
assertEquals(null, accessor.query(TemporalQueries.localDate()));
|
||||
assertEquals(null, accessor.query(TemporalQueries.localTime()));
|
||||
if (expectedField1 != null) {
|
||||
assertEquals(accessor.isSupported(expectedField1), true);
|
||||
assertEquals(accessor.getLong(expectedField1), expectedValue1.longValue());
|
||||
assertEquals(true, accessor.isSupported(expectedField1));
|
||||
assertEquals(expectedValue1.longValue(), accessor.getLong(expectedField1));
|
||||
}
|
||||
if (expectedField2 != null) {
|
||||
assertEquals(accessor.isSupported(expectedField2), true);
|
||||
assertEquals(accessor.getLong(expectedField2), expectedValue2.longValue());
|
||||
assertEquals(true, accessor.isSupported(expectedField2));
|
||||
assertEquals(expectedValue2.longValue(), accessor.getLong(expectedField2));
|
||||
}
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
@DataProvider(name="resolveTwoToDate")
|
||||
Object[][] data_resolveTwoToDate() {
|
||||
return new Object[][]{
|
||||
// merge
|
||||
@ -379,7 +382,8 @@ public class TCKDateTimeParseResolver {
|
||||
};
|
||||
}
|
||||
|
||||
@Test(dataProvider="resolveTwoToDate")
|
||||
@ParameterizedTest
|
||||
@MethodSource("data_resolveTwoToDate")
|
||||
public void test_resolveTwoToDate(TemporalField field1, long value1,
|
||||
TemporalField field2, long value2,
|
||||
LocalDate expectedDate) {
|
||||
@ -389,12 +393,11 @@ public class TCKDateTimeParseResolver {
|
||||
.appendValue(field2).toFormatter();
|
||||
|
||||
TemporalAccessor accessor = f.parse(str);
|
||||
assertEquals(accessor.query(TemporalQueries.localDate()), expectedDate);
|
||||
assertEquals(accessor.query(TemporalQueries.localTime()), null);
|
||||
assertEquals(expectedDate, accessor.query(TemporalQueries.localDate()));
|
||||
assertEquals(null, accessor.query(TemporalQueries.localTime()));
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
@DataProvider(name="resolveTwoToTime")
|
||||
Object[][] data_resolveTwoToTime() {
|
||||
return new Object[][]{
|
||||
// merge
|
||||
@ -466,7 +469,8 @@ public class TCKDateTimeParseResolver {
|
||||
};
|
||||
}
|
||||
|
||||
@Test(dataProvider="resolveTwoToTime")
|
||||
@ParameterizedTest
|
||||
@MethodSource("data_resolveTwoToTime")
|
||||
public void test_resolveTwoToTime(TemporalField field1, long value1,
|
||||
TemporalField field2, long value2,
|
||||
LocalTime expectedTime) {
|
||||
@ -476,12 +480,11 @@ public class TCKDateTimeParseResolver {
|
||||
.appendValue(field2).toFormatter();
|
||||
|
||||
TemporalAccessor accessor = f.parse(str);
|
||||
assertEquals(accessor.query(TemporalQueries.localDate()), null);
|
||||
assertEquals(accessor.query(TemporalQueries.localTime()), expectedTime);
|
||||
assertEquals(null, accessor.query(TemporalQueries.localDate()));
|
||||
assertEquals(expectedTime, accessor.query(TemporalQueries.localTime()));
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
@DataProvider(name="resolveThreeToDate")
|
||||
Object[][] data_resolveThreeToDate() {
|
||||
return new Object[][]{
|
||||
// merge
|
||||
@ -497,7 +500,8 @@ public class TCKDateTimeParseResolver {
|
||||
};
|
||||
}
|
||||
|
||||
@Test(dataProvider="resolveThreeToDate")
|
||||
@ParameterizedTest
|
||||
@MethodSource("data_resolveThreeToDate")
|
||||
public void test_resolveThreeToDate(TemporalField field1, long value1,
|
||||
TemporalField field2, long value2,
|
||||
TemporalField field3, long value3,
|
||||
@ -509,12 +513,11 @@ public class TCKDateTimeParseResolver {
|
||||
.appendValue(field3).toFormatter();
|
||||
|
||||
TemporalAccessor accessor = f.parse(str);
|
||||
assertEquals(accessor.query(TemporalQueries.localDate()), expectedDate);
|
||||
assertEquals(accessor.query(TemporalQueries.localTime()), null);
|
||||
assertEquals(expectedDate, accessor.query(TemporalQueries.localDate()));
|
||||
assertEquals(null, accessor.query(TemporalQueries.localTime()));
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
@DataProvider(name="resolveFourToDate")
|
||||
Object[][] data_resolveFourToDate() {
|
||||
return new Object[][]{
|
||||
// merge
|
||||
@ -528,7 +531,8 @@ public class TCKDateTimeParseResolver {
|
||||
};
|
||||
}
|
||||
|
||||
@Test(dataProvider="resolveFourToDate")
|
||||
@ParameterizedTest
|
||||
@MethodSource("data_resolveFourToDate")
|
||||
public void test_resolveFourToDate(TemporalField field1, long value1,
|
||||
TemporalField field2, long value2,
|
||||
TemporalField field3, long value3,
|
||||
@ -542,12 +546,11 @@ public class TCKDateTimeParseResolver {
|
||||
.appendValue(field4).toFormatter();
|
||||
|
||||
TemporalAccessor accessor = f.parse(str);
|
||||
assertEquals(accessor.query(TemporalQueries.localDate()), expectedDate);
|
||||
assertEquals(accessor.query(TemporalQueries.localTime()), null);
|
||||
assertEquals(expectedDate, accessor.query(TemporalQueries.localDate()));
|
||||
assertEquals(null, accessor.query(TemporalQueries.localTime()));
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
@DataProvider(name="resolveFourToTime")
|
||||
Object[][] data_resolveFourToTime() {
|
||||
return new Object[][]{
|
||||
// merge
|
||||
@ -597,7 +600,8 @@ public class TCKDateTimeParseResolver {
|
||||
};
|
||||
}
|
||||
|
||||
@Test(dataProvider="resolveFourToTime")
|
||||
@ParameterizedTest
|
||||
@MethodSource("data_resolveFourToTime")
|
||||
public void test_resolveFourToTime(ResolverStyle style,
|
||||
long hour, long min, long sec, long nano, LocalTime expectedTime, Period excessPeriod) {
|
||||
DateTimeFormatter f = new DateTimeFormatterBuilder()
|
||||
@ -610,9 +614,9 @@ public class TCKDateTimeParseResolver {
|
||||
for (ResolverStyle s : styles) {
|
||||
if (expectedTime != null) {
|
||||
TemporalAccessor accessor = f.withResolverStyle(s).parse("");
|
||||
assertEquals(accessor.query(TemporalQueries.localDate()), null, "ResolverStyle: " + s);
|
||||
assertEquals(accessor.query(TemporalQueries.localTime()), expectedTime, "ResolverStyle: " + s);
|
||||
assertEquals(accessor.query(DateTimeFormatter.parsedExcessDays()), excessPeriod, "ResolverStyle: " + s);
|
||||
assertEquals(null, accessor.query(TemporalQueries.localDate()), "ResolverStyle: " + s);
|
||||
assertEquals(expectedTime, accessor.query(TemporalQueries.localTime()), "ResolverStyle: " + s);
|
||||
assertEquals(excessPeriod, accessor.query(DateTimeFormatter.parsedExcessDays()), "ResolverStyle: " + s);
|
||||
} else {
|
||||
try {
|
||||
f.withResolverStyle(style).parse("");
|
||||
@ -624,7 +628,8 @@ public class TCKDateTimeParseResolver {
|
||||
}
|
||||
}
|
||||
|
||||
@Test(dataProvider="resolveFourToTime")
|
||||
@ParameterizedTest
|
||||
@MethodSource("data_resolveFourToTime")
|
||||
public void test_resolveThreeToTime(ResolverStyle style,
|
||||
long hour, long min, long sec, long nano, LocalTime expectedTime, Period excessPeriod) {
|
||||
DateTimeFormatter f = new DateTimeFormatterBuilder()
|
||||
@ -636,9 +641,9 @@ public class TCKDateTimeParseResolver {
|
||||
for (ResolverStyle s : styles) {
|
||||
if (expectedTime != null) {
|
||||
TemporalAccessor accessor = f.withResolverStyle(s).parse("");
|
||||
assertEquals(accessor.query(TemporalQueries.localDate()), null, "ResolverStyle: " + s);
|
||||
assertEquals(accessor.query(TemporalQueries.localTime()), expectedTime.minusNanos(nano), "ResolverStyle: " + s);
|
||||
assertEquals(accessor.query(DateTimeFormatter.parsedExcessDays()), excessPeriod, "ResolverStyle: " + s);
|
||||
assertEquals(null, accessor.query(TemporalQueries.localDate()), "ResolverStyle: " + s);
|
||||
assertEquals(expectedTime.minusNanos(nano), accessor.query(TemporalQueries.localTime()), "ResolverStyle: " + s);
|
||||
assertEquals(excessPeriod, accessor.query(DateTimeFormatter.parsedExcessDays()), "ResolverStyle: " + s);
|
||||
} else {
|
||||
try {
|
||||
f.withResolverStyle(style).parse("");
|
||||
@ -650,7 +655,8 @@ public class TCKDateTimeParseResolver {
|
||||
}
|
||||
}
|
||||
|
||||
@Test(dataProvider="resolveFourToTime")
|
||||
@ParameterizedTest
|
||||
@MethodSource("data_resolveFourToTime")
|
||||
public void test_resolveFourToDateTime(ResolverStyle style,
|
||||
long hour, long min, long sec, long nano, LocalTime expectedTime, Period excessPeriod) {
|
||||
DateTimeFormatter f = new DateTimeFormatterBuilder()
|
||||
@ -665,15 +671,14 @@ public class TCKDateTimeParseResolver {
|
||||
LocalDate expectedDate = LocalDate.of(2012, 6, 30).plus(excessPeriod);
|
||||
for (ResolverStyle s : styles) {
|
||||
TemporalAccessor accessor = f.withResolverStyle(s).parse("");
|
||||
assertEquals(accessor.query(TemporalQueries.localDate()), expectedDate, "ResolverStyle: " + s);
|
||||
assertEquals(accessor.query(TemporalQueries.localTime()), expectedTime, "ResolverStyle: " + s);
|
||||
assertEquals(accessor.query(DateTimeFormatter.parsedExcessDays()), Period.ZERO, "ResolverStyle: " + s);
|
||||
assertEquals(expectedDate, accessor.query(TemporalQueries.localDate()), "ResolverStyle: " + s);
|
||||
assertEquals(expectedTime, accessor.query(TemporalQueries.localTime()), "ResolverStyle: " + s);
|
||||
assertEquals(Period.ZERO, accessor.query(DateTimeFormatter.parsedExcessDays()), "ResolverStyle: " + s);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
@DataProvider(name="resolveSecondOfDay")
|
||||
Object[][] data_resolveSecondOfDay() {
|
||||
return new Object[][]{
|
||||
{STRICT, 0, 0, 0},
|
||||
@ -696,16 +701,17 @@ public class TCKDateTimeParseResolver {
|
||||
};
|
||||
}
|
||||
|
||||
@Test(dataProvider="resolveSecondOfDay")
|
||||
@ParameterizedTest
|
||||
@MethodSource("data_resolveSecondOfDay")
|
||||
public void test_resolveSecondOfDay(ResolverStyle style, long value, Integer expectedSecond, int expectedDays) {
|
||||
String str = Long.toString(value);
|
||||
DateTimeFormatter f = new DateTimeFormatterBuilder().appendValue(SECOND_OF_DAY).toFormatter();
|
||||
|
||||
if (expectedSecond != null) {
|
||||
TemporalAccessor accessor = f.withResolverStyle(style).parse(str);
|
||||
assertEquals(accessor.query(TemporalQueries.localDate()), null);
|
||||
assertEquals(accessor.query(TemporalQueries.localTime()), LocalTime.ofSecondOfDay(expectedSecond));
|
||||
assertEquals(accessor.query(DateTimeFormatter.parsedExcessDays()), Period.ofDays(expectedDays));
|
||||
assertEquals(null, accessor.query(TemporalQueries.localDate()));
|
||||
assertEquals(LocalTime.ofSecondOfDay(expectedSecond), accessor.query(TemporalQueries.localTime()));
|
||||
assertEquals(Period.ofDays(expectedDays), accessor.query(DateTimeFormatter.parsedExcessDays()));
|
||||
} else {
|
||||
try {
|
||||
f.withResolverStyle(style).parse(str);
|
||||
@ -717,7 +723,6 @@ public class TCKDateTimeParseResolver {
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
@DataProvider(name="resolveMinuteOfDay")
|
||||
Object[][] data_resolveMinuteOfDay() {
|
||||
return new Object[][]{
|
||||
{STRICT, 0, 0, 0},
|
||||
@ -740,16 +745,17 @@ public class TCKDateTimeParseResolver {
|
||||
};
|
||||
}
|
||||
|
||||
@Test(dataProvider="resolveMinuteOfDay")
|
||||
@ParameterizedTest
|
||||
@MethodSource("data_resolveMinuteOfDay")
|
||||
public void test_resolveMinuteOfDay(ResolverStyle style, long value, Integer expectedMinute, int expectedDays) {
|
||||
String str = Long.toString(value);
|
||||
DateTimeFormatter f = new DateTimeFormatterBuilder().appendValue(MINUTE_OF_DAY).toFormatter();
|
||||
|
||||
if (expectedMinute != null) {
|
||||
TemporalAccessor accessor = f.withResolverStyle(style).parse(str);
|
||||
assertEquals(accessor.query(TemporalQueries.localDate()), null);
|
||||
assertEquals(accessor.query(TemporalQueries.localTime()), LocalTime.ofSecondOfDay(expectedMinute * 60));
|
||||
assertEquals(accessor.query(DateTimeFormatter.parsedExcessDays()), Period.ofDays(expectedDays));
|
||||
assertEquals(null, accessor.query(TemporalQueries.localDate()));
|
||||
assertEquals(LocalTime.ofSecondOfDay(expectedMinute * 60), accessor.query(TemporalQueries.localTime()));
|
||||
assertEquals(Period.ofDays(expectedDays), accessor.query(DateTimeFormatter.parsedExcessDays()));
|
||||
} else {
|
||||
try {
|
||||
f.withResolverStyle(style).parse(str);
|
||||
@ -761,7 +767,6 @@ public class TCKDateTimeParseResolver {
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
@DataProvider(name="resolveClockHourOfDay")
|
||||
Object[][] data_resolveClockHourOfDay() {
|
||||
return new Object[][]{
|
||||
{STRICT, 1, 1, 0},
|
||||
@ -784,16 +789,17 @@ public class TCKDateTimeParseResolver {
|
||||
};
|
||||
}
|
||||
|
||||
@Test(dataProvider="resolveClockHourOfDay")
|
||||
@ParameterizedTest
|
||||
@MethodSource("data_resolveClockHourOfDay")
|
||||
public void test_resolveClockHourOfDay(ResolverStyle style, long value, Integer expectedHour, int expectedDays) {
|
||||
String str = Long.toString(value);
|
||||
DateTimeFormatter f = new DateTimeFormatterBuilder().appendValue(CLOCK_HOUR_OF_DAY).toFormatter();
|
||||
|
||||
if (expectedHour != null) {
|
||||
TemporalAccessor accessor = f.withResolverStyle(style).parse(str);
|
||||
assertEquals(accessor.query(TemporalQueries.localDate()), null);
|
||||
assertEquals(accessor.query(TemporalQueries.localTime()), LocalTime.of(expectedHour, 0));
|
||||
assertEquals(accessor.query(DateTimeFormatter.parsedExcessDays()), Period.ofDays(expectedDays));
|
||||
assertEquals(null, accessor.query(TemporalQueries.localDate()));
|
||||
assertEquals(LocalTime.of(expectedHour, 0), accessor.query(TemporalQueries.localTime()));
|
||||
assertEquals(Period.ofDays(expectedDays), accessor.query(DateTimeFormatter.parsedExcessDays()));
|
||||
} else {
|
||||
try {
|
||||
f.withResolverStyle(style).parse(str);
|
||||
@ -805,7 +811,6 @@ public class TCKDateTimeParseResolver {
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
@DataProvider(name="resolveClockHourOfAmPm")
|
||||
Object[][] data_resolveClockHourOfAmPm() {
|
||||
return new Object[][]{
|
||||
{STRICT, 1, 1},
|
||||
@ -828,18 +833,19 @@ public class TCKDateTimeParseResolver {
|
||||
};
|
||||
}
|
||||
|
||||
@Test(dataProvider="resolveClockHourOfAmPm")
|
||||
@ParameterizedTest
|
||||
@MethodSource("data_resolveClockHourOfAmPm")
|
||||
public void test_resolveClockHourOfAmPm(ResolverStyle style, long value, Integer expectedValue) {
|
||||
String str = Long.toString(value);
|
||||
DateTimeFormatter f = new DateTimeFormatterBuilder().appendValue(CLOCK_HOUR_OF_AMPM).toFormatter();
|
||||
|
||||
if (expectedValue != null) {
|
||||
TemporalAccessor accessor = f.withResolverStyle(style).parse(str);
|
||||
assertEquals(accessor.query(TemporalQueries.localDate()), null);
|
||||
assertEquals(accessor.query(TemporalQueries.localTime()), null);
|
||||
assertEquals(accessor.isSupported(CLOCK_HOUR_OF_AMPM), false);
|
||||
assertEquals(accessor.isSupported(HOUR_OF_AMPM), true);
|
||||
assertEquals(accessor.getLong(HOUR_OF_AMPM), expectedValue.longValue());
|
||||
assertEquals(null, accessor.query(TemporalQueries.localDate()));
|
||||
assertEquals(null, accessor.query(TemporalQueries.localTime()));
|
||||
assertEquals(false, accessor.isSupported(CLOCK_HOUR_OF_AMPM));
|
||||
assertEquals(true, accessor.isSupported(HOUR_OF_AMPM));
|
||||
assertEquals(expectedValue.longValue(), accessor.getLong(HOUR_OF_AMPM));
|
||||
} else {
|
||||
try {
|
||||
f.withResolverStyle(style).parse(str);
|
||||
@ -851,7 +857,6 @@ public class TCKDateTimeParseResolver {
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
@DataProvider(name="resolveAmPm")
|
||||
Object[][] data_resolveAmPm() {
|
||||
return new Object[][]{
|
||||
{STRICT, 0, null, 0},
|
||||
@ -871,17 +876,18 @@ public class TCKDateTimeParseResolver {
|
||||
};
|
||||
}
|
||||
|
||||
@Test(dataProvider="resolveAmPm")
|
||||
@ParameterizedTest
|
||||
@MethodSource("data_resolveAmPm")
|
||||
public void test_resolveAmPm(ResolverStyle style, long value, LocalTime expectedTime, Integer expectedValue) {
|
||||
String str = Long.toString(value);
|
||||
DateTimeFormatter f = new DateTimeFormatterBuilder().appendValue(AMPM_OF_DAY).toFormatter();
|
||||
|
||||
if (expectedValue != null) {
|
||||
TemporalAccessor accessor = f.withResolverStyle(style).parse(str);
|
||||
assertEquals(accessor.query(TemporalQueries.localDate()), null);
|
||||
assertEquals(accessor.query(TemporalQueries.localTime()), expectedTime);
|
||||
assertEquals(accessor.isSupported(AMPM_OF_DAY), true);
|
||||
assertEquals(accessor.getLong(AMPM_OF_DAY), expectedValue.longValue());
|
||||
assertEquals(null, accessor.query(TemporalQueries.localDate()));
|
||||
assertEquals(expectedTime, accessor.query(TemporalQueries.localTime()));
|
||||
assertEquals(true, accessor.isSupported(AMPM_OF_DAY));
|
||||
assertEquals(expectedValue.longValue(), accessor.getLong(AMPM_OF_DAY));
|
||||
} else {
|
||||
try {
|
||||
f.withResolverStyle(style).parse(str);
|
||||
@ -898,9 +904,9 @@ public class TCKDateTimeParseResolver {
|
||||
public void test_withChronology_noOverride() {
|
||||
DateTimeFormatter f = new DateTimeFormatterBuilder().parseDefaulting(EPOCH_DAY, 2).toFormatter();
|
||||
TemporalAccessor accessor = f.parse("");
|
||||
assertEquals(accessor.query(TemporalQueries.localDate()), LocalDate.of(1970, 1, 3));
|
||||
assertEquals(accessor.query(TemporalQueries.localTime()), null);
|
||||
assertEquals(accessor.query(TemporalQueries.chronology()), IsoChronology.INSTANCE);
|
||||
assertEquals(LocalDate.of(1970, 1, 3), accessor.query(TemporalQueries.localDate()));
|
||||
assertEquals(null, accessor.query(TemporalQueries.localTime()));
|
||||
assertEquals(IsoChronology.INSTANCE, accessor.query(TemporalQueries.chronology()));
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -908,18 +914,18 @@ public class TCKDateTimeParseResolver {
|
||||
DateTimeFormatter f = new DateTimeFormatterBuilder().parseDefaulting(EPOCH_DAY, 2).toFormatter();
|
||||
f = f.withChronology(MinguoChronology.INSTANCE);
|
||||
TemporalAccessor accessor = f.parse("");
|
||||
assertEquals(accessor.query(TemporalQueries.localDate()), LocalDate.of(1970, 1, 3));
|
||||
assertEquals(accessor.query(TemporalQueries.localTime()), null);
|
||||
assertEquals(accessor.query(TemporalQueries.chronology()), MinguoChronology.INSTANCE);
|
||||
assertEquals(LocalDate.of(1970, 1, 3), accessor.query(TemporalQueries.localDate()));
|
||||
assertEquals(null, accessor.query(TemporalQueries.localTime()));
|
||||
assertEquals(MinguoChronology.INSTANCE, accessor.query(TemporalQueries.chronology()));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test_withChronology_parsedChronology_noOverride() {
|
||||
DateTimeFormatter f = new DateTimeFormatterBuilder().parseDefaulting(EPOCH_DAY, 2).appendChronologyId().toFormatter();
|
||||
TemporalAccessor accessor = f.parse("ThaiBuddhist");
|
||||
assertEquals(accessor.query(TemporalQueries.localDate()), LocalDate.of(1970, 1, 3));
|
||||
assertEquals(accessor.query(TemporalQueries.localTime()), null);
|
||||
assertEquals(accessor.query(TemporalQueries.chronology()), ThaiBuddhistChronology.INSTANCE);
|
||||
assertEquals(LocalDate.of(1970, 1, 3), accessor.query(TemporalQueries.localDate()));
|
||||
assertEquals(null, accessor.query(TemporalQueries.localTime()));
|
||||
assertEquals(ThaiBuddhistChronology.INSTANCE, accessor.query(TemporalQueries.chronology()));
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -927,9 +933,9 @@ public class TCKDateTimeParseResolver {
|
||||
DateTimeFormatter f = new DateTimeFormatterBuilder().parseDefaulting(EPOCH_DAY, 2).appendChronologyId().toFormatter();
|
||||
f = f.withChronology(MinguoChronology.INSTANCE);
|
||||
TemporalAccessor accessor = f.parse("ThaiBuddhist");
|
||||
assertEquals(accessor.query(TemporalQueries.localDate()), LocalDate.of(1970, 1, 3));
|
||||
assertEquals(accessor.query(TemporalQueries.localTime()), null);
|
||||
assertEquals(accessor.query(TemporalQueries.chronology()), ThaiBuddhistChronology.INSTANCE);
|
||||
assertEquals(LocalDate.of(1970, 1, 3), accessor.query(TemporalQueries.localDate()));
|
||||
assertEquals(null, accessor.query(TemporalQueries.localTime()));
|
||||
assertEquals(ThaiBuddhistChronology.INSTANCE, accessor.query(TemporalQueries.chronology()));
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
@ -938,9 +944,9 @@ public class TCKDateTimeParseResolver {
|
||||
public void test_withZone_noOverride() {
|
||||
DateTimeFormatter f = new DateTimeFormatterBuilder().parseDefaulting(EPOCH_DAY, 2).toFormatter();
|
||||
TemporalAccessor accessor = f.parse("");
|
||||
assertEquals(accessor.query(TemporalQueries.localDate()), LocalDate.of(1970, 1, 3));
|
||||
assertEquals(accessor.query(TemporalQueries.localTime()), null);
|
||||
assertEquals(accessor.query(TemporalQueries.zoneId()), null);
|
||||
assertEquals(LocalDate.of(1970, 1, 3), accessor.query(TemporalQueries.localDate()));
|
||||
assertEquals(null, accessor.query(TemporalQueries.localTime()));
|
||||
assertEquals(null, accessor.query(TemporalQueries.zoneId()));
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -948,18 +954,18 @@ public class TCKDateTimeParseResolver {
|
||||
DateTimeFormatter f = new DateTimeFormatterBuilder().parseDefaulting(EPOCH_DAY, 2).toFormatter();
|
||||
f = f.withZone(EUROPE_ATHENS);
|
||||
TemporalAccessor accessor = f.parse("");
|
||||
assertEquals(accessor.query(TemporalQueries.localDate()), LocalDate.of(1970, 1, 3));
|
||||
assertEquals(accessor.query(TemporalQueries.localTime()), null);
|
||||
assertEquals(accessor.query(TemporalQueries.zoneId()), EUROPE_ATHENS);
|
||||
assertEquals(LocalDate.of(1970, 1, 3), accessor.query(TemporalQueries.localDate()));
|
||||
assertEquals(null, accessor.query(TemporalQueries.localTime()));
|
||||
assertEquals(EUROPE_ATHENS, accessor.query(TemporalQueries.zoneId()));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test_withZone_parsedZone_noOverride() {
|
||||
DateTimeFormatter f = new DateTimeFormatterBuilder().parseDefaulting(EPOCH_DAY, 2).appendZoneId().toFormatter();
|
||||
TemporalAccessor accessor = f.parse("Europe/Paris");
|
||||
assertEquals(accessor.query(TemporalQueries.localDate()), LocalDate.of(1970, 1, 3));
|
||||
assertEquals(accessor.query(TemporalQueries.localTime()), null);
|
||||
assertEquals(accessor.query(TemporalQueries.zoneId()), EUROPE_PARIS);
|
||||
assertEquals(LocalDate.of(1970, 1, 3), accessor.query(TemporalQueries.localDate()));
|
||||
assertEquals(null, accessor.query(TemporalQueries.localTime()));
|
||||
assertEquals(EUROPE_PARIS, accessor.query(TemporalQueries.zoneId()));
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -967,9 +973,9 @@ public class TCKDateTimeParseResolver {
|
||||
DateTimeFormatter f = new DateTimeFormatterBuilder().parseDefaulting(EPOCH_DAY, 2).appendZoneId().toFormatter();
|
||||
f = f.withZone(EUROPE_ATHENS);
|
||||
TemporalAccessor accessor = f.parse("Europe/Paris");
|
||||
assertEquals(accessor.query(TemporalQueries.localDate()), LocalDate.of(1970, 1, 3));
|
||||
assertEquals(accessor.query(TemporalQueries.localTime()), null);
|
||||
assertEquals(accessor.query(TemporalQueries.zoneId()), EUROPE_PARIS);
|
||||
assertEquals(LocalDate.of(1970, 1, 3), accessor.query(TemporalQueries.localDate()));
|
||||
assertEquals(null, accessor.query(TemporalQueries.localTime()));
|
||||
assertEquals(EUROPE_PARIS, accessor.query(TemporalQueries.zoneId()));
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
@ -978,8 +984,8 @@ public class TCKDateTimeParseResolver {
|
||||
LocalTime lt = LocalTime.of(12, 30, 40);
|
||||
DateTimeFormatter f = new DateTimeFormatterBuilder().appendValue(new ResolvingField(lt)).toFormatter();
|
||||
TemporalAccessor accessor = f.parse("1234567890");
|
||||
assertEquals(accessor.query(TemporalQueries.localDate()), null);
|
||||
assertEquals(accessor.query(TemporalQueries.localTime()), lt);
|
||||
assertEquals(null, accessor.query(TemporalQueries.localDate()));
|
||||
assertEquals(lt, accessor.query(TemporalQueries.localTime()));
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------------
|
||||
@ -988,9 +994,9 @@ public class TCKDateTimeParseResolver {
|
||||
LocalDate ldt = LocalDate.of(2010, 6, 30);
|
||||
DateTimeFormatter f = new DateTimeFormatterBuilder().appendValue(new ResolvingField(ldt)).toFormatter();
|
||||
TemporalAccessor accessor = f.parse("1234567890");
|
||||
assertEquals(accessor.query(TemporalQueries.localDate()), LocalDate.of(2010, 6, 30));
|
||||
assertEquals(accessor.query(TemporalQueries.localTime()), null);
|
||||
assertEquals(accessor.query(TemporalQueries.chronology()), IsoChronology.INSTANCE);
|
||||
assertEquals(LocalDate.of(2010, 6, 30), accessor.query(TemporalQueries.localDate()));
|
||||
assertEquals(null, accessor.query(TemporalQueries.localTime()));
|
||||
assertEquals(IsoChronology.INSTANCE, accessor.query(TemporalQueries.chronology()));
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -999,24 +1005,28 @@ public class TCKDateTimeParseResolver {
|
||||
DateTimeFormatter f = new DateTimeFormatterBuilder().appendValue(new ResolvingField(mdt)).toFormatter();
|
||||
f = f.withChronology(MinguoChronology.INSTANCE);
|
||||
TemporalAccessor accessor = f.parse("1234567890");
|
||||
assertEquals(accessor.query(TemporalQueries.localDate()), LocalDate.from(mdt));
|
||||
assertEquals(accessor.query(TemporalQueries.localTime()), null);
|
||||
assertEquals(accessor.query(TemporalQueries.chronology()), MinguoChronology.INSTANCE);
|
||||
assertEquals(LocalDate.from(mdt), accessor.query(TemporalQueries.localDate()));
|
||||
assertEquals(null, accessor.query(TemporalQueries.localTime()));
|
||||
assertEquals(MinguoChronology.INSTANCE, accessor.query(TemporalQueries.chronology()));
|
||||
}
|
||||
|
||||
@Test(expectedExceptions = DateTimeParseException.class)
|
||||
@Test
|
||||
public void test_fieldResolvesToChronoLocalDate_noOverrideChrono_wrongChrono() {
|
||||
ChronoLocalDate cld = ThaiBuddhistChronology.INSTANCE.dateNow();
|
||||
DateTimeFormatter f = new DateTimeFormatterBuilder().appendValue(new ResolvingField(cld)).toFormatter();
|
||||
f.parse("1234567890");
|
||||
Assertions.assertThrows(DateTimeParseException.class, () -> {
|
||||
ChronoLocalDate cld = ThaiBuddhistChronology.INSTANCE.dateNow();
|
||||
DateTimeFormatter f = new DateTimeFormatterBuilder().appendValue(new ResolvingField(cld)).toFormatter();
|
||||
f.parse("1234567890");
|
||||
});
|
||||
}
|
||||
|
||||
@Test(expectedExceptions = DateTimeParseException.class)
|
||||
@Test
|
||||
public void test_fieldResolvesToChronoLocalDate_overrideChrono_wrongChrono() {
|
||||
ChronoLocalDate cld = ThaiBuddhistChronology.INSTANCE.dateNow();
|
||||
DateTimeFormatter f = new DateTimeFormatterBuilder().appendValue(new ResolvingField(cld)).toFormatter();
|
||||
f = f.withChronology(MinguoChronology.INSTANCE);
|
||||
f.parse("1234567890");
|
||||
Assertions.assertThrows(DateTimeParseException.class, () -> {
|
||||
ChronoLocalDate cld = ThaiBuddhistChronology.INSTANCE.dateNow();
|
||||
DateTimeFormatter f = new DateTimeFormatterBuilder().appendValue(new ResolvingField(cld)).toFormatter();
|
||||
f = f.withChronology(MinguoChronology.INSTANCE);
|
||||
f.parse("1234567890");
|
||||
});
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------------
|
||||
@ -1025,9 +1035,9 @@ public class TCKDateTimeParseResolver {
|
||||
LocalDateTime ldt = LocalDateTime.of(2010, 6, 30, 12, 30);
|
||||
DateTimeFormatter f = new DateTimeFormatterBuilder().appendValue(new ResolvingField(ldt)).toFormatter();
|
||||
TemporalAccessor accessor = f.parse("1234567890");
|
||||
assertEquals(accessor.query(TemporalQueries.localDate()), LocalDate.of(2010, 6, 30));
|
||||
assertEquals(accessor.query(TemporalQueries.localTime()), LocalTime.of(12, 30));
|
||||
assertEquals(accessor.query(TemporalQueries.chronology()), IsoChronology.INSTANCE);
|
||||
assertEquals(LocalDate.of(2010, 6, 30), accessor.query(TemporalQueries.localDate()));
|
||||
assertEquals(LocalTime.of(12, 30), accessor.query(TemporalQueries.localTime()));
|
||||
assertEquals(IsoChronology.INSTANCE, accessor.query(TemporalQueries.chronology()));
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -1036,24 +1046,28 @@ public class TCKDateTimeParseResolver {
|
||||
DateTimeFormatter f = new DateTimeFormatterBuilder().appendValue(new ResolvingField(mdt.atTime(LocalTime.NOON))).toFormatter();
|
||||
f = f.withChronology(MinguoChronology.INSTANCE);
|
||||
TemporalAccessor accessor = f.parse("1234567890");
|
||||
assertEquals(accessor.query(TemporalQueries.localDate()), LocalDate.from(mdt));
|
||||
assertEquals(accessor.query(TemporalQueries.localTime()), LocalTime.NOON);
|
||||
assertEquals(accessor.query(TemporalQueries.chronology()), MinguoChronology.INSTANCE);
|
||||
assertEquals(LocalDate.from(mdt), accessor.query(TemporalQueries.localDate()));
|
||||
assertEquals(LocalTime.NOON, accessor.query(TemporalQueries.localTime()));
|
||||
assertEquals(MinguoChronology.INSTANCE, accessor.query(TemporalQueries.chronology()));
|
||||
}
|
||||
|
||||
@Test(expectedExceptions = DateTimeParseException.class)
|
||||
@Test
|
||||
public void test_fieldResolvesToChronoLocalDateTime_noOverrideChrono_wrongChrono() {
|
||||
ChronoLocalDateTime<?> cldt = ThaiBuddhistChronology.INSTANCE.dateNow().atTime(LocalTime.NOON);
|
||||
DateTimeFormatter f = new DateTimeFormatterBuilder().appendValue(new ResolvingField(cldt)).toFormatter();
|
||||
f.parse("1234567890");
|
||||
Assertions.assertThrows(DateTimeParseException.class, () -> {
|
||||
ChronoLocalDateTime<?> cldt = ThaiBuddhistChronology.INSTANCE.dateNow().atTime(LocalTime.NOON);
|
||||
DateTimeFormatter f = new DateTimeFormatterBuilder().appendValue(new ResolvingField(cldt)).toFormatter();
|
||||
f.parse("1234567890");
|
||||
});
|
||||
}
|
||||
|
||||
@Test(expectedExceptions = DateTimeParseException.class)
|
||||
@Test
|
||||
public void test_fieldResolvesToChronoLocalDateTime_overrideChrono_wrongChrono() {
|
||||
ChronoLocalDateTime<?> cldt = ThaiBuddhistChronology.INSTANCE.dateNow().atTime(LocalTime.NOON);
|
||||
DateTimeFormatter f = new DateTimeFormatterBuilder().appendValue(new ResolvingField(cldt)).toFormatter();
|
||||
f = f.withChronology(MinguoChronology.INSTANCE);
|
||||
f.parse("1234567890");
|
||||
Assertions.assertThrows(DateTimeParseException.class, () -> {
|
||||
ChronoLocalDateTime<?> cldt = ThaiBuddhistChronology.INSTANCE.dateNow().atTime(LocalTime.NOON);
|
||||
DateTimeFormatter f = new DateTimeFormatterBuilder().appendValue(new ResolvingField(cldt)).toFormatter();
|
||||
f = f.withChronology(MinguoChronology.INSTANCE);
|
||||
f.parse("1234567890");
|
||||
});
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------------
|
||||
@ -1062,10 +1076,10 @@ public class TCKDateTimeParseResolver {
|
||||
ZonedDateTime zdt = ZonedDateTime.of(2010, 6, 30, 12, 30, 0, 0, EUROPE_PARIS);
|
||||
DateTimeFormatter f = new DateTimeFormatterBuilder().appendValue(new ResolvingField(zdt)).toFormatter();
|
||||
TemporalAccessor accessor = f.parse("1234567890");
|
||||
assertEquals(accessor.query(TemporalQueries.localDate()), LocalDate.of(2010, 6, 30));
|
||||
assertEquals(accessor.query(TemporalQueries.localTime()), LocalTime.of(12, 30));
|
||||
assertEquals(accessor.query(TemporalQueries.chronology()), IsoChronology.INSTANCE);
|
||||
assertEquals(accessor.query(TemporalQueries.zoneId()), EUROPE_PARIS);
|
||||
assertEquals(LocalDate.of(2010, 6, 30), accessor.query(TemporalQueries.localDate()));
|
||||
assertEquals(LocalTime.of(12, 30), accessor.query(TemporalQueries.localTime()));
|
||||
assertEquals(IsoChronology.INSTANCE, accessor.query(TemporalQueries.chronology()));
|
||||
assertEquals(EUROPE_PARIS, accessor.query(TemporalQueries.zoneId()));
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -1075,25 +1089,29 @@ public class TCKDateTimeParseResolver {
|
||||
DateTimeFormatter f = new DateTimeFormatterBuilder().appendValue(new ResolvingField(mzdt)).toFormatter();
|
||||
f = f.withChronology(MinguoChronology.INSTANCE);
|
||||
TemporalAccessor accessor = f.parse("1234567890");
|
||||
assertEquals(accessor.query(TemporalQueries.localDate()), LocalDate.from(mdt));
|
||||
assertEquals(accessor.query(TemporalQueries.localTime()), LocalTime.NOON);
|
||||
assertEquals(accessor.query(TemporalQueries.chronology()), MinguoChronology.INSTANCE);
|
||||
assertEquals(accessor.query(TemporalQueries.zoneId()), EUROPE_PARIS);
|
||||
assertEquals(LocalDate.from(mdt), accessor.query(TemporalQueries.localDate()));
|
||||
assertEquals(LocalTime.NOON, accessor.query(TemporalQueries.localTime()));
|
||||
assertEquals(MinguoChronology.INSTANCE, accessor.query(TemporalQueries.chronology()));
|
||||
assertEquals(EUROPE_PARIS, accessor.query(TemporalQueries.zoneId()));
|
||||
}
|
||||
|
||||
@Test(expectedExceptions = DateTimeParseException.class)
|
||||
@Test
|
||||
public void test_fieldResolvesToChronoZonedDateTime_noOverrideChrono_wrongChrono() {
|
||||
ChronoZonedDateTime<?> cldt = ThaiBuddhistChronology.INSTANCE.dateNow().atTime(LocalTime.NOON).atZone(EUROPE_PARIS);
|
||||
DateTimeFormatter f = new DateTimeFormatterBuilder().appendValue(new ResolvingField(cldt)).toFormatter();
|
||||
f.parse("1234567890");
|
||||
Assertions.assertThrows(DateTimeParseException.class, () -> {
|
||||
ChronoZonedDateTime<?> cldt = ThaiBuddhistChronology.INSTANCE.dateNow().atTime(LocalTime.NOON).atZone(EUROPE_PARIS);
|
||||
DateTimeFormatter f = new DateTimeFormatterBuilder().appendValue(new ResolvingField(cldt)).toFormatter();
|
||||
f.parse("1234567890");
|
||||
});
|
||||
}
|
||||
|
||||
@Test(expectedExceptions = DateTimeParseException.class)
|
||||
@Test
|
||||
public void test_fieldResolvesToChronoZonedDateTime_overrideChrono_wrongChrono() {
|
||||
ChronoZonedDateTime<?> cldt = ThaiBuddhistChronology.INSTANCE.dateNow().atTime(LocalTime.NOON).atZone(EUROPE_PARIS);
|
||||
DateTimeFormatter f = new DateTimeFormatterBuilder().appendValue(new ResolvingField(cldt)).toFormatter();
|
||||
f = f.withChronology(MinguoChronology.INSTANCE);
|
||||
f.parse("1234567890");
|
||||
Assertions.assertThrows(DateTimeParseException.class, () -> {
|
||||
ChronoZonedDateTime<?> cldt = ThaiBuddhistChronology.INSTANCE.dateNow().atTime(LocalTime.NOON).atZone(EUROPE_PARIS);
|
||||
DateTimeFormatter f = new DateTimeFormatterBuilder().appendValue(new ResolvingField(cldt)).toFormatter();
|
||||
f = f.withChronology(MinguoChronology.INSTANCE);
|
||||
f.parse("1234567890");
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -1101,15 +1119,17 @@ public class TCKDateTimeParseResolver {
|
||||
ZonedDateTime zdt = ZonedDateTime.of(2010, 6, 30, 12, 30, 0, 0, EUROPE_PARIS);
|
||||
DateTimeFormatter f = new DateTimeFormatterBuilder().appendValue(new ResolvingField(zdt)).toFormatter();
|
||||
f = f.withZone(EUROPE_PARIS);
|
||||
assertEquals(f.parse("1234567890", ZonedDateTime::from), zdt);
|
||||
assertEquals(zdt, f.parse("1234567890", ZonedDateTime::from));
|
||||
}
|
||||
|
||||
@Test(expectedExceptions = DateTimeParseException.class)
|
||||
@Test
|
||||
public void test_fieldResolvesToChronoZonedDateTime_overrideZone_wrongZone() {
|
||||
ZonedDateTime zdt = ZonedDateTime.of(2010, 6, 30, 12, 30, 0, 0, EUROPE_PARIS);
|
||||
DateTimeFormatter f = new DateTimeFormatterBuilder().appendValue(new ResolvingField(zdt)).toFormatter();
|
||||
f = f.withZone(ZoneId.of("Europe/London"));
|
||||
f.parse("1234567890");
|
||||
Assertions.assertThrows(DateTimeParseException.class, () -> {
|
||||
ZonedDateTime zdt = ZonedDateTime.of(2010, 6, 30, 12, 30, 0, 0, EUROPE_PARIS);
|
||||
DateTimeFormatter f = new DateTimeFormatterBuilder().appendValue(new ResolvingField(zdt)).toFormatter();
|
||||
f = f.withZone(ZoneId.of("Europe/London"));
|
||||
f.parse("1234567890");
|
||||
});
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------------
|
||||
@ -1170,15 +1190,15 @@ public class TCKDateTimeParseResolver {
|
||||
.appendValue(INSTANT_SECONDS).toFormatter();
|
||||
TemporalAccessor acc = fmt.parse("86402");
|
||||
Instant expected = Instant.ofEpochSecond(86402);
|
||||
assertEquals(acc.isSupported(INSTANT_SECONDS), true);
|
||||
assertEquals(acc.isSupported(NANO_OF_SECOND), true);
|
||||
assertEquals(acc.isSupported(MICRO_OF_SECOND), true);
|
||||
assertEquals(acc.isSupported(MILLI_OF_SECOND), true);
|
||||
assertEquals(acc.getLong(INSTANT_SECONDS), 86402L);
|
||||
assertEquals(acc.getLong(NANO_OF_SECOND), 0L);
|
||||
assertEquals(acc.getLong(MICRO_OF_SECOND), 0L);
|
||||
assertEquals(acc.getLong(MILLI_OF_SECOND), 0L);
|
||||
assertEquals(Instant.from(acc), expected);
|
||||
assertEquals(true, acc.isSupported(INSTANT_SECONDS));
|
||||
assertEquals(true, acc.isSupported(NANO_OF_SECOND));
|
||||
assertEquals(true, acc.isSupported(MICRO_OF_SECOND));
|
||||
assertEquals(true, acc.isSupported(MILLI_OF_SECOND));
|
||||
assertEquals(86402L, acc.getLong(INSTANT_SECONDS));
|
||||
assertEquals(0L, acc.getLong(NANO_OF_SECOND));
|
||||
assertEquals(0L, acc.getLong(MICRO_OF_SECOND));
|
||||
assertEquals(0L, acc.getLong(MILLI_OF_SECOND));
|
||||
assertEquals(expected, Instant.from(acc));
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -1187,15 +1207,15 @@ public class TCKDateTimeParseResolver {
|
||||
.appendValue(INSTANT_SECONDS).appendLiteral('.').appendValue(NANO_OF_SECOND).toFormatter();
|
||||
TemporalAccessor acc = fmt.parse("86402.123456789");
|
||||
Instant expected = Instant.ofEpochSecond(86402, 123456789);
|
||||
assertEquals(acc.isSupported(INSTANT_SECONDS), true);
|
||||
assertEquals(acc.isSupported(NANO_OF_SECOND), true);
|
||||
assertEquals(acc.isSupported(MICRO_OF_SECOND), true);
|
||||
assertEquals(acc.isSupported(MILLI_OF_SECOND), true);
|
||||
assertEquals(acc.getLong(INSTANT_SECONDS), 86402L);
|
||||
assertEquals(acc.getLong(NANO_OF_SECOND), 123456789L);
|
||||
assertEquals(acc.getLong(MICRO_OF_SECOND), 123456L);
|
||||
assertEquals(acc.getLong(MILLI_OF_SECOND), 123L);
|
||||
assertEquals(Instant.from(acc), expected);
|
||||
assertEquals(true, acc.isSupported(INSTANT_SECONDS));
|
||||
assertEquals(true, acc.isSupported(NANO_OF_SECOND));
|
||||
assertEquals(true, acc.isSupported(MICRO_OF_SECOND));
|
||||
assertEquals(true, acc.isSupported(MILLI_OF_SECOND));
|
||||
assertEquals(86402L, acc.getLong(INSTANT_SECONDS));
|
||||
assertEquals(123456789L, acc.getLong(NANO_OF_SECOND));
|
||||
assertEquals(123456L, acc.getLong(MICRO_OF_SECOND));
|
||||
assertEquals(123L, acc.getLong(MILLI_OF_SECOND));
|
||||
assertEquals(expected, Instant.from(acc));
|
||||
}
|
||||
|
||||
// SPEC: ChronoField.SECOND_OF_DAY
|
||||
@ -1204,14 +1224,14 @@ public class TCKDateTimeParseResolver {
|
||||
DateTimeFormatter fmt = new DateTimeFormatterBuilder()
|
||||
.appendValue(SECOND_OF_DAY).toFormatter();
|
||||
TemporalAccessor acc = fmt.parse("864");
|
||||
assertEquals(acc.isSupported(SECOND_OF_DAY), true);
|
||||
assertEquals(acc.isSupported(NANO_OF_SECOND), true);
|
||||
assertEquals(acc.isSupported(MICRO_OF_SECOND), true);
|
||||
assertEquals(acc.isSupported(MILLI_OF_SECOND), true);
|
||||
assertEquals(acc.getLong(SECOND_OF_DAY), 864L);
|
||||
assertEquals(acc.getLong(NANO_OF_SECOND), 0L);
|
||||
assertEquals(acc.getLong(MICRO_OF_SECOND), 0L);
|
||||
assertEquals(acc.getLong(MILLI_OF_SECOND), 0L);
|
||||
assertEquals(true, acc.isSupported(SECOND_OF_DAY));
|
||||
assertEquals(true, acc.isSupported(NANO_OF_SECOND));
|
||||
assertEquals(true, acc.isSupported(MICRO_OF_SECOND));
|
||||
assertEquals(true, acc.isSupported(MILLI_OF_SECOND));
|
||||
assertEquals(864L, acc.getLong(SECOND_OF_DAY));
|
||||
assertEquals(0L, acc.getLong(NANO_OF_SECOND));
|
||||
assertEquals(0L, acc.getLong(MICRO_OF_SECOND));
|
||||
assertEquals(0L, acc.getLong(MILLI_OF_SECOND));
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -1219,14 +1239,14 @@ public class TCKDateTimeParseResolver {
|
||||
DateTimeFormatter fmt = new DateTimeFormatterBuilder()
|
||||
.appendValue(SECOND_OF_DAY).appendLiteral('.').appendValue(NANO_OF_SECOND).toFormatter();
|
||||
TemporalAccessor acc = fmt.parse("864.123456789");
|
||||
assertEquals(acc.isSupported(SECOND_OF_DAY), true);
|
||||
assertEquals(acc.isSupported(NANO_OF_SECOND), true);
|
||||
assertEquals(acc.isSupported(MICRO_OF_SECOND), true);
|
||||
assertEquals(acc.isSupported(MILLI_OF_SECOND), true);
|
||||
assertEquals(acc.getLong(SECOND_OF_DAY), 864L);
|
||||
assertEquals(acc.getLong(NANO_OF_SECOND), 123456789L);
|
||||
assertEquals(acc.getLong(MICRO_OF_SECOND), 123456L);
|
||||
assertEquals(acc.getLong(MILLI_OF_SECOND), 123L);
|
||||
assertEquals(true, acc.isSupported(SECOND_OF_DAY));
|
||||
assertEquals(true, acc.isSupported(NANO_OF_SECOND));
|
||||
assertEquals(true, acc.isSupported(MICRO_OF_SECOND));
|
||||
assertEquals(true, acc.isSupported(MILLI_OF_SECOND));
|
||||
assertEquals(864L, acc.getLong(SECOND_OF_DAY));
|
||||
assertEquals(123456789L, acc.getLong(NANO_OF_SECOND));
|
||||
assertEquals(123456L, acc.getLong(MICRO_OF_SECOND));
|
||||
assertEquals(123L, acc.getLong(MILLI_OF_SECOND));
|
||||
}
|
||||
|
||||
// SPEC: ChronoField.SECOND_OF_MINUTE
|
||||
@ -1235,14 +1255,14 @@ public class TCKDateTimeParseResolver {
|
||||
DateTimeFormatter fmt = new DateTimeFormatterBuilder()
|
||||
.appendValue(SECOND_OF_MINUTE).toFormatter();
|
||||
TemporalAccessor acc = fmt.parse("32");
|
||||
assertEquals(acc.isSupported(SECOND_OF_MINUTE), true);
|
||||
assertEquals(acc.isSupported(NANO_OF_SECOND), true);
|
||||
assertEquals(acc.isSupported(MICRO_OF_SECOND), true);
|
||||
assertEquals(acc.isSupported(MILLI_OF_SECOND), true);
|
||||
assertEquals(acc.getLong(SECOND_OF_MINUTE), 32L);
|
||||
assertEquals(acc.getLong(NANO_OF_SECOND), 0L);
|
||||
assertEquals(acc.getLong(MICRO_OF_SECOND), 0L);
|
||||
assertEquals(acc.getLong(MILLI_OF_SECOND), 0L);
|
||||
assertEquals(true, acc.isSupported(SECOND_OF_MINUTE));
|
||||
assertEquals(true, acc.isSupported(NANO_OF_SECOND));
|
||||
assertEquals(true, acc.isSupported(MICRO_OF_SECOND));
|
||||
assertEquals(true, acc.isSupported(MILLI_OF_SECOND));
|
||||
assertEquals(32L, acc.getLong(SECOND_OF_MINUTE));
|
||||
assertEquals(0L, acc.getLong(NANO_OF_SECOND));
|
||||
assertEquals(0L, acc.getLong(MICRO_OF_SECOND));
|
||||
assertEquals(0L, acc.getLong(MILLI_OF_SECOND));
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -1250,14 +1270,14 @@ public class TCKDateTimeParseResolver {
|
||||
DateTimeFormatter fmt = new DateTimeFormatterBuilder()
|
||||
.appendValue(SECOND_OF_MINUTE).appendLiteral('.').appendValue(NANO_OF_SECOND).toFormatter();
|
||||
TemporalAccessor acc = fmt.parse("32.123456789");
|
||||
assertEquals(acc.isSupported(SECOND_OF_MINUTE), true);
|
||||
assertEquals(acc.isSupported(NANO_OF_SECOND), true);
|
||||
assertEquals(acc.isSupported(MICRO_OF_SECOND), true);
|
||||
assertEquals(acc.isSupported(MILLI_OF_SECOND), true);
|
||||
assertEquals(acc.getLong(SECOND_OF_MINUTE), 32L);
|
||||
assertEquals(acc.getLong(NANO_OF_SECOND), 123456789L);
|
||||
assertEquals(acc.getLong(MICRO_OF_SECOND), 123456L);
|
||||
assertEquals(acc.getLong(MILLI_OF_SECOND), 123L);
|
||||
assertEquals(true, acc.isSupported(SECOND_OF_MINUTE));
|
||||
assertEquals(true, acc.isSupported(NANO_OF_SECOND));
|
||||
assertEquals(true, acc.isSupported(MICRO_OF_SECOND));
|
||||
assertEquals(true, acc.isSupported(MILLI_OF_SECOND));
|
||||
assertEquals(32L, acc.getLong(SECOND_OF_MINUTE));
|
||||
assertEquals(123456789L, acc.getLong(NANO_OF_SECOND));
|
||||
assertEquals(123456L, acc.getLong(MICRO_OF_SECOND));
|
||||
assertEquals(123L, acc.getLong(MILLI_OF_SECOND));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2012, 2013, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2012, 2025, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
@ -62,7 +62,8 @@ package tck.java.time.format;
|
||||
import static java.time.temporal.ChronoField.DAY_OF_MONTH;
|
||||
import static java.time.temporal.ChronoField.DAY_OF_WEEK;
|
||||
import static java.time.temporal.ChronoField.MONTH_OF_YEAR;
|
||||
import static org.testng.Assert.assertEquals;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.Month;
|
||||
@ -74,25 +75,26 @@ import java.util.HashMap;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
|
||||
import org.testng.annotations.BeforeMethod;
|
||||
import org.testng.annotations.DataProvider;
|
||||
import org.testng.annotations.Test;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.TestInstance;
|
||||
import org.junit.jupiter.params.ParameterizedTest;
|
||||
import org.junit.jupiter.params.provider.MethodSource;
|
||||
|
||||
/**
|
||||
* Test text printing.
|
||||
*/
|
||||
@Test
|
||||
@TestInstance(TestInstance.Lifecycle.PER_CLASS)
|
||||
public class TCKDateTimeTextPrinting {
|
||||
|
||||
private DateTimeFormatterBuilder builder;
|
||||
|
||||
@BeforeMethod
|
||||
@BeforeEach
|
||||
public void setUp() {
|
||||
builder = new DateTimeFormatterBuilder();
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
@DataProvider(name="printText")
|
||||
Object[][] data_text() {
|
||||
return new Object[][] {
|
||||
{DAY_OF_WEEK, TextStyle.FULL, 1, "Monday"},
|
||||
@ -135,23 +137,25 @@ public class TCKDateTimeTextPrinting {
|
||||
};
|
||||
}
|
||||
|
||||
@Test(dataProvider="printText")
|
||||
@ParameterizedTest
|
||||
@MethodSource("data_text")
|
||||
public void test_appendText2arg_format(TemporalField field, TextStyle style, int value, String expected) throws Exception {
|
||||
DateTimeFormatter f = builder.appendText(field, style).toFormatter(Locale.ENGLISH);
|
||||
LocalDateTime dt = LocalDateTime.of(2010, 1, 1, 0, 0);
|
||||
dt = dt.with(field, value);
|
||||
String text = f.format(dt);
|
||||
assertEquals(text, expected);
|
||||
assertEquals(expected, text);
|
||||
}
|
||||
|
||||
@Test(dataProvider="printText")
|
||||
@ParameterizedTest
|
||||
@MethodSource("data_text")
|
||||
public void test_appendText1arg_format(TemporalField field, TextStyle style, int value, String expected) throws Exception {
|
||||
if (style == TextStyle.FULL) {
|
||||
DateTimeFormatter f = builder.appendText(field).toFormatter(Locale.ENGLISH);
|
||||
LocalDateTime dt = LocalDateTime.of(2010, 1, 1, 0, 0);
|
||||
dt = dt.with(field, value);
|
||||
String text = f.format(dt);
|
||||
assertEquals(text, expected);
|
||||
assertEquals(expected, text);
|
||||
}
|
||||
}
|
||||
|
||||
@ -175,7 +179,7 @@ public class TCKDateTimeTextPrinting {
|
||||
DateTimeFormatter f = builder.toFormatter();
|
||||
LocalDateTime dt = LocalDateTime.of(2010, 1, 1, 0, 0);
|
||||
for (Month month : Month.values()) {
|
||||
assertEquals(f.format(dt.with(month)), map.get((long) month.getValue()));
|
||||
assertEquals(map.get((long) month.getValue()), f.format(dt.with(month)));
|
||||
}
|
||||
}
|
||||
|
||||
@ -188,9 +192,9 @@ public class TCKDateTimeTextPrinting {
|
||||
builder.appendText(DAY_OF_MONTH, map);
|
||||
DateTimeFormatter f = builder.toFormatter();
|
||||
LocalDateTime dt = LocalDateTime.of(2010, 1, 1, 0, 0);
|
||||
assertEquals(f.format(dt.withDayOfMonth(1)), "1st");
|
||||
assertEquals(f.format(dt.withDayOfMonth(2)), "2nd");
|
||||
assertEquals(f.format(dt.withDayOfMonth(3)), "3rd");
|
||||
assertEquals("1st", f.format(dt.withDayOfMonth(1)));
|
||||
assertEquals("2nd", f.format(dt.withDayOfMonth(2)));
|
||||
assertEquals("3rd", f.format(dt.withDayOfMonth(3)));
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -200,7 +204,7 @@ public class TCKDateTimeTextPrinting {
|
||||
builder.appendText(MONTH_OF_YEAR, map);
|
||||
DateTimeFormatter f = builder.toFormatter();
|
||||
LocalDateTime dt = LocalDateTime.of(2010, 2, 1, 0, 0);
|
||||
assertEquals(f.format(dt), "2");
|
||||
assertEquals("2", f.format(dt));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2012, 2013, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2012, 2025, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
@ -59,71 +59,70 @@
|
||||
*/
|
||||
package tck.java.time.format;
|
||||
|
||||
import static org.testng.Assert.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
|
||||
import java.time.format.DecimalStyle;
|
||||
import java.util.Arrays;
|
||||
import java.util.Locale;
|
||||
import java.util.Set;
|
||||
|
||||
import org.testng.annotations.Test;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
/**
|
||||
* Test DecimalStyle.
|
||||
*/
|
||||
@Test
|
||||
public class TCKDecimalStyle {
|
||||
|
||||
@Test
|
||||
public void test_getAvailableLocales() {
|
||||
Set<Locale> locales = DecimalStyle.getAvailableLocales();
|
||||
assertEquals(locales.size() > 0, true, "locales: " + locales);
|
||||
assertEquals(locales.contains(Locale.US), true, "Locale.US not found in available Locales");
|
||||
assertEquals(true, locales.size() > 0, "locales: " + locales);
|
||||
assertEquals(true, locales.contains(Locale.US), "Locale.US not found in available Locales");
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
@Test
|
||||
public void test_of_Locale() {
|
||||
DecimalStyle loc1 = DecimalStyle.of(Locale.CANADA);
|
||||
assertEquals(loc1.getZeroDigit(), '0');
|
||||
assertEquals(loc1.getPositiveSign(), '+');
|
||||
assertEquals(loc1.getNegativeSign(), '-');
|
||||
assertEquals(loc1.getDecimalSeparator(), '.');
|
||||
assertEquals('0', loc1.getZeroDigit());
|
||||
assertEquals('+', loc1.getPositiveSign());
|
||||
assertEquals('-', loc1.getNegativeSign());
|
||||
assertEquals('.', loc1.getDecimalSeparator());
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
@Test
|
||||
public void test_STANDARD() {
|
||||
DecimalStyle loc1 = DecimalStyle.STANDARD;
|
||||
assertEquals(loc1.getZeroDigit(), '0');
|
||||
assertEquals(loc1.getPositiveSign(), '+');
|
||||
assertEquals(loc1.getNegativeSign(), '-');
|
||||
assertEquals(loc1.getDecimalSeparator(), '.');
|
||||
assertEquals('0', loc1.getZeroDigit());
|
||||
assertEquals('+', loc1.getPositiveSign());
|
||||
assertEquals('-', loc1.getNegativeSign());
|
||||
assertEquals('.', loc1.getDecimalSeparator());
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
@Test
|
||||
public void test_zeroDigit() {
|
||||
DecimalStyle base = DecimalStyle.STANDARD;
|
||||
assertEquals(base.withZeroDigit('A').getZeroDigit(), 'A');
|
||||
assertEquals('A', base.withZeroDigit('A').getZeroDigit());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test_positiveSign() {
|
||||
DecimalStyle base = DecimalStyle.STANDARD;
|
||||
assertEquals(base.withPositiveSign('A').getPositiveSign(), 'A');
|
||||
assertEquals('A', base.withPositiveSign('A').getPositiveSign());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test_negativeSign() {
|
||||
DecimalStyle base = DecimalStyle.STANDARD;
|
||||
assertEquals(base.withNegativeSign('A').getNegativeSign(), 'A');
|
||||
assertEquals('A', base.withNegativeSign('A').getNegativeSign());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test_decimalSeparator() {
|
||||
DecimalStyle base = DecimalStyle.STANDARD;
|
||||
assertEquals(base.withDecimalSeparator('A').getDecimalSeparator(), 'A');
|
||||
assertEquals('A', base.withDecimalSeparator('A').getDecimalSeparator());
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
@ -166,46 +165,46 @@ public class TCKDecimalStyle {
|
||||
public void test_equalsHashCode1() {
|
||||
DecimalStyle a = DecimalStyle.STANDARD;
|
||||
DecimalStyle b = DecimalStyle.STANDARD;
|
||||
assertEquals(a.equals(b), true);
|
||||
assertEquals(b.equals(a), true);
|
||||
assertEquals(a.hashCode(), b.hashCode());
|
||||
assertEquals(true, a.equals(b));
|
||||
assertEquals(true, b.equals(a));
|
||||
assertEquals(b.hashCode(), a.hashCode());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test_equalsHashCode2() {
|
||||
DecimalStyle a = DecimalStyle.STANDARD.withZeroDigit('A');
|
||||
DecimalStyle b = DecimalStyle.STANDARD.withZeroDigit('A');
|
||||
assertEquals(a.equals(b), true);
|
||||
assertEquals(b.equals(a), true);
|
||||
assertEquals(a.hashCode(), b.hashCode());
|
||||
assertEquals(true, a.equals(b));
|
||||
assertEquals(true, b.equals(a));
|
||||
assertEquals(b.hashCode(), a.hashCode());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test_equalsHashCode3() {
|
||||
DecimalStyle a = DecimalStyle.STANDARD.withZeroDigit('A');
|
||||
DecimalStyle b = DecimalStyle.STANDARD.withDecimalSeparator('A');
|
||||
assertEquals(a.equals(b), false);
|
||||
assertEquals(b.equals(a), false);
|
||||
assertEquals(false, a.equals(b));
|
||||
assertEquals(false, b.equals(a));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test_equalsHashCode_bad() {
|
||||
DecimalStyle a = DecimalStyle.STANDARD;
|
||||
assertEquals(a.equals(""), false);
|
||||
assertEquals(a.equals(null), false);
|
||||
assertEquals(false, a.equals(""));
|
||||
assertEquals(false, a.equals(null));
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
@Test
|
||||
public void test_toString_base() {
|
||||
DecimalStyle base = DecimalStyle.STANDARD;
|
||||
assertEquals(base.toString(), "DecimalStyle[0+-.]");
|
||||
assertEquals("DecimalStyle[0+-.]", base.toString());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test_toString_altered() {
|
||||
DecimalStyle base = DecimalStyle.of(Locale.US).withZeroDigit('A').withDecimalSeparator('@');
|
||||
assertEquals(base.toString(), "DecimalStyle[A+-@]");
|
||||
assertEquals("DecimalStyle[A+-@]", base.toString());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2012, 2022, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2012, 2025, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
@ -64,15 +64,16 @@ import java.time.format.FormatStyle;
|
||||
import java.time.temporal.Temporal;
|
||||
import java.util.Locale;
|
||||
|
||||
import static org.testng.Assert.assertEquals;
|
||||
|
||||
import org.testng.annotations.DataProvider;
|
||||
import org.testng.annotations.Test;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.TestInstance;
|
||||
import org.junit.jupiter.params.ParameterizedTest;
|
||||
import org.junit.jupiter.params.provider.MethodSource;
|
||||
|
||||
/**
|
||||
* Test.
|
||||
*/
|
||||
@Test
|
||||
@TestInstance(TestInstance.Lifecycle.PER_CLASS)
|
||||
public class TCKFormatStyle {
|
||||
|
||||
private static final ZoneId ZONEID_PARIS = ZoneId.of("Europe/Paris");
|
||||
@ -84,11 +85,10 @@ public class TCKFormatStyle {
|
||||
@Test
|
||||
public void test_valueOf() {
|
||||
for (FormatStyle style : FormatStyle.values()) {
|
||||
assertEquals(FormatStyle.valueOf(style.name()), style);
|
||||
assertEquals(style, FormatStyle.valueOf(style.name()));
|
||||
}
|
||||
}
|
||||
|
||||
@DataProvider(name="formatStyle")
|
||||
Object[][] data_formatStyle() {
|
||||
return new Object[][] {
|
||||
{ZonedDateTime.of(LocalDateTime.of(2001, 10, 2, 1, 2, 3), ZONEID_PARIS), FormatStyle.FULL, "Tuesday, October 2, 2001, 1:02:03\u202fAM Central European Summer Time Europe/Paris"},
|
||||
@ -103,11 +103,12 @@ public class TCKFormatStyle {
|
||||
};
|
||||
}
|
||||
|
||||
@Test(dataProvider = "formatStyle")
|
||||
@ParameterizedTest
|
||||
@MethodSource("data_formatStyle")
|
||||
public void test_formatStyle(Temporal temporal, FormatStyle style, String formattedStr) {
|
||||
DateTimeFormatterBuilder builder = new DateTimeFormatterBuilder();
|
||||
DateTimeFormatter formatter = builder.appendLocalized(style, style).appendLiteral(" ").appendZoneOrOffsetId().toFormatter();
|
||||
formatter = formatter.withLocale(Locale.US);
|
||||
assertEquals(formatter.format(temporal), formattedStr);
|
||||
assertEquals(formattedStr, formatter.format(temporal));
|
||||
}
|
||||
}
|
||||
|
||||
@ -59,10 +59,8 @@
|
||||
*/
|
||||
package tck.java.time.format;
|
||||
|
||||
import static org.testng.Assert.assertEquals;
|
||||
import static org.testng.Assert.fail;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
|
||||
import java.time.DateTimeException;
|
||||
import java.time.Instant;
|
||||
import java.time.OffsetDateTime;
|
||||
import java.time.Period;
|
||||
@ -73,8 +71,11 @@ import java.time.format.DateTimeParseException;
|
||||
import java.time.format.ResolverStyle;
|
||||
import java.time.temporal.TemporalAccessor;
|
||||
|
||||
import org.testng.annotations.DataProvider;
|
||||
import org.testng.annotations.Test;
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.TestInstance;
|
||||
import org.junit.jupiter.params.ParameterizedTest;
|
||||
import org.junit.jupiter.params.provider.MethodSource;
|
||||
|
||||
/*
|
||||
* @test
|
||||
@ -84,10 +85,9 @@ import org.testng.annotations.Test;
|
||||
/**
|
||||
* Test DateTimeFormatterBuilder.appendInstant().
|
||||
*/
|
||||
@Test
|
||||
@TestInstance(TestInstance.Lifecycle.PER_CLASS)
|
||||
public class TCKInstantPrinterParser {
|
||||
|
||||
@DataProvider(name="printGrouped")
|
||||
Object[][] data_printGrouped() {
|
||||
return new Object[][] {
|
||||
{0, 0, "1970-01-01T00:00:00Z"},
|
||||
@ -113,15 +113,15 @@ public class TCKInstantPrinterParser {
|
||||
};
|
||||
}
|
||||
|
||||
@Test(dataProvider="printGrouped")
|
||||
@ParameterizedTest
|
||||
@MethodSource("data_printGrouped")
|
||||
public void test_print_grouped(long instantSecs, int nano, String expected) {
|
||||
Instant instant = Instant.ofEpochSecond(instantSecs, nano);
|
||||
DateTimeFormatter f = new DateTimeFormatterBuilder().appendInstant().toFormatter();
|
||||
assertEquals(f.format(instant), expected);
|
||||
assertEquals(expected, f.format(instant));
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
@DataProvider(name="printDigits")
|
||||
Object[][] data_printDigits() {
|
||||
return new Object[][] {
|
||||
{-1, 0, 0, "1970-01-01T00:00:00Z"},
|
||||
@ -191,15 +191,15 @@ public class TCKInstantPrinterParser {
|
||||
};
|
||||
}
|
||||
|
||||
@Test(dataProvider="printDigits")
|
||||
@ParameterizedTest
|
||||
@MethodSource("data_printDigits")
|
||||
public void test_print_digits(int fractionalDigits, long instantSecs, int nano, String expected) {
|
||||
Instant instant = Instant.ofEpochSecond(instantSecs, nano);
|
||||
DateTimeFormatter f = new DateTimeFormatterBuilder().appendInstant(fractionalDigits).toFormatter();
|
||||
assertEquals(f.format(instant), expected);
|
||||
assertEquals(expected, f.format(instant));
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
@DataProvider(name="parseDigits")
|
||||
Object[][] data_parse_digits() {
|
||||
return new Object[][] {
|
||||
{0, 0, "1970-01-01T00:00:00Z"},
|
||||
@ -236,16 +236,16 @@ public class TCKInstantPrinterParser {
|
||||
};
|
||||
}
|
||||
|
||||
@Test(dataProvider="parseDigits")
|
||||
@ParameterizedTest
|
||||
@MethodSource("data_parse_digits")
|
||||
public void test_parse_digitsMinusOne(long instantSecs, int nano, String input) {
|
||||
Instant expected = Instant.ofEpochSecond(instantSecs, nano);
|
||||
DateTimeFormatter f = new DateTimeFormatterBuilder().appendInstant(-1).toFormatter();
|
||||
assertEquals(f.parse(input, Instant::from), expected);
|
||||
assertEquals(f.parse(input).query(DateTimeFormatter.parsedExcessDays()), Period.ZERO);
|
||||
assertEquals(f.parse(input).query(DateTimeFormatter.parsedLeapSecond()), Boolean.FALSE);
|
||||
assertEquals(expected, f.parse(input, Instant::from));
|
||||
assertEquals(Period.ZERO, f.parse(input).query(DateTimeFormatter.parsedExcessDays()));
|
||||
assertEquals(Boolean.FALSE, f.parse(input).query(DateTimeFormatter.parsedLeapSecond()));
|
||||
}
|
||||
|
||||
@DataProvider(name="parseNineDigits")
|
||||
Object[][] data_parse_ninedigits() {
|
||||
return new Object[][] {
|
||||
{0, 0, "1970-01-01T00:00:00.000000000Z"},
|
||||
@ -264,16 +264,16 @@ public class TCKInstantPrinterParser {
|
||||
};
|
||||
}
|
||||
|
||||
@Test(dataProvider="parseNineDigits")
|
||||
@ParameterizedTest
|
||||
@MethodSource("data_parse_ninedigits")
|
||||
public void test_parse_digitsNine(long instantSecs, int nano, String input) {
|
||||
DateTimeFormatter f = new DateTimeFormatterBuilder().appendInstant(9).toFormatter();
|
||||
Instant expected = Instant.ofEpochSecond(instantSecs, nano);
|
||||
assertEquals(f.parse(input, Instant::from), expected);
|
||||
assertEquals(f.parse(input).query(DateTimeFormatter.parsedExcessDays()), Period.ZERO);
|
||||
assertEquals(f.parse(input).query(DateTimeFormatter.parsedLeapSecond()), Boolean.FALSE);
|
||||
assertEquals(expected, f.parse(input, Instant::from));
|
||||
assertEquals(Period.ZERO, f.parse(input).query(DateTimeFormatter.parsedExcessDays()));
|
||||
assertEquals(Boolean.FALSE, f.parse(input).query(DateTimeFormatter.parsedLeapSecond()));
|
||||
}
|
||||
|
||||
@DataProvider(name="parseMaxMinInstant")
|
||||
Object[][] data_parse_MaxMinInstant() {
|
||||
return new Object[][] {
|
||||
{"+1000000000-12-31T23:59:59.999999999-01:00"},
|
||||
@ -281,10 +281,13 @@ public class TCKInstantPrinterParser {
|
||||
};
|
||||
}
|
||||
|
||||
@Test(dataProvider="parseMaxMinInstant", expectedExceptions=DateTimeParseException.class)
|
||||
@ParameterizedTest
|
||||
@MethodSource("data_parse_MaxMinInstant")
|
||||
public void test_invalid_Instant(String input) {
|
||||
DateTimeFormatter f = new DateTimeFormatterBuilder().appendInstant(-1).toFormatter();
|
||||
f.parse(input, Instant::from);
|
||||
Assertions.assertThrows(DateTimeParseException.class, () -> {
|
||||
DateTimeFormatter f = new DateTimeFormatterBuilder().appendInstant(-1).toFormatter();
|
||||
f.parse(input, Instant::from);
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -293,9 +296,9 @@ public class TCKInstantPrinterParser {
|
||||
DateTimeFormatter f = new DateTimeFormatterBuilder().appendInstant(-1).toFormatter();
|
||||
for (ResolverStyle style : ResolverStyle.values()) {
|
||||
TemporalAccessor parsed = f.withResolverStyle(style).parse("1970-02-03T24:00:00Z");
|
||||
assertEquals(parsed.query(Instant::from), expected);
|
||||
assertEquals(parsed.query(DateTimeFormatter.parsedExcessDays()), Period.ZERO);
|
||||
assertEquals(parsed.query(DateTimeFormatter.parsedLeapSecond()), Boolean.FALSE);
|
||||
assertEquals(expected, parsed.query(Instant::from));
|
||||
assertEquals(Period.ZERO, parsed.query(DateTimeFormatter.parsedExcessDays()));
|
||||
assertEquals(Boolean.FALSE, parsed.query(DateTimeFormatter.parsedLeapSecond()));
|
||||
}
|
||||
}
|
||||
|
||||
@ -305,9 +308,9 @@ public class TCKInstantPrinterParser {
|
||||
DateTimeFormatter f = new DateTimeFormatterBuilder().appendInstant(-1).toFormatter();
|
||||
for (ResolverStyle style : ResolverStyle.values()) {
|
||||
TemporalAccessor parsed = f.withResolverStyle(style).parse("1970-02-03T23:59:60.123456789Z");
|
||||
assertEquals(parsed.query(Instant::from), expected);
|
||||
assertEquals(parsed.query(DateTimeFormatter.parsedExcessDays()), Period.ZERO);
|
||||
assertEquals(parsed.query(DateTimeFormatter.parsedLeapSecond()), Boolean.TRUE);
|
||||
assertEquals(expected, parsed.query(Instant::from));
|
||||
assertEquals(Period.ZERO, parsed.query(DateTimeFormatter.parsedExcessDays()));
|
||||
assertEquals(Boolean.TRUE, parsed.query(DateTimeFormatter.parsedLeapSecond()));
|
||||
}
|
||||
}
|
||||
|
||||
@ -464,14 +467,14 @@ public class TCKInstantPrinterParser {
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
@Test(expectedExceptions=IllegalArgumentException.class)
|
||||
@Test
|
||||
public void test_appendInstant_tooSmall() {
|
||||
new DateTimeFormatterBuilder().appendInstant(-2);
|
||||
Assertions.assertThrows(IllegalArgumentException.class, () -> new DateTimeFormatterBuilder().appendInstant(-2));
|
||||
}
|
||||
|
||||
@Test(expectedExceptions=IllegalArgumentException.class)
|
||||
@Test
|
||||
public void test_appendInstant_tooBig() {
|
||||
new DateTimeFormatterBuilder().appendInstant(10);
|
||||
Assertions.assertThrows(IllegalArgumentException.class, () -> new DateTimeFormatterBuilder().appendInstant(10));
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------
|
||||
@ -479,7 +482,7 @@ public class TCKInstantPrinterParser {
|
||||
public void test_equality() {
|
||||
Instant instant1 = Instant.parse("2018-09-12T22:15:51+05:30");
|
||||
Instant instant2 = Instant.parse("2018-09-12T16:45:51Z");
|
||||
assertEquals(instant2, instant1);
|
||||
assertEquals(instant1, instant2);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2012, 2016, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2012, 2025, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
@ -60,7 +60,8 @@
|
||||
package tck.java.time.format;
|
||||
|
||||
import static java.time.temporal.ChronoField.YEAR_OF_ERA;
|
||||
import static org.testng.Assert.assertEquals;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
|
||||
import java.text.ParsePosition;
|
||||
import java.time.LocalDate;
|
||||
@ -72,21 +73,24 @@ import java.time.temporal.TemporalField;
|
||||
import java.time.temporal.WeekFields;
|
||||
import java.util.Locale;
|
||||
|
||||
import org.testng.annotations.DataProvider;
|
||||
import org.testng.annotations.Test;
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.TestInstance;
|
||||
import org.junit.jupiter.params.ParameterizedTest;
|
||||
import org.junit.jupiter.params.provider.MethodSource;
|
||||
|
||||
import test.java.time.format.AbstractTestPrinterParser;
|
||||
|
||||
/**
|
||||
* Test TCKLocalizedFieldParser.
|
||||
*/
|
||||
@Test
|
||||
@TestInstance(TestInstance.Lifecycle.PER_CLASS)
|
||||
public class TCKLocalizedFieldParser extends AbstractTestPrinterParser {
|
||||
public static final WeekFields WEEKDEF = WeekFields.of(Locale.US);
|
||||
public static final TemporalField WEEK_BASED_YEAR = WEEKDEF.weekBasedYear();
|
||||
public static final TemporalField WEEK_OF_WEEK_BASED_YEAR = WEEKDEF.weekOfWeekBasedYear();
|
||||
public static final TemporalField DAY_OF_WEEK = WEEKDEF.dayOfWeek();
|
||||
//-----------------------------------------------------------------------
|
||||
@DataProvider(name="FieldPatterns")
|
||||
Object[][] provider_fieldPatterns() {
|
||||
return new Object[][] {
|
||||
{"e", "6", 0, 1, 6},
|
||||
@ -101,7 +105,8 @@ public class TCKLocalizedFieldParser extends AbstractTestPrinterParser {
|
||||
};
|
||||
}
|
||||
|
||||
@Test(dataProvider="FieldPatterns")
|
||||
@ParameterizedTest
|
||||
@MethodSource("provider_fieldPatterns")
|
||||
public void test_parse_textField(String pattern, String text, int pos, int expectedPos, long expectedValue) {
|
||||
WeekFields weekDef = WeekFields.of(locale);
|
||||
TemporalField field = null;
|
||||
@ -128,16 +133,15 @@ public class TCKLocalizedFieldParser extends AbstractTestPrinterParser {
|
||||
DateTimeFormatter dtf = b.toFormatter(locale);
|
||||
TemporalAccessor parsed = dtf.parseUnresolved(text, ppos);
|
||||
if (ppos.getErrorIndex() != -1) {
|
||||
assertEquals(ppos.getErrorIndex(), expectedPos);
|
||||
assertEquals(expectedPos, ppos.getErrorIndex());
|
||||
} else {
|
||||
assertEquals(ppos.getIndex(), expectedPos, "Incorrect ending parse position");
|
||||
assertEquals(expectedPos, ppos.getIndex(), "Incorrect ending parse position");
|
||||
long value = parsed.getLong(field);
|
||||
assertEquals(value, expectedValue, "Value incorrect for " + field);
|
||||
assertEquals(expectedValue, value, "Value incorrect for " + field);
|
||||
}
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
@DataProvider(name="LocalWeekMonthYearPatterns")
|
||||
Object[][] provider_patternLocalDate() {
|
||||
return new Object[][] {
|
||||
{"e W M y", "1 1 1 2012", 0, 10, LocalDate.of(2012, 1, 1)},
|
||||
@ -153,28 +157,28 @@ public class TCKLocalizedFieldParser extends AbstractTestPrinterParser {
|
||||
};
|
||||
}
|
||||
|
||||
@Test(dataProvider="LocalWeekMonthYearPatterns")
|
||||
@ParameterizedTest
|
||||
@MethodSource("provider_patternLocalDate")
|
||||
public void test_parse_textLocalDate(String pattern, String text, int pos, int expectedPos, LocalDate expectedValue) {
|
||||
ParsePosition ppos = new ParsePosition(pos);
|
||||
DateTimeFormatterBuilder b = new DateTimeFormatterBuilder().appendPattern(pattern);
|
||||
DateTimeFormatter dtf = b.toFormatter(locale);
|
||||
TemporalAccessor parsed = dtf.parseUnresolved(text, ppos);
|
||||
if (ppos.getErrorIndex() != -1) {
|
||||
assertEquals(ppos.getErrorIndex(), expectedPos);
|
||||
assertEquals(expectedPos, ppos.getErrorIndex());
|
||||
} else {
|
||||
assertEquals(ppos.getIndex(), expectedPos, "Incorrect ending parse position");
|
||||
assertEquals(parsed.isSupported(YEAR_OF_ERA), true);
|
||||
assertEquals(parsed.isSupported(WeekFields.of(locale).dayOfWeek()), true);
|
||||
assertEquals(parsed.isSupported(WeekFields.of(locale).weekOfMonth()) ||
|
||||
parsed.isSupported(WeekFields.of(locale).weekOfYear()), true);
|
||||
assertEquals(expectedPos, ppos.getIndex(), "Incorrect ending parse position");
|
||||
assertEquals(true, parsed.isSupported(YEAR_OF_ERA));
|
||||
assertEquals(true, parsed.isSupported(WeekFields.of(locale).dayOfWeek()));
|
||||
assertEquals(true, parsed.isSupported(WeekFields.of(locale).weekOfMonth()) ||
|
||||
parsed.isSupported(WeekFields.of(locale).weekOfYear()));
|
||||
// ensure combination resolves into a date
|
||||
LocalDate result = LocalDate.parse(text, dtf);
|
||||
assertEquals(result, expectedValue, "LocalDate incorrect for " + pattern);
|
||||
assertEquals(expectedValue, result, "LocalDate incorrect for " + pattern);
|
||||
}
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
@DataProvider(name="LocalWeekBasedYearPatterns")
|
||||
Object[][] provider_patternLocalWeekBasedYearDate() {
|
||||
return new Object[][] {
|
||||
//{"w Y", "29 2012", 0, 7, LocalDate.of(2012, 7, 20)}, // Default lenient dayOfWeek not supported
|
||||
@ -190,28 +194,28 @@ public class TCKLocalizedFieldParser extends AbstractTestPrinterParser {
|
||||
};
|
||||
}
|
||||
|
||||
@Test(dataProvider="LocalWeekBasedYearPatterns")
|
||||
@ParameterizedTest
|
||||
@MethodSource("provider_patternLocalWeekBasedYearDate")
|
||||
public void test_parse_WeekBasedYear(String pattern, String text, int pos, int expectedPos, LocalDate expectedValue) {
|
||||
ParsePosition ppos = new ParsePosition(pos);
|
||||
DateTimeFormatterBuilder b = new DateTimeFormatterBuilder().appendPattern(pattern);
|
||||
DateTimeFormatter dtf = b.toFormatter(locale);
|
||||
TemporalAccessor parsed = dtf.parseUnresolved(text, ppos);
|
||||
if (ppos.getErrorIndex() != -1) {
|
||||
assertEquals(ppos.getErrorIndex(), expectedPos);
|
||||
assertEquals(expectedPos, ppos.getErrorIndex());
|
||||
} else {
|
||||
WeekFields weekDef = WeekFields.of(locale);
|
||||
assertEquals(ppos.getIndex(), expectedPos, "Incorrect ending parse position");
|
||||
assertEquals(parsed.isSupported(weekDef.dayOfWeek()), pattern.indexOf('e') >= 0);
|
||||
assertEquals(parsed.isSupported(weekDef.weekOfWeekBasedYear()), pattern.indexOf('w') >= 0);
|
||||
assertEquals(parsed.isSupported(weekDef.weekBasedYear()), pattern.indexOf('Y') >= 0);
|
||||
assertEquals(expectedPos, ppos.getIndex(), "Incorrect ending parse position");
|
||||
assertEquals(pattern.indexOf('e') >= 0, parsed.isSupported(weekDef.dayOfWeek()));
|
||||
assertEquals(pattern.indexOf('w') >= 0, parsed.isSupported(weekDef.weekOfWeekBasedYear()));
|
||||
assertEquals(pattern.indexOf('Y') >= 0, parsed.isSupported(weekDef.weekBasedYear()));
|
||||
// ensure combination resolves into a date
|
||||
LocalDate result = LocalDate.parse(text, dtf);
|
||||
assertEquals(result, expectedValue, "LocalDate incorrect for " + pattern + ", weekDef: " + weekDef);
|
||||
assertEquals(expectedValue, result, "LocalDate incorrect for " + pattern + ", weekDef: " + weekDef);
|
||||
}
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
@DataProvider(name = "adjacentValuePatterns1")
|
||||
Object[][] provider_adjacentValuePatterns1() {
|
||||
return new Object[][] {
|
||||
{"YYww", WEEK_BASED_YEAR, WEEK_OF_WEEK_BASED_YEAR, "1612", 2016, 12},
|
||||
@ -219,18 +223,18 @@ public class TCKLocalizedFieldParser extends AbstractTestPrinterParser {
|
||||
};
|
||||
}
|
||||
|
||||
@Test(dataProvider = "adjacentValuePatterns1")
|
||||
@ParameterizedTest
|
||||
@MethodSource("provider_adjacentValuePatterns1")
|
||||
public void test_adjacentValuePatterns1(String pattern, TemporalField field1, TemporalField field2,
|
||||
String text, int expected1, int expected2) {
|
||||
DateTimeFormatter df = new DateTimeFormatterBuilder()
|
||||
.appendPattern(pattern).toFormatter(Locale.US);
|
||||
ParsePosition ppos = new ParsePosition(0);
|
||||
TemporalAccessor parsed = df.parseUnresolved(text, ppos);
|
||||
assertEquals(parsed.get(field1), expected1);
|
||||
assertEquals(parsed.get(field2), expected2);
|
||||
assertEquals(expected1, parsed.get(field1));
|
||||
assertEquals(expected2, parsed.get(field2));
|
||||
}
|
||||
|
||||
@DataProvider(name = "adjacentValuePatterns2")
|
||||
Object[][] provider_adjacentValuePatterns2() {
|
||||
return new Object[][] {
|
||||
{"YYYYwwc", WEEK_BASED_YEAR, WEEK_OF_WEEK_BASED_YEAR, DAY_OF_WEEK,
|
||||
@ -242,16 +246,17 @@ public class TCKLocalizedFieldParser extends AbstractTestPrinterParser {
|
||||
};
|
||||
}
|
||||
|
||||
@Test(dataProvider = "adjacentValuePatterns2")
|
||||
@ParameterizedTest
|
||||
@MethodSource("provider_adjacentValuePatterns2")
|
||||
public void test_adjacentValuePatterns2(String pattern, TemporalField field1, TemporalField field2,
|
||||
TemporalField field3, String text, int expected1, int expected2, int expected3) {
|
||||
DateTimeFormatter df = new DateTimeFormatterBuilder()
|
||||
.appendPattern(pattern).toFormatter(Locale.US);
|
||||
ParsePosition ppos = new ParsePosition(0);
|
||||
TemporalAccessor parsed = df.parseUnresolved(text, ppos);
|
||||
assertEquals(parsed.get(field1), expected1);
|
||||
assertEquals(parsed.get(field2), expected2);
|
||||
assertEquals(parsed.get(field3), expected3);
|
||||
assertEquals(expected1, parsed.get(field1));
|
||||
assertEquals(expected2, parsed.get(field2));
|
||||
assertEquals(expected3, parsed.get(field3));
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -262,14 +267,13 @@ public class TCKLocalizedFieldParser extends AbstractTestPrinterParser {
|
||||
.appendPattern(pattern).toFormatter(Locale.US);
|
||||
ParsePosition ppos = new ParsePosition(0);
|
||||
TemporalAccessor parsed = df.parseUnresolved(text, ppos);
|
||||
assertEquals(parsed.get(DAY_OF_WEEK), 6);
|
||||
assertEquals(parsed.get(WEEK_OF_WEEK_BASED_YEAR), 29);
|
||||
assertEquals(6, parsed.get(DAY_OF_WEEK));
|
||||
assertEquals(29, parsed.get(WEEK_OF_WEEK_BASED_YEAR));
|
||||
LocalDate result = LocalDate.parse(text, df);
|
||||
LocalDate expectedValue = LocalDate.of(2012, 07, 20);
|
||||
assertEquals(result, expectedValue, "LocalDate incorrect for " + pattern);
|
||||
assertEquals(expectedValue, result, "LocalDate incorrect for " + pattern);
|
||||
}
|
||||
|
||||
@DataProvider(name = "invalidPatterns")
|
||||
Object[][] provider_invalidPatterns() {
|
||||
return new Object[][] {
|
||||
{"W", "01"},
|
||||
@ -279,8 +283,9 @@ public class TCKLocalizedFieldParser extends AbstractTestPrinterParser {
|
||||
};
|
||||
}
|
||||
|
||||
@Test(dataProvider = "invalidPatterns", expectedExceptions = DateTimeParseException.class)
|
||||
@ParameterizedTest
|
||||
@MethodSource("provider_invalidPatterns")
|
||||
public void test_invalidPatterns(String pattern, String value) {
|
||||
DateTimeFormatter.ofPattern(pattern).parse(value);
|
||||
Assertions.assertThrows(DateTimeParseException.class, () -> DateTimeFormatter.ofPattern(pattern).parse(value));
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2012, 2013, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2012, 2025, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
@ -59,26 +59,26 @@
|
||||
*/
|
||||
package tck.java.time.format;
|
||||
|
||||
import static org.testng.Assert.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
|
||||
import java.time.LocalDate;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.time.format.DateTimeFormatterBuilder;
|
||||
import java.time.temporal.WeekFields;
|
||||
|
||||
import org.testng.annotations.DataProvider;
|
||||
import org.testng.annotations.Test;
|
||||
import org.junit.jupiter.api.TestInstance;
|
||||
import org.junit.jupiter.params.ParameterizedTest;
|
||||
import org.junit.jupiter.params.provider.MethodSource;
|
||||
|
||||
import test.java.time.format.AbstractTestPrinterParser;
|
||||
|
||||
/**
|
||||
* Test LocalizedFieldPrinterParser.
|
||||
*/
|
||||
@Test
|
||||
@TestInstance(TestInstance.Lifecycle.PER_CLASS)
|
||||
public class TCKLocalizedFieldPrinter extends AbstractTestPrinterParser {
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
@DataProvider(name="Patterns")
|
||||
Object[][] provider_pad() {
|
||||
return new Object[][] {
|
||||
{"e", "6"},
|
||||
@ -92,18 +92,18 @@ public class TCKLocalizedFieldPrinter extends AbstractTestPrinterParser {
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
@Test(dataProvider="Patterns")
|
||||
@ParameterizedTest
|
||||
@MethodSource("provider_pad")
|
||||
public void test_localizedDayOfWeek(String pattern, String expected) {
|
||||
DateTimeFormatterBuilder b
|
||||
= new DateTimeFormatterBuilder().appendPattern(pattern);
|
||||
LocalDate date = LocalDate.of(2012, 7, 20);
|
||||
|
||||
String result = b.toFormatter(locale).format(date);
|
||||
assertEquals(result, expected, "Wrong output for pattern '" + pattern + "'.");
|
||||
assertEquals(expected, result, "Wrong output for pattern '" + pattern + "'.");
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
@DataProvider(name="LocalWeekBasedYearPatterns")
|
||||
Object[][] provider_patternLocalWeekBasedYearDate() {
|
||||
return new Object[][] {
|
||||
{"e w Y", "6 29 2012", LocalDate.of(2012, 7, 20)},
|
||||
@ -119,11 +119,12 @@ public class TCKLocalizedFieldPrinter extends AbstractTestPrinterParser {
|
||||
};
|
||||
}
|
||||
|
||||
@Test(dataProvider = "LocalWeekBasedYearPatterns")
|
||||
@ParameterizedTest
|
||||
@MethodSource("provider_patternLocalWeekBasedYearDate")
|
||||
public void test_print_WeekBasedYear(String pattern, String expectedText, LocalDate date) {
|
||||
DateTimeFormatter dtf = DateTimeFormatter.ofPattern(pattern, locale);
|
||||
String result = dtf.format(date);
|
||||
WeekFields weekDef = WeekFields.of(locale);
|
||||
assertEquals(result, expectedText, "Incorrect formatting for " + pattern + ", weekDef: " + weekDef);
|
||||
assertEquals(expectedText, result, "Incorrect formatting for " + pattern + ", weekDef: " + weekDef);
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2016, 2025, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
@ -27,12 +27,11 @@ import java.time.ZonedDateTime;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.util.Locale;
|
||||
|
||||
import org.testng.annotations.Test;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
/**
|
||||
* Test localized behavior of formatter.
|
||||
*/
|
||||
@Test
|
||||
public class TCKLocalizedOffsetIdPrinterParser {
|
||||
@Test
|
||||
public void test_localized_offset_parse() {
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2012, 2020, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2012, 2025, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
@ -59,7 +59,7 @@
|
||||
*/
|
||||
package tck.java.time.format;
|
||||
|
||||
import static org.testng.Assert.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
|
||||
import java.text.DateFormat;
|
||||
import java.text.ParsePosition;
|
||||
@ -72,33 +72,35 @@ import java.time.temporal.TemporalAccessor;
|
||||
import java.util.Date;
|
||||
import java.util.Locale;
|
||||
|
||||
import org.testng.annotations.BeforeMethod;
|
||||
import org.testng.annotations.DataProvider;
|
||||
import org.testng.annotations.Test;
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.TestInstance;
|
||||
import org.junit.jupiter.params.ParameterizedTest;
|
||||
import org.junit.jupiter.params.provider.MethodSource;
|
||||
|
||||
/**
|
||||
* Test localized behavior of formatter.
|
||||
*/
|
||||
@Test
|
||||
@TestInstance(TestInstance.Lifecycle.PER_CLASS)
|
||||
public class TCKLocalizedPrinterParser {
|
||||
|
||||
private DateTimeFormatterBuilder builder;
|
||||
private ParsePosition pos;
|
||||
|
||||
@BeforeMethod
|
||||
@BeforeEach
|
||||
public void setUp() {
|
||||
builder = new DateTimeFormatterBuilder();
|
||||
pos = new ParsePosition(0);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
@Test(expectedExceptions=IllegalArgumentException.class)
|
||||
@Test
|
||||
public void test_parse_negativePosition() {
|
||||
builder.appendLocalized(null, null);
|
||||
Assertions.assertThrows(IllegalArgumentException.class, () -> builder.appendLocalized(null, null));
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
@DataProvider(name="date")
|
||||
Object[][] data_date() {
|
||||
return new Object[][] {
|
||||
{LocalDate.of(2012, 6, 30), FormatStyle.SHORT, DateFormat.SHORT, Locale.UK},
|
||||
@ -124,7 +126,8 @@ public class TCKLocalizedPrinterParser {
|
||||
}
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
@Test(dataProvider="date")
|
||||
@ParameterizedTest
|
||||
@MethodSource("data_date")
|
||||
public void test_date_print(LocalDate date, FormatStyle dateStyle, int dateStyleOld, Locale locale) {
|
||||
DateFormat old = DateFormat.getDateInstance(dateStyleOld, locale);
|
||||
Date oldDate = new Date(date.getYear() - 1900, date.getMonthValue() - 1, date.getDayOfMonth());
|
||||
@ -132,11 +135,12 @@ public class TCKLocalizedPrinterParser {
|
||||
|
||||
DateTimeFormatter f = builder.appendLocalized(dateStyle, null).toFormatter(locale);
|
||||
String formatted = f.format(date);
|
||||
assertEquals(formatted, text);
|
||||
assertEquals(text, formatted);
|
||||
}
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
@Test(dataProvider="date")
|
||||
@ParameterizedTest
|
||||
@MethodSource("data_date")
|
||||
public void test_date_parse(LocalDate date, FormatStyle dateStyle, int dateStyleOld, Locale locale) {
|
||||
DateFormat old = DateFormat.getDateInstance(dateStyleOld, locale);
|
||||
Date oldDate = new Date(date.getYear() - 1900, date.getMonthValue() - 1, date.getDayOfMonth());
|
||||
@ -144,13 +148,12 @@ public class TCKLocalizedPrinterParser {
|
||||
|
||||
DateTimeFormatter f = builder.appendLocalized(dateStyle, null).toFormatter(locale);
|
||||
TemporalAccessor parsed = f.parse(text, pos);
|
||||
assertEquals(pos.getIndex(), text.length());
|
||||
assertEquals(pos.getErrorIndex(), -1);
|
||||
assertEquals(LocalDate.from(parsed), date);
|
||||
assertEquals(text.length(), pos.getIndex());
|
||||
assertEquals(-1, pos.getErrorIndex());
|
||||
assertEquals(date, LocalDate.from(parsed));
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
@DataProvider(name="time")
|
||||
Object[][] data_time() {
|
||||
return new Object[][] {
|
||||
{LocalTime.of(11, 30), FormatStyle.SHORT, DateFormat.SHORT, Locale.UK},
|
||||
@ -177,7 +180,8 @@ public class TCKLocalizedPrinterParser {
|
||||
}
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
@Test(dataProvider="time")
|
||||
@ParameterizedTest
|
||||
@MethodSource("data_time")
|
||||
public void test_time_print(LocalTime time, FormatStyle timeStyle, int timeStyleOld, Locale locale) {
|
||||
DateFormat old = DateFormat.getTimeInstance(timeStyleOld, locale);
|
||||
Date oldDate = new Date(1970 - 1900, 0, 0, time.getHour(), time.getMinute(), time.getSecond());
|
||||
@ -185,11 +189,12 @@ public class TCKLocalizedPrinterParser {
|
||||
|
||||
DateTimeFormatter f = builder.appendLocalized(null, timeStyle).toFormatter(locale);
|
||||
String formatted = f.format(time);
|
||||
assertEquals(formatted, text);
|
||||
assertEquals(text, formatted);
|
||||
}
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
@Test(dataProvider="time")
|
||||
@ParameterizedTest
|
||||
@MethodSource("data_time")
|
||||
public void test_time_parse(LocalTime time, FormatStyle timeStyle, int timeStyleOld, Locale locale) {
|
||||
DateFormat old = DateFormat.getTimeInstance(timeStyleOld, locale);
|
||||
Date oldDate = new Date(1970 - 1900, 0, 0, time.getHour(), time.getMinute(), time.getSecond());
|
||||
@ -197,9 +202,9 @@ public class TCKLocalizedPrinterParser {
|
||||
|
||||
DateTimeFormatter f = builder.appendLocalized(null, timeStyle).toFormatter(locale);
|
||||
TemporalAccessor parsed = f.parse(text, pos);
|
||||
assertEquals(pos.getIndex(), text.length());
|
||||
assertEquals(pos.getErrorIndex(), -1);
|
||||
assertEquals(LocalTime.from(parsed), time);
|
||||
assertEquals(text.length(), pos.getIndex());
|
||||
assertEquals(-1, pos.getErrorIndex());
|
||||
assertEquals(time, LocalTime.from(parsed));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2012, 2019, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2012, 2025, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
@ -59,7 +59,7 @@
|
||||
*/
|
||||
package tck.java.time.format;
|
||||
|
||||
import static org.testng.Assert.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.OffsetDateTime;
|
||||
@ -71,14 +71,17 @@ import java.time.format.DateTimeFormatterBuilder;
|
||||
import java.time.format.TextStyle;
|
||||
import java.util.Locale;
|
||||
|
||||
import org.testng.annotations.BeforeMethod;
|
||||
import org.testng.annotations.DataProvider;
|
||||
import org.testng.annotations.Test;
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.TestInstance;
|
||||
import org.junit.jupiter.params.ParameterizedTest;
|
||||
import org.junit.jupiter.params.provider.MethodSource;
|
||||
|
||||
/**
|
||||
* Test DateTimeFormatterBuilder.appendOffset().
|
||||
*/
|
||||
@Test
|
||||
@TestInstance(TestInstance.Lifecycle.PER_CLASS)
|
||||
public class TCKOffsetPrinterParser {
|
||||
|
||||
private static final ZoneOffset OFFSET_UTC = ZoneOffset.UTC;
|
||||
@ -104,13 +107,12 @@ public class TCKOffsetPrinterParser {
|
||||
private static final ZoneOffset OFFSET_M112345 = ZoneOffset.ofHoursMinutesSeconds(-11, -23, -45);
|
||||
private DateTimeFormatterBuilder builder;
|
||||
|
||||
@BeforeMethod
|
||||
@BeforeEach
|
||||
public void setUp() {
|
||||
builder = new DateTimeFormatterBuilder();
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
@DataProvider(name="print")
|
||||
Object[][] data_print() {
|
||||
return new Object[][] {
|
||||
{"+HH", "Z", DT_2012_06_30_12_30_40, OFFSET_UTC, "Z"},
|
||||
@ -441,7 +443,6 @@ public class TCKOffsetPrinterParser {
|
||||
};
|
||||
}
|
||||
|
||||
@DataProvider(name="print_localized")
|
||||
Object[][] data_print_localized() {
|
||||
return new Object[][] {
|
||||
{TextStyle.FULL, DT_2012_06_30_12_30_40, OFFSET_UTC, "GMT"},
|
||||
@ -469,16 +470,18 @@ public class TCKOffsetPrinterParser {
|
||||
};
|
||||
}
|
||||
|
||||
@Test(dataProvider="print")
|
||||
@ParameterizedTest
|
||||
@MethodSource("data_print")
|
||||
public void test_print(String offsetPattern, String noOffset, LocalDateTime ldt, ZoneId zone, String expected) {
|
||||
ZonedDateTime zdt = ldt.atZone(zone);
|
||||
builder.appendOffset(offsetPattern, noOffset);
|
||||
String output = builder.toFormatter().format(zdt);
|
||||
assertEquals(output, expected);
|
||||
assertEquals(expected, output);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
@Test(dataProvider="print")
|
||||
@ParameterizedTest
|
||||
@MethodSource("data_print")
|
||||
public void test_print_pattern_X(String offsetPattern, String noOffset, LocalDateTime ldt, ZoneId zone, String expected) {
|
||||
String pattern = null;
|
||||
if (offsetPattern.equals("+HHmm") && noOffset.equals("Z")) {
|
||||
@ -496,11 +499,12 @@ public class TCKOffsetPrinterParser {
|
||||
ZonedDateTime zdt = ldt.atZone(zone);
|
||||
builder.appendPattern(pattern);
|
||||
String output = builder.toFormatter().format(zdt);
|
||||
assertEquals(output, expected);
|
||||
assertEquals(expected, output);
|
||||
}
|
||||
}
|
||||
|
||||
@Test(dataProvider="print")
|
||||
@ParameterizedTest
|
||||
@MethodSource("data_print")
|
||||
public void test_print_pattern_x(String offsetPattern, String noOffset, LocalDateTime ldt, ZoneId zone, String expected) {
|
||||
String pattern = null;
|
||||
String zero = null;
|
||||
@ -524,117 +528,119 @@ public class TCKOffsetPrinterParser {
|
||||
ZonedDateTime zdt = ldt.atZone(zone);
|
||||
builder.appendPattern(pattern);
|
||||
String output = builder.toFormatter().format(zdt);
|
||||
assertEquals(output, (expected.equals("Z") ? zero : expected));
|
||||
assertEquals((expected.equals("Z") ? zero : expected), output);
|
||||
}
|
||||
}
|
||||
|
||||
@Test(dataProvider="print")
|
||||
@ParameterizedTest
|
||||
@MethodSource("data_print")
|
||||
public void test_print_pattern_Z(String offsetPattern, String noOffset, LocalDateTime ldt, ZoneId zone, String expected) {
|
||||
String pattern = null;
|
||||
if (offsetPattern.equals("+HHMM") && noOffset.equals("Z")) {
|
||||
ZonedDateTime zdt = ldt.atZone(zone);
|
||||
DateTimeFormatter f1 = new DateTimeFormatterBuilder().appendPattern("Z").toFormatter();
|
||||
String output1 = f1.format(zdt);
|
||||
assertEquals(output1, (expected.equals("Z") ? "+0000" : expected));
|
||||
assertEquals((expected.equals("Z") ? "+0000" : expected), output1);
|
||||
|
||||
DateTimeFormatter f2 = new DateTimeFormatterBuilder().appendPattern("ZZ").toFormatter();
|
||||
String output2 = f2.format(zdt);
|
||||
assertEquals(output2, (expected.equals("Z") ? "+0000" : expected));
|
||||
assertEquals((expected.equals("Z") ? "+0000" : expected), output2);
|
||||
|
||||
DateTimeFormatter f3 = new DateTimeFormatterBuilder().appendPattern("ZZZ").toFormatter();
|
||||
String output3 = f3.format(zdt);
|
||||
assertEquals(output3, (expected.equals("Z") ? "+0000" : expected));
|
||||
assertEquals((expected.equals("Z") ? "+0000" : expected), output3);
|
||||
} else if (offsetPattern.equals("+HH:MM:ss") && noOffset.equals("Z")) {
|
||||
ZonedDateTime zdt = ldt.atZone(zone);
|
||||
DateTimeFormatter f = new DateTimeFormatterBuilder().appendPattern("ZZZZZ").toFormatter();
|
||||
String output = f.format(zdt);
|
||||
assertEquals(output, expected);
|
||||
assertEquals(expected, output);
|
||||
}
|
||||
}
|
||||
|
||||
@Test(dataProvider="print_localized")
|
||||
@ParameterizedTest
|
||||
@MethodSource("data_print_localized")
|
||||
public void test_print_localized(TextStyle style, LocalDateTime ldt, ZoneOffset offset, String expected) {
|
||||
OffsetDateTime odt = OffsetDateTime.of(ldt, offset);
|
||||
ZonedDateTime zdt = ldt.atZone(offset);
|
||||
|
||||
DateTimeFormatter f = new DateTimeFormatterBuilder().appendLocalizedOffset(style)
|
||||
.toFormatter(Locale.US);
|
||||
assertEquals(f.format(odt), expected);
|
||||
assertEquals(f.format(zdt), expected);
|
||||
assertEquals(f.parse(expected, ZoneOffset::from), offset);
|
||||
assertEquals(expected, f.format(odt));
|
||||
assertEquals(expected, f.format(zdt));
|
||||
assertEquals(offset, f.parse(expected, ZoneOffset::from));
|
||||
|
||||
if (style == TextStyle.FULL) {
|
||||
f = new DateTimeFormatterBuilder().appendPattern("ZZZZ")
|
||||
.toFormatter(Locale.US);
|
||||
assertEquals(f.format(odt), expected);
|
||||
assertEquals(f.format(zdt), expected);
|
||||
assertEquals(f.parse(expected, ZoneOffset::from), offset);
|
||||
assertEquals(expected, f.format(odt));
|
||||
assertEquals(expected, f.format(zdt));
|
||||
assertEquals(offset, f.parse(expected, ZoneOffset::from));
|
||||
|
||||
f = new DateTimeFormatterBuilder().appendPattern("OOOO")
|
||||
.toFormatter(Locale.US);
|
||||
assertEquals(f.format(odt), expected);
|
||||
assertEquals(f.format(zdt), expected);
|
||||
assertEquals(f.parse(expected, ZoneOffset::from), offset);
|
||||
assertEquals(expected, f.format(odt));
|
||||
assertEquals(expected, f.format(zdt));
|
||||
assertEquals(offset, f.parse(expected, ZoneOffset::from));
|
||||
}
|
||||
|
||||
if (style == TextStyle.SHORT) {
|
||||
f = new DateTimeFormatterBuilder().appendPattern("O")
|
||||
.toFormatter(Locale.US);
|
||||
assertEquals(f.format(odt), expected);
|
||||
assertEquals(f.format(zdt), expected);
|
||||
assertEquals(f.parse(expected, ZoneOffset::from), offset);
|
||||
assertEquals(expected, f.format(odt));
|
||||
assertEquals(expected, f.format(zdt));
|
||||
assertEquals(offset, f.parse(expected, ZoneOffset::from));
|
||||
}
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
@Test(expectedExceptions=IllegalArgumentException.class)
|
||||
@Test
|
||||
public void test_print_pattern_X6rejected() {
|
||||
builder.appendPattern("XXXXXX");
|
||||
Assertions.assertThrows(IllegalArgumentException.class, () -> builder.appendPattern("XXXXXX"));
|
||||
}
|
||||
|
||||
@Test(expectedExceptions=IllegalArgumentException.class)
|
||||
@Test
|
||||
public void test_print_pattern_x6rejected() {
|
||||
builder.appendPattern("xxxxxx");
|
||||
Assertions.assertThrows(IllegalArgumentException.class, () -> builder.appendPattern("xxxxxx"));
|
||||
}
|
||||
|
||||
@Test(expectedExceptions=IllegalArgumentException.class)
|
||||
@Test
|
||||
public void test_print_pattern_Z6rejected() {
|
||||
builder.appendPattern("ZZZZZZ");
|
||||
Assertions.assertThrows(IllegalArgumentException.class, () -> builder.appendPattern("ZZZZZZ"));
|
||||
}
|
||||
|
||||
@Test(expectedExceptions=IllegalArgumentException.class)
|
||||
@Test
|
||||
public void test_print_pattern_O2rejected() {
|
||||
builder.appendPattern("OO");
|
||||
Assertions.assertThrows(IllegalArgumentException.class, () -> builder.appendPattern("OO"));
|
||||
}
|
||||
|
||||
@Test(expectedExceptions=IllegalArgumentException.class)
|
||||
@Test
|
||||
public void test_print_pattern_O3rejected() {
|
||||
builder.appendPattern("OOO");
|
||||
Assertions.assertThrows(IllegalArgumentException.class, () -> builder.appendPattern("OOO"));
|
||||
}
|
||||
|
||||
@Test(expectedExceptions=IllegalArgumentException.class)
|
||||
@Test
|
||||
public void test_print_pattern_O5rejected() {
|
||||
builder.appendPattern("OOOOO");
|
||||
Assertions.assertThrows(IllegalArgumentException.class, () -> builder.appendPattern("OOOOO"));
|
||||
}
|
||||
|
||||
@Test(expectedExceptions=IllegalArgumentException.class)
|
||||
@Test
|
||||
public void test_print_pattern_localzed_full_standline() {
|
||||
builder.appendLocalizedOffset(TextStyle.FULL_STANDALONE);
|
||||
Assertions.assertThrows(IllegalArgumentException.class, () -> builder.appendLocalizedOffset(TextStyle.FULL_STANDALONE));
|
||||
}
|
||||
|
||||
@Test(expectedExceptions=IllegalArgumentException.class)
|
||||
@Test
|
||||
public void test_print_pattern_localzed_short_standalone() {
|
||||
builder.appendLocalizedOffset(TextStyle.SHORT_STANDALONE);
|
||||
Assertions.assertThrows(IllegalArgumentException.class, () -> builder.appendLocalizedOffset(TextStyle.SHORT_STANDALONE));
|
||||
}
|
||||
|
||||
@Test(expectedExceptions=IllegalArgumentException.class)
|
||||
@Test
|
||||
public void test_print_pattern_localzed_narrow() {
|
||||
builder.appendLocalizedOffset(TextStyle.NARROW);
|
||||
Assertions.assertThrows(IllegalArgumentException.class, () -> builder.appendLocalizedOffset(TextStyle.NARROW));
|
||||
}
|
||||
|
||||
@Test(expectedExceptions=IllegalArgumentException.class)
|
||||
@Test
|
||||
public void test_print_pattern_localzed_narrow_standalone() {
|
||||
builder.appendLocalizedOffset(TextStyle.NARROW_STANDALONE);
|
||||
Assertions.assertThrows(IllegalArgumentException.class, () -> builder.appendLocalizedOffset(TextStyle.NARROW_STANDALONE));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2012, 2013, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2012, 2025, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
@ -61,48 +61,55 @@ package tck.java.time.format;
|
||||
|
||||
import static java.time.temporal.ChronoField.DAY_OF_MONTH;
|
||||
import static java.time.temporal.ChronoField.MONTH_OF_YEAR;
|
||||
import static org.testng.Assert.assertEquals;
|
||||
import static org.testng.Assert.assertNotNull;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||
|
||||
import java.text.ParsePosition;
|
||||
import java.time.format.DateTimeFormatterBuilder;
|
||||
import java.time.format.SignStyle;
|
||||
import java.time.temporal.TemporalAccessor;
|
||||
|
||||
import org.testng.annotations.BeforeMethod;
|
||||
import org.testng.annotations.DataProvider;
|
||||
import org.testng.annotations.Test;
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.TestInstance;
|
||||
import org.junit.jupiter.params.ParameterizedTest;
|
||||
import org.junit.jupiter.params.provider.MethodSource;
|
||||
|
||||
/**
|
||||
* Test padding behavior of formatter.
|
||||
*/
|
||||
@Test
|
||||
@TestInstance(TestInstance.Lifecycle.PER_CLASS)
|
||||
public class TCKPadPrinterParser {
|
||||
|
||||
private DateTimeFormatterBuilder builder;
|
||||
private ParsePosition pos;
|
||||
|
||||
@BeforeMethod
|
||||
@BeforeEach
|
||||
public void setUp() {
|
||||
builder = new DateTimeFormatterBuilder();
|
||||
pos = new ParsePosition(0);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
@Test(expectedExceptions=IndexOutOfBoundsException.class)
|
||||
@Test
|
||||
public void test_parse_negativePosition() {
|
||||
builder.padNext(3, '-').appendLiteral('Z');
|
||||
builder.toFormatter().parseUnresolved("--Z", new ParsePosition(-1));
|
||||
Assertions.assertThrows(IndexOutOfBoundsException.class, () -> {
|
||||
builder.padNext(3, '-').appendLiteral('Z');
|
||||
builder.toFormatter().parseUnresolved("--Z", new ParsePosition(-1));
|
||||
});
|
||||
}
|
||||
|
||||
@Test(expectedExceptions=IndexOutOfBoundsException.class)
|
||||
@Test
|
||||
public void test_parse_offEndPosition() {
|
||||
builder.padNext(3, '-').appendLiteral('Z');
|
||||
builder.toFormatter().parseUnresolved("--Z", new ParsePosition(4));
|
||||
Assertions.assertThrows(IndexOutOfBoundsException.class, () -> {
|
||||
builder.padNext(3, '-').appendLiteral('Z');
|
||||
builder.toFormatter().parseUnresolved("--Z", new ParsePosition(4));
|
||||
});
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
@DataProvider(name="parseStrict")
|
||||
Object[][] data_parseStrict() {
|
||||
return new Object[][] {
|
||||
{"222", 3, -1, 222},
|
||||
@ -126,22 +133,22 @@ public class TCKPadPrinterParser {
|
||||
};
|
||||
}
|
||||
|
||||
@Test(dataProvider="parseStrict")
|
||||
@ParameterizedTest
|
||||
@MethodSource("data_parseStrict")
|
||||
public void test_parseStrict(String text, int expectedIndex, int expectedErrorIndex, Number expectedMonth) {
|
||||
builder.padNext(3, '#').appendValue(MONTH_OF_YEAR, 1, 3, SignStyle.NORMAL);
|
||||
TemporalAccessor parsed = builder.toFormatter().parseUnresolved(text, pos);
|
||||
assertEquals(pos.getIndex(), expectedIndex);
|
||||
assertEquals(pos.getErrorIndex(), expectedErrorIndex);
|
||||
assertEquals(expectedIndex, pos.getIndex());
|
||||
assertEquals(expectedErrorIndex, pos.getErrorIndex());
|
||||
if (expectedMonth != null) {
|
||||
assertEquals(parsed.isSupported(MONTH_OF_YEAR), true);
|
||||
assertEquals(parsed.getLong(MONTH_OF_YEAR), expectedMonth.longValue());
|
||||
assertEquals(true, parsed.isSupported(MONTH_OF_YEAR));
|
||||
assertEquals(expectedMonth.longValue(), parsed.getLong(MONTH_OF_YEAR));
|
||||
} else {
|
||||
assertEquals(parsed, null);
|
||||
assertEquals(null, parsed);
|
||||
}
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
@DataProvider(name="parseLenient")
|
||||
Object[][] data_parseLenient() {
|
||||
return new Object[][] {
|
||||
{"222", 3, -1, 222},
|
||||
@ -167,17 +174,18 @@ public class TCKPadPrinterParser {
|
||||
};
|
||||
}
|
||||
|
||||
@Test(dataProvider="parseLenient")
|
||||
@ParameterizedTest
|
||||
@MethodSource("data_parseLenient")
|
||||
public void test_parseLenient(String text, int expectedIndex, int expectedErrorIndex, Number expectedMonth) {
|
||||
builder.parseLenient().padNext(3, '#').appendValue(MONTH_OF_YEAR, 1, 3, SignStyle.NORMAL);
|
||||
TemporalAccessor parsed = builder.toFormatter().parseUnresolved(text, pos);
|
||||
assertEquals(pos.getIndex(), expectedIndex);
|
||||
assertEquals(pos.getErrorIndex(), expectedErrorIndex);
|
||||
assertEquals(expectedIndex, pos.getIndex());
|
||||
assertEquals(expectedErrorIndex, pos.getErrorIndex());
|
||||
if (expectedMonth != null) {
|
||||
assertEquals(parsed.isSupported(MONTH_OF_YEAR), true);
|
||||
assertEquals(parsed.getLong(MONTH_OF_YEAR), expectedMonth.longValue());
|
||||
assertEquals(true, parsed.isSupported(MONTH_OF_YEAR));
|
||||
assertEquals(expectedMonth.longValue(), parsed.getLong(MONTH_OF_YEAR));
|
||||
} else {
|
||||
assertEquals(parsed, null);
|
||||
assertEquals(null, parsed);
|
||||
}
|
||||
}
|
||||
|
||||
@ -186,19 +194,19 @@ public class TCKPadPrinterParser {
|
||||
public void test_parse_decoratedStartsWithPad() {
|
||||
builder.padNext(8, '-').appendLiteral("-HELLO-");
|
||||
TemporalAccessor parsed = builder.toFormatter().parseUnresolved("--HELLO-", pos);
|
||||
assertEquals(pos.getIndex(), 0);
|
||||
assertEquals(pos.getErrorIndex(), 2);
|
||||
assertEquals(parsed, null);
|
||||
assertEquals(0, pos.getIndex());
|
||||
assertEquals(2, pos.getErrorIndex());
|
||||
assertEquals(null, parsed);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test_parse_decoratedStartsWithPad_number() {
|
||||
builder.padNext(3, '-').appendValue(MONTH_OF_YEAR, 1, 2, SignStyle.NORMAL);
|
||||
TemporalAccessor parsed = builder.toFormatter().parseUnresolved("--2", pos);
|
||||
assertEquals(pos.getIndex(), 3);
|
||||
assertEquals(pos.getErrorIndex(), -1);
|
||||
assertEquals(parsed.isSupported(MONTH_OF_YEAR), true);
|
||||
assertEquals(parsed.getLong(MONTH_OF_YEAR), 2L); // +2, not -2
|
||||
assertEquals(3, pos.getIndex());
|
||||
assertEquals(-1, pos.getErrorIndex());
|
||||
assertEquals(true, parsed.isSupported(MONTH_OF_YEAR));
|
||||
assertEquals(2L, parsed.getLong(MONTH_OF_YEAR)); // +2, not -2
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
@ -206,8 +214,8 @@ public class TCKPadPrinterParser {
|
||||
public void test_parse_decoratedEmpty_strict() {
|
||||
builder.padNext(4, '-').optionalStart().appendValue(DAY_OF_MONTH).optionalEnd();
|
||||
TemporalAccessor parsed = builder.toFormatter().parseUnresolved("----", pos);
|
||||
assertEquals(pos.getIndex(), 4);
|
||||
assertEquals(pos.getErrorIndex(), -1);
|
||||
assertEquals(4, pos.getIndex());
|
||||
assertEquals(-1, pos.getErrorIndex());
|
||||
assertNotNull(parsed);
|
||||
}
|
||||
|
||||
@ -215,8 +223,8 @@ public class TCKPadPrinterParser {
|
||||
public void test_parse_decoratedEmpty_lenient() {
|
||||
builder.parseLenient().padNext(4, '-').optionalStart().appendValue(DAY_OF_MONTH).optionalEnd();
|
||||
TemporalAccessor parsed = builder.toFormatter().parseUnresolved("----", pos);
|
||||
assertEquals(pos.getIndex(), 4);
|
||||
assertEquals(pos.getErrorIndex(), -1);
|
||||
assertEquals(4, pos.getIndex());
|
||||
assertEquals(-1, pos.getErrorIndex());
|
||||
assertNotNull(parsed);
|
||||
}
|
||||
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2012, 2013, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2012, 2025, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
@ -64,17 +64,18 @@ import java.time.format.ResolverStyle;
|
||||
import java.time.temporal.ChronoField;
|
||||
import java.time.temporal.TemporalAccessor;
|
||||
|
||||
import static org.testng.Assert.assertEquals;
|
||||
import static org.testng.Assert.assertTrue;
|
||||
import static org.testng.Assert.fail;
|
||||
|
||||
import org.testng.annotations.DataProvider;
|
||||
import org.testng.annotations.Test;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
import static org.junit.jupiter.api.Assertions.fail;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.TestInstance;
|
||||
import org.junit.jupiter.params.ParameterizedTest;
|
||||
import org.junit.jupiter.params.provider.MethodSource;
|
||||
|
||||
/**
|
||||
* Test.
|
||||
*/
|
||||
@Test
|
||||
@TestInstance(TestInstance.Lifecycle.PER_CLASS)
|
||||
public class TCKResolverStyle {
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
@ -83,11 +84,10 @@ public class TCKResolverStyle {
|
||||
@Test
|
||||
public void test_valueOf() {
|
||||
for (ResolverStyle style : ResolverStyle.values()) {
|
||||
assertEquals(ResolverStyle.valueOf(style.name()), style);
|
||||
assertEquals(style, ResolverStyle.valueOf(style.name()));
|
||||
}
|
||||
}
|
||||
|
||||
@DataProvider(name="resolverStyle")
|
||||
Object[][] data_resolverStyle() {
|
||||
return new Object[][] {
|
||||
{"2000/15/30", ResolverStyle.LENIENT, null, 2001, 3, 30},
|
||||
@ -104,7 +104,8 @@ public class TCKResolverStyle {
|
||||
};
|
||||
}
|
||||
|
||||
@Test(dataProvider = "resolverStyle")
|
||||
@ParameterizedTest
|
||||
@MethodSource("data_resolverStyle")
|
||||
public void test_resolverStyle(String str, ResolverStyle style, Class<?> expectedEx, int year, int month, int day) {
|
||||
DateTimeFormatterBuilder builder = new DateTimeFormatterBuilder();
|
||||
builder.appendValue(ChronoField.YEAR_OF_ERA);
|
||||
@ -122,9 +123,9 @@ public class TCKResolverStyle {
|
||||
formatter = formatter.withResolverStyle(style);
|
||||
if (expectedEx == null) {
|
||||
TemporalAccessor accessor = formatter.parse(str);
|
||||
assertEquals(accessor.get(ChronoField.YEAR_OF_ERA), year);
|
||||
assertEquals(accessor.get(ChronoField.MONTH_OF_YEAR), month);
|
||||
assertEquals(accessor.get(ChronoField.DAY_OF_MONTH), day);
|
||||
assertEquals(year, accessor.get(ChronoField.YEAR_OF_ERA));
|
||||
assertEquals(month, accessor.get(ChronoField.MONTH_OF_YEAR));
|
||||
assertEquals(day, accessor.get(ChronoField.DAY_OF_MONTH));
|
||||
} else {
|
||||
try {
|
||||
formatter.parse(str);
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2012, 2013, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2012, 2025, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
@ -62,17 +62,18 @@ import java.time.format.DateTimeFormatterBuilder;
|
||||
import java.time.format.SignStyle;
|
||||
import java.time.temporal.ChronoField;
|
||||
|
||||
import static org.testng.Assert.assertEquals;
|
||||
import static org.testng.Assert.assertTrue;
|
||||
import static org.testng.Assert.fail;
|
||||
|
||||
import org.testng.annotations.DataProvider;
|
||||
import org.testng.annotations.Test;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
import static org.junit.jupiter.api.Assertions.fail;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.TestInstance;
|
||||
import org.junit.jupiter.params.ParameterizedTest;
|
||||
import org.junit.jupiter.params.provider.MethodSource;
|
||||
|
||||
/**
|
||||
* Test.
|
||||
*/
|
||||
@Test
|
||||
@TestInstance(TestInstance.Lifecycle.PER_CLASS)
|
||||
public class TCKSignStyle {
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
@ -81,11 +82,10 @@ public class TCKSignStyle {
|
||||
@Test
|
||||
public void test_valueOf() {
|
||||
for (SignStyle style : SignStyle.values()) {
|
||||
assertEquals(SignStyle.valueOf(style.name()), style);
|
||||
assertEquals(style, SignStyle.valueOf(style.name()));
|
||||
}
|
||||
}
|
||||
|
||||
@DataProvider(name="signStyle")
|
||||
Object[][] data_signStyle() {
|
||||
return new Object[][] {
|
||||
{LocalDate.of(0, 10, 2), SignStyle.ALWAYS, null, "+00"},
|
||||
@ -113,7 +113,8 @@ public class TCKSignStyle {
|
||||
};
|
||||
}
|
||||
|
||||
@Test(dataProvider = "signStyle")
|
||||
@ParameterizedTest
|
||||
@MethodSource("data_signStyle")
|
||||
public void test_signStyle(LocalDate localDate, SignStyle style, Class<?> expectedEx, String expectedStr) {
|
||||
DateTimeFormatterBuilder builder = new DateTimeFormatterBuilder();
|
||||
DateTimeFormatter formatter = builder.appendValue(ChronoField.YEAR, 2, 4, style)
|
||||
@ -121,7 +122,7 @@ public class TCKSignStyle {
|
||||
formatter = formatter.withZone(ZoneOffset.UTC);
|
||||
if (expectedEx == null) {
|
||||
String output = formatter.format(localDate);
|
||||
assertEquals(output, expectedStr);
|
||||
assertEquals(expectedStr, output);
|
||||
} else {
|
||||
try {
|
||||
formatter.format(localDate);
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2013, 2025, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
@ -59,28 +59,27 @@
|
||||
*/
|
||||
package tck.java.time.format;
|
||||
|
||||
import static org.testng.Assert.assertEquals;
|
||||
import static org.testng.Assert.assertTrue;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
import java.time.format.TextStyle;
|
||||
|
||||
import org.testng.annotations.Test;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
/**
|
||||
* Test DecimalStyle.
|
||||
*/
|
||||
@Test
|
||||
public class TCKTextStyle {
|
||||
|
||||
@Test
|
||||
public void test_standaloneNormal() {
|
||||
assertEquals(TextStyle.FULL, TextStyle.FULL_STANDALONE.asNormal());
|
||||
assertEquals(TextStyle.SHORT, TextStyle.SHORT.asNormal());
|
||||
assertEquals(TextStyle.NARROW, TextStyle.NARROW.asNormal());
|
||||
assertEquals(TextStyle.FULL_STANDALONE.asNormal(), TextStyle.FULL);
|
||||
assertEquals(TextStyle.SHORT.asNormal(), TextStyle.SHORT);
|
||||
assertEquals(TextStyle.NARROW.asNormal(), TextStyle.NARROW);
|
||||
|
||||
assertEquals(TextStyle.FULL_STANDALONE, TextStyle.FULL_STANDALONE.asStandalone());
|
||||
assertEquals(TextStyle.SHORT_STANDALONE, TextStyle.SHORT.asStandalone());
|
||||
assertEquals(TextStyle.NARROW_STANDALONE, TextStyle.NARROW.asStandalone());
|
||||
assertEquals(TextStyle.FULL_STANDALONE.asStandalone(), TextStyle.FULL_STANDALONE);
|
||||
assertEquals(TextStyle.SHORT.asStandalone(), TextStyle.SHORT_STANDALONE);
|
||||
assertEquals(TextStyle.NARROW.asStandalone(), TextStyle.NARROW_STANDALONE);
|
||||
|
||||
assertTrue(TextStyle.FULL_STANDALONE.isStandalone());
|
||||
assertTrue(TextStyle.SHORT_STANDALONE.isStandalone());
|
||||
@ -97,7 +96,7 @@ public class TCKTextStyle {
|
||||
@Test
|
||||
public void test_valueOf() {
|
||||
for (TextStyle style : TextStyle.values()) {
|
||||
assertEquals(TextStyle.valueOf(style.name()), style);
|
||||
assertEquals(style, TextStyle.valueOf(style.name()));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2012, 2013, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2012, 2025, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
@ -59,30 +59,29 @@
|
||||
*/
|
||||
package tck.java.time.format;
|
||||
|
||||
import static org.testng.Assert.assertEquals;
|
||||
import static org.testng.Assert.assertNotNull;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
|
||||
import java.text.ParsePosition;
|
||||
import java.time.DateTimeException;
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.ZoneId;
|
||||
import java.time.ZoneOffset;
|
||||
import java.time.ZonedDateTime;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.time.format.DateTimeFormatterBuilder;
|
||||
import java.time.temporal.TemporalAccessor;
|
||||
import java.time.temporal.TemporalQueries;
|
||||
import java.util.Locale;
|
||||
import java.util.Objects;
|
||||
|
||||
import org.testng.annotations.BeforeMethod;
|
||||
import org.testng.annotations.DataProvider;
|
||||
import org.testng.annotations.Test;
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.TestInstance;
|
||||
import org.junit.jupiter.params.ParameterizedTest;
|
||||
import org.junit.jupiter.params.provider.MethodSource;
|
||||
|
||||
/**
|
||||
* Test DateTimeFormatterBuilder.appendZoneId().
|
||||
*/
|
||||
@Test
|
||||
@TestInstance(TestInstance.Lifecycle.PER_CLASS)
|
||||
public class TCKZoneIdPrinterParser {
|
||||
|
||||
private static final ZoneOffset OFFSET_UTC = ZoneOffset.UTC;
|
||||
@ -94,14 +93,13 @@ public class TCKZoneIdPrinterParser {
|
||||
private DateTimeFormatterBuilder builder;
|
||||
private ParsePosition pos;
|
||||
|
||||
@BeforeMethod
|
||||
@BeforeEach
|
||||
public void setUp() {
|
||||
builder = new DateTimeFormatterBuilder();
|
||||
pos = new ParsePosition(0);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
@DataProvider(name="print")
|
||||
Object[][] data_print() {
|
||||
return new Object[][] {
|
||||
{DT_2012_06_30_12_30_40, EUROPE_PARIS, "Europe/Paris"},
|
||||
@ -111,45 +109,46 @@ public class TCKZoneIdPrinterParser {
|
||||
};
|
||||
}
|
||||
|
||||
@Test(dataProvider="print")
|
||||
@ParameterizedTest
|
||||
@MethodSource("data_print")
|
||||
public void test_print(LocalDateTime ldt, ZoneId zone, String expected) {
|
||||
ZonedDateTime zdt = ldt.atZone(zone);
|
||||
builder.appendZoneId();
|
||||
String output = builder.toFormatter().format(zdt);
|
||||
assertEquals(output, expected);
|
||||
assertEquals(expected, output);
|
||||
}
|
||||
|
||||
@Test(dataProvider="print")
|
||||
@ParameterizedTest
|
||||
@MethodSource("data_print")
|
||||
public void test_print_pattern_VV(LocalDateTime ldt, ZoneId zone, String expected) {
|
||||
ZonedDateTime zdt = ldt.atZone(zone);
|
||||
builder.appendPattern("VV");
|
||||
String output = builder.toFormatter().format(zdt);
|
||||
assertEquals(output, expected);
|
||||
assertEquals(expected, output);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
@Test(expectedExceptions=IllegalArgumentException.class)
|
||||
@Test
|
||||
public void test_print_pattern_V1rejected() {
|
||||
builder.appendPattern("V");
|
||||
Assertions.assertThrows(IllegalArgumentException.class, () -> builder.appendPattern("V"));
|
||||
}
|
||||
|
||||
@Test(expectedExceptions=IllegalArgumentException.class)
|
||||
@Test
|
||||
public void test_print_pattern_V3rejected() {
|
||||
builder.appendPattern("VVV");
|
||||
Assertions.assertThrows(IllegalArgumentException.class, () -> builder.appendPattern("VVV"));
|
||||
}
|
||||
|
||||
@Test(expectedExceptions=IllegalArgumentException.class)
|
||||
@Test
|
||||
public void test_print_pattern_V4rejected() {
|
||||
builder.appendPattern("VVVV");
|
||||
Assertions.assertThrows(IllegalArgumentException.class, () -> builder.appendPattern("VVVV"));
|
||||
}
|
||||
|
||||
@Test(expectedExceptions=IllegalArgumentException.class)
|
||||
@Test
|
||||
public void test_print_pattern_V5rejected() {
|
||||
builder.appendPattern("VVVVV");
|
||||
Assertions.assertThrows(IllegalArgumentException.class, () -> builder.appendPattern("VVVVV"));
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
@DataProvider(name="parseSuccess")
|
||||
Object[][] data_parseSuccess() {
|
||||
return new Object[][] {
|
||||
{"Z", 1, -1, ZoneId.of("Z"), true},
|
||||
@ -208,7 +207,8 @@ public class TCKZoneIdPrinterParser {
|
||||
};
|
||||
}
|
||||
|
||||
@Test(dataProvider="parseSuccess")
|
||||
@ParameterizedTest
|
||||
@MethodSource("data_parseSuccess")
|
||||
public void test_ZoneId_parseSuccess_plain(
|
||||
String text, int expectedIndex, int expectedErrorIndex, ZoneId expected, boolean isZoneOffset)
|
||||
{
|
||||
@ -216,7 +216,8 @@ public class TCKZoneIdPrinterParser {
|
||||
test(text, expectedIndex, expectedErrorIndex, expected, isZoneOffset);
|
||||
}
|
||||
|
||||
@Test(dataProvider="parseSuccess")
|
||||
@ParameterizedTest
|
||||
@MethodSource("data_parseSuccess")
|
||||
public void test_ZoneId_parseSuccess_prefix(
|
||||
String text, int expectedIndex, int expectedErrorIndex, ZoneId expected, boolean isZoneOffset)
|
||||
{
|
||||
@ -228,7 +229,8 @@ public class TCKZoneIdPrinterParser {
|
||||
expected, isZoneOffset);
|
||||
}
|
||||
|
||||
@Test(dataProvider="parseSuccess")
|
||||
@ParameterizedTest
|
||||
@MethodSource("data_parseSuccess")
|
||||
public void test_ZoneId_parseSuccess_suffix(
|
||||
String text, int expectedIndex, int expectedErrorIndex, ZoneId expected, boolean isZoneOffset)
|
||||
{
|
||||
@ -236,7 +238,8 @@ public class TCKZoneIdPrinterParser {
|
||||
test(text + "XXX", expectedIndex, expectedErrorIndex, expected, isZoneOffset);
|
||||
}
|
||||
|
||||
@Test(dataProvider="parseSuccess")
|
||||
@ParameterizedTest
|
||||
@MethodSource("data_parseSuccess")
|
||||
public void test_ZoneId_parseSuccess_caseSensitive(
|
||||
String text, int expectedIndex, int expectedErrorIndex, ZoneId expected, boolean isZoneOffset)
|
||||
{
|
||||
@ -245,15 +248,16 @@ public class TCKZoneIdPrinterParser {
|
||||
if (text.matches("[^A-Z]*[A-Z].*")) { // if input has letters
|
||||
String lcText = text.toLowerCase(Locale.ENGLISH);
|
||||
TemporalAccessor parsed = builder.toFormatter().parseUnresolved(lcText, pos);
|
||||
assertEquals(pos.getErrorIndex() >= 0, true);
|
||||
assertEquals(pos.getIndex(), 0);
|
||||
assertEquals(parsed, null);
|
||||
assertEquals(true, pos.getErrorIndex() >= 0);
|
||||
assertEquals(0, pos.getIndex());
|
||||
assertEquals(null, parsed);
|
||||
} else {
|
||||
test(text.toLowerCase(Locale.ENGLISH), expectedIndex, expectedErrorIndex, expected, isZoneOffset);
|
||||
}
|
||||
}
|
||||
|
||||
@Test(dataProvider="parseSuccess")
|
||||
@ParameterizedTest
|
||||
@MethodSource("data_parseSuccess")
|
||||
public void test_ZoneId_parseSuccess_caseInsensitive(
|
||||
String text, int expectedIndex, int expectedErrorIndex, ZoneId expected, boolean isZoneOffset)
|
||||
{
|
||||
@ -261,7 +265,8 @@ public class TCKZoneIdPrinterParser {
|
||||
test(text.toLowerCase(Locale.ENGLISH), expectedIndex, expectedErrorIndex, expected, isZoneOffset);
|
||||
}
|
||||
|
||||
@Test(dataProvider="parseSuccess")
|
||||
@ParameterizedTest
|
||||
@MethodSource("data_parseSuccess")
|
||||
public void test_ZoneOrOffsetId_parseSuccess_plain(
|
||||
String text, int expectedIndex, int expectedErrorIndex, ZoneId expected, boolean isZoneOffset)
|
||||
{
|
||||
@ -269,7 +274,8 @@ public class TCKZoneIdPrinterParser {
|
||||
test(text, expectedIndex, expectedErrorIndex, expected, isZoneOffset);
|
||||
}
|
||||
|
||||
@Test(dataProvider="parseSuccess")
|
||||
@ParameterizedTest
|
||||
@MethodSource("data_parseSuccess")
|
||||
public void test_ZoneOrOffsetId_parseSuccess_prefix(
|
||||
String text, int expectedIndex, int expectedErrorIndex, ZoneId expected, boolean isZoneOffset)
|
||||
{
|
||||
@ -281,7 +287,8 @@ public class TCKZoneIdPrinterParser {
|
||||
expected, isZoneOffset);
|
||||
}
|
||||
|
||||
@Test(dataProvider="parseSuccess")
|
||||
@ParameterizedTest
|
||||
@MethodSource("data_parseSuccess")
|
||||
public void test_ZoneOrOffsetId_parseSuccess_suffix(
|
||||
String text, int expectedIndex, int expectedErrorIndex, ZoneId expected, boolean isZoneOffset)
|
||||
{
|
||||
@ -289,7 +296,8 @@ public class TCKZoneIdPrinterParser {
|
||||
test(text + "XXX", expectedIndex, expectedErrorIndex, expected, isZoneOffset);
|
||||
}
|
||||
|
||||
@Test(dataProvider="parseSuccess")
|
||||
@ParameterizedTest
|
||||
@MethodSource("data_parseSuccess")
|
||||
public void test_ZoneOrOffsetId_parseSuccess_caseSensitive(
|
||||
String text, int expectedIndex, int expectedErrorIndex, ZoneId expected, boolean isZoneOffset)
|
||||
{
|
||||
@ -297,15 +305,16 @@ public class TCKZoneIdPrinterParser {
|
||||
if (text.matches("[^A-Z]*[A-Z].*")) { // if input has letters
|
||||
String lcText = text.toLowerCase(Locale.ENGLISH);
|
||||
TemporalAccessor parsed = builder.toFormatter().parseUnresolved(lcText, pos);
|
||||
assertEquals(pos.getErrorIndex() >= 0, true);
|
||||
assertEquals(pos.getIndex(), 0);
|
||||
assertEquals(parsed, null);
|
||||
assertEquals(true, pos.getErrorIndex() >= 0);
|
||||
assertEquals(0, pos.getIndex());
|
||||
assertEquals(null, parsed);
|
||||
} else {
|
||||
test(text.toLowerCase(Locale.ENGLISH), expectedIndex, expectedErrorIndex, expected, isZoneOffset);
|
||||
}
|
||||
}
|
||||
|
||||
@Test(dataProvider="parseSuccess")
|
||||
@ParameterizedTest
|
||||
@MethodSource("data_parseSuccess")
|
||||
public void test_ZoneOrOffsetIdparseSuccess_caseInsensitive(
|
||||
String text, int expectedIndex, int expectedErrorIndex, ZoneId expected, boolean isZoneOffset)
|
||||
{
|
||||
@ -316,20 +325,17 @@ public class TCKZoneIdPrinterParser {
|
||||
private void test(String text, int expectedIndex, int expectedErrorIndex, ZoneId expected,
|
||||
boolean isZoneOffset) {
|
||||
TemporalAccessor parsed = builder.toFormatter().parseUnresolved(text, pos);
|
||||
assertEquals(pos.getErrorIndex(), expectedErrorIndex, "Incorrect error index parsing: " + text);
|
||||
assertEquals(pos.getIndex(), expectedIndex, "Incorrect index parsing: " + text);
|
||||
assertEquals(expectedErrorIndex, pos.getErrorIndex(), "Incorrect error index parsing: " + text);
|
||||
assertEquals(expectedIndex, pos.getIndex(), "Incorrect index parsing: " + text);
|
||||
if (expected != null) {
|
||||
assertEquals(parsed.query(TemporalQueries.zoneId()),
|
||||
expected,
|
||||
assertEquals(expected, parsed.query(TemporalQueries.zoneId()),
|
||||
"Incorrect zoneId parsing: " + text);
|
||||
assertEquals(parsed.query(TemporalQueries.offset()),
|
||||
isZoneOffset ? expected : null,
|
||||
assertEquals(isZoneOffset ? expected : null, parsed.query(TemporalQueries.offset()),
|
||||
"Incorrect offset parsing: " + text);
|
||||
assertEquals(parsed.query(TemporalQueries.zone()),
|
||||
expected,
|
||||
assertEquals(expected, parsed.query(TemporalQueries.zone()),
|
||||
"Incorrect zone parsing: " + text);
|
||||
} else {
|
||||
assertEquals(parsed, null);
|
||||
assertEquals(null, parsed);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2012, 2013, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2012, 2025, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
@ -69,14 +69,13 @@ import java.time.ZoneId;
|
||||
import java.time.ZoneOffset;
|
||||
import java.time.ZonedDateTime;
|
||||
|
||||
import org.testng.annotations.Test;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import tck.java.time.AbstractTCKTest;
|
||||
|
||||
/**
|
||||
* Test system and offset clocks serialization.
|
||||
*/
|
||||
@Test
|
||||
public class TCKClockSerialization extends AbstractTCKTest {
|
||||
|
||||
private static final ZoneId MOSCOW = ZoneId.of("Europe/Moscow");
|
||||
@ -87,6 +86,7 @@ public class TCKClockSerialization extends AbstractTCKTest {
|
||||
private static final Instant INSTANT = ZDT.toInstant();
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
@Test
|
||||
public void test_systemClockSerializable() throws IOException, ClassNotFoundException {
|
||||
assertSerializable(Clock.systemUTC());
|
||||
assertSerializable(Clock.systemDefaultZone());
|
||||
@ -94,11 +94,13 @@ public class TCKClockSerialization extends AbstractTCKTest {
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
@Test
|
||||
public void test_offsetClockSerializable() throws IOException, ClassNotFoundException {
|
||||
assertSerializable(Clock.offset(Clock.system(PARIS), AMOUNT));
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
@Test
|
||||
public void test_tickClockSerializable() throws IOException, ClassNotFoundException {
|
||||
assertSerializable(Clock.tickSeconds(PARIS));
|
||||
assertSerializable(Clock.tickMinutes(MOSCOW));
|
||||
@ -106,6 +108,7 @@ public class TCKClockSerialization extends AbstractTCKTest {
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
@Test
|
||||
public void test_fixedClockSerializable() throws IOException, ClassNotFoundException {
|
||||
assertSerializable(Clock.fixed(INSTANT, ZoneOffset.UTC));
|
||||
assertSerializable(Clock.fixed(INSTANT, PARIS));
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2012, 2013, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2012, 2025, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
@ -59,9 +59,8 @@
|
||||
*/
|
||||
package tck.java.time.serial;
|
||||
|
||||
import static org.testng.Assert.assertTrue;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
import org.testng.annotations.Test;
|
||||
import tck.java.time.AbstractTCKTest;
|
||||
|
||||
import java.io.ByteArrayOutputStream;
|
||||
@ -69,10 +68,11 @@ import java.io.DataOutputStream;
|
||||
import java.io.Serializable;
|
||||
import java.time.Duration;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
/**
|
||||
* Test Duration serialization.
|
||||
*/
|
||||
@Test
|
||||
public class TCKDurationSerialization extends AbstractTCKTest {
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2012, 2013, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2012, 2025, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
@ -59,18 +59,17 @@
|
||||
*/
|
||||
package tck.java.time.serial;
|
||||
|
||||
import org.testng.annotations.BeforeMethod;
|
||||
import org.testng.annotations.Test;
|
||||
import tck.java.time.AbstractTCKTest;
|
||||
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.DataOutputStream;
|
||||
import java.time.Instant;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
/**
|
||||
* Test Instant serialization.
|
||||
*/
|
||||
@Test
|
||||
public class TCKInstantSerialization extends AbstractTCKTest {
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2012, 2013, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2012, 2025, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
@ -59,23 +59,23 @@
|
||||
*/
|
||||
package tck.java.time.serial;
|
||||
|
||||
import org.testng.annotations.BeforeMethod;
|
||||
import org.testng.annotations.Test;
|
||||
import tck.java.time.AbstractTCKTest;
|
||||
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.DataOutputStream;
|
||||
import java.time.LocalDate;
|
||||
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
/**
|
||||
* Test LocalDate serialization.
|
||||
*/
|
||||
@Test
|
||||
public class TCKLocalDateSerialization extends AbstractTCKTest {
|
||||
|
||||
private LocalDate TEST_2007_07_15;
|
||||
|
||||
@BeforeMethod
|
||||
@BeforeEach
|
||||
public void setUp() {
|
||||
TEST_2007_07_15 = LocalDate.of(2007, 7, 15);
|
||||
}
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2012, 2013, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2012, 2025, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
@ -59,17 +59,17 @@
|
||||
*/
|
||||
package tck.java.time.serial;
|
||||
|
||||
import org.testng.annotations.Test;
|
||||
import tck.java.time.AbstractTCKTest;
|
||||
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.DataOutputStream;
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
/**
|
||||
* Test serialization of LocalDateTime.
|
||||
*/
|
||||
@Test
|
||||
public class TCKLocalDateTimeSerialization extends AbstractTCKTest {
|
||||
|
||||
private LocalDateTime TEST_2007_07_15_12_30_40_987654321 = LocalDateTime.of(2007, 7, 15, 12, 30, 40, 987654321);
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2012, 2013, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2012, 2025, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
@ -59,25 +59,25 @@
|
||||
*/
|
||||
package tck.java.time.serial;
|
||||
|
||||
import org.testng.annotations.BeforeMethod;
|
||||
import org.testng.annotations.Test;
|
||||
import tck.java.time.AbstractTCKTest;
|
||||
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.DataOutputStream;
|
||||
import java.time.LocalTime;
|
||||
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
/**
|
||||
* Test LocalTime serialization.
|
||||
*/
|
||||
@Test
|
||||
public class TCKLocalTimeSerialization extends AbstractTCKTest {
|
||||
|
||||
|
||||
private LocalTime TEST_12_30_40_987654321;
|
||||
|
||||
|
||||
@BeforeMethod
|
||||
@BeforeEach
|
||||
public void setUp() {
|
||||
TEST_12_30_40_987654321 = LocalTime.of(12, 30, 40, 987654321);
|
||||
}
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2012, 2013, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2012, 2025, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
@ -59,8 +59,6 @@
|
||||
*/
|
||||
package tck.java.time.serial;
|
||||
|
||||
import org.testng.annotations.BeforeMethod;
|
||||
import org.testng.annotations.Test;
|
||||
import tck.java.time.AbstractTCKTest;
|
||||
|
||||
import java.io.ByteArrayOutputStream;
|
||||
@ -68,15 +66,17 @@ import java.io.DataOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.time.MonthDay;
|
||||
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
/**
|
||||
* Test MonthDay serialization.
|
||||
*/
|
||||
@Test
|
||||
public class TCKMonthDaySerialization extends AbstractTCKTest {
|
||||
|
||||
private MonthDay TEST_07_15;
|
||||
|
||||
@BeforeMethod
|
||||
@BeforeEach
|
||||
public void setUp() {
|
||||
TEST_07_15 = MonthDay.of(7, 15);
|
||||
}
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2012, 2013, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2012, 2025, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
@ -66,20 +66,20 @@ import java.time.LocalDateTime;
|
||||
import java.time.OffsetDateTime;
|
||||
import java.time.ZoneOffset;
|
||||
|
||||
import org.testng.annotations.BeforeMethod;
|
||||
import org.testng.annotations.Test;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import tck.java.time.AbstractTCKTest;
|
||||
|
||||
/**
|
||||
* Test OffsetDateTime serialization.
|
||||
*/
|
||||
@Test
|
||||
public class TCKOffsetDateTimeSerialization extends AbstractTCKTest {
|
||||
|
||||
private static final ZoneOffset OFFSET_PONE = ZoneOffset.ofHours(1);
|
||||
private OffsetDateTime TEST_2008_6_30_11_30_59_000000500;
|
||||
|
||||
@BeforeMethod
|
||||
@BeforeEach
|
||||
public void setUp() {
|
||||
TEST_2008_6_30_11_30_59_000000500 = OffsetDateTime.of(2008, 6, 30, 11, 30, 59, 500, OFFSET_PONE);
|
||||
}
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2012, 2013, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2012, 2025, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
@ -59,8 +59,6 @@
|
||||
*/
|
||||
package tck.java.time.serial;
|
||||
|
||||
import org.testng.annotations.BeforeMethod;
|
||||
import org.testng.annotations.Test;
|
||||
import tck.java.time.AbstractTCKTest;
|
||||
|
||||
import java.io.ByteArrayOutputStream;
|
||||
@ -68,16 +66,18 @@ import java.io.DataOutputStream;
|
||||
import java.time.OffsetTime;
|
||||
import java.time.ZoneOffset;
|
||||
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
/**
|
||||
* Test OffsetTime serialization.
|
||||
*/
|
||||
@Test
|
||||
public class TCKOffsetTimeSerialization extends AbstractTCKTest {
|
||||
|
||||
private static final ZoneOffset OFFSET_PONE = ZoneOffset.ofHours(1);
|
||||
private OffsetTime TEST_11_30_59_500_PONE;
|
||||
|
||||
@BeforeMethod
|
||||
@BeforeEach
|
||||
public void setUp() {
|
||||
TEST_11_30_59_500_PONE = OffsetTime.of(11, 30, 59, 500, OFFSET_PONE);
|
||||
}
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2012, 2013, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2012, 2025, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
@ -59,15 +59,15 @@
|
||||
*/
|
||||
package tck.java.time.serial;
|
||||
|
||||
import org.testng.annotations.Test;
|
||||
import tck.java.time.AbstractTCKTest;
|
||||
|
||||
import java.time.Period;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
/**
|
||||
* Test serialization of Period.
|
||||
*/
|
||||
@Test
|
||||
public class TCKPeriodSerialization extends AbstractTCKTest {
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2012, 2013, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2012, 2025, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
@ -59,8 +59,6 @@
|
||||
*/
|
||||
package tck.java.time.serial;
|
||||
|
||||
import org.testng.annotations.BeforeMethod;
|
||||
import org.testng.annotations.Test;
|
||||
import tck.java.time.AbstractTCKTest;
|
||||
|
||||
import java.io.ByteArrayOutputStream;
|
||||
@ -68,15 +66,17 @@ import java.io.DataOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.time.YearMonth;
|
||||
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
/**
|
||||
* Test serialization of YearMonth.
|
||||
*/
|
||||
@Test
|
||||
public class TCKYearMonthSerialization extends AbstractTCKTest {
|
||||
|
||||
private YearMonth TEST_2008_06;
|
||||
|
||||
@BeforeMethod
|
||||
@BeforeEach
|
||||
public void setUp() {
|
||||
TEST_2008_06 = YearMonth.of(2008, 6);
|
||||
}
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2012, 2013, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2012, 2025, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
@ -59,17 +59,17 @@
|
||||
*/
|
||||
package tck.java.time.serial;
|
||||
|
||||
import org.testng.annotations.Test;
|
||||
import tck.java.time.AbstractTCKTest;
|
||||
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.DataOutputStream;
|
||||
import java.time.Year;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
/**
|
||||
* Test Year serialization.
|
||||
*/
|
||||
@Test
|
||||
public class TCKYearSerialization extends AbstractTCKTest {
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2012, 2017, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2012, 2025, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
@ -59,8 +59,6 @@
|
||||
*/
|
||||
package tck.java.time.serial;
|
||||
|
||||
import org.testng.annotations.DataProvider;
|
||||
import org.testng.annotations.Test;
|
||||
import tck.java.time.AbstractTCKTest;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
@ -72,13 +70,18 @@ import java.time.DateTimeException;
|
||||
import java.time.ZoneId;
|
||||
import java.time.zone.ZoneRulesException;
|
||||
|
||||
import static org.testng.Assert.assertEquals;
|
||||
import static org.testng.Assert.fail;
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.fail;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.TestInstance;
|
||||
import org.junit.jupiter.params.ParameterizedTest;
|
||||
import org.junit.jupiter.params.provider.MethodSource;
|
||||
|
||||
/**
|
||||
* Test serialization of ZoneId.
|
||||
*/
|
||||
@Test
|
||||
@TestInstance(TestInstance.Lifecycle.PER_CLASS)
|
||||
public class TCKZoneIdSerialization extends AbstractTCKTest {
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
@ -105,11 +108,11 @@ public class TCKZoneIdSerialization extends AbstractTCKTest {
|
||||
String id = "QWERTYUIOPASDFGHJKLZXCVBNM~/._+-";
|
||||
ZoneId deser = deserialize(id);
|
||||
// getId, equals, hashCode, toString and normalized are OK
|
||||
assertEquals(deser.getId(), id);
|
||||
assertEquals(deser.toString(), id);
|
||||
assertEquals(id, deser.getId());
|
||||
assertEquals(id, deser.toString());
|
||||
assertEquals(deser, deser);
|
||||
assertEquals(deser.hashCode(), deser.hashCode());
|
||||
assertEquals(deser.normalized(), deser);
|
||||
assertEquals(deser, deser.normalized());
|
||||
// getting the rules is not
|
||||
try {
|
||||
deser.getRules();
|
||||
@ -119,39 +122,45 @@ public class TCKZoneIdSerialization extends AbstractTCKTest {
|
||||
}
|
||||
}
|
||||
|
||||
@Test(expectedExceptions=DateTimeException.class)
|
||||
@Test
|
||||
public void test_deserialization_lenient_badCharacters() throws Exception {
|
||||
// an ID can be loaded without validation during deserialization
|
||||
// but there is a check to ensure the ID format is valid
|
||||
deserialize("|!?");
|
||||
Assertions.assertThrows(DateTimeException.class, () -> {
|
||||
// an ID can be loaded without validation during deserialization
|
||||
// but there is a check to ensure the ID format is valid
|
||||
deserialize("|!?");
|
||||
});
|
||||
}
|
||||
|
||||
@Test(dataProvider="offsetBasedValid")
|
||||
@ParameterizedTest
|
||||
@MethodSource("data_offsetBasedValid")
|
||||
public void test_deserialization_lenient_offsetNotAllowed_noPrefix(String input, String resolvedId) throws Exception {
|
||||
ZoneId deserialized = deserialize(input);
|
||||
assertEquals(deserialized, ZoneId.of(input));
|
||||
assertEquals(deserialized, ZoneId.of(resolvedId));
|
||||
assertEquals(ZoneId.of(input), deserialized);
|
||||
assertEquals(ZoneId.of(resolvedId), deserialized);
|
||||
}
|
||||
|
||||
@Test(dataProvider="offsetBasedValidPrefix")
|
||||
@ParameterizedTest
|
||||
@MethodSource("data_offsetBasedValidPrefix")
|
||||
public void test_deserialization_lenient_offsetNotAllowed_prefixUTC(String input, String resolvedId, String offsetId) throws Exception {
|
||||
ZoneId deserialized = deserialize("UTC" + input);
|
||||
assertEquals(deserialized, ZoneId.of("UTC" + input));
|
||||
assertEquals(deserialized, ZoneId.of("UTC" + resolvedId));
|
||||
assertEquals(ZoneId.of("UTC" + input), deserialized);
|
||||
assertEquals(ZoneId.of("UTC" + resolvedId), deserialized);
|
||||
}
|
||||
|
||||
@Test(dataProvider="offsetBasedValidPrefix")
|
||||
@ParameterizedTest
|
||||
@MethodSource("data_offsetBasedValidPrefix")
|
||||
public void test_deserialization_lenient_offsetNotAllowed_prefixGMT(String input, String resolvedId, String offsetId) throws Exception {
|
||||
ZoneId deserialized = deserialize("GMT" + input);
|
||||
assertEquals(deserialized, ZoneId.of("GMT" + input));
|
||||
assertEquals(deserialized, ZoneId.of("GMT" + resolvedId));
|
||||
assertEquals(ZoneId.of("GMT" + input), deserialized);
|
||||
assertEquals(ZoneId.of("GMT" + resolvedId), deserialized);
|
||||
}
|
||||
|
||||
@Test(dataProvider="offsetBasedValidPrefix")
|
||||
@ParameterizedTest
|
||||
@MethodSource("data_offsetBasedValidPrefix")
|
||||
public void test_deserialization_lenient_offsetNotAllowed_prefixUT(String input, String resolvedId, String offsetId) throws Exception {
|
||||
ZoneId deserialized = deserialize("UT" + input);
|
||||
assertEquals(deserialized, ZoneId.of("UT" + input));
|
||||
assertEquals(deserialized, ZoneId.of("UT" + resolvedId));
|
||||
assertEquals(ZoneId.of("UT" + input), deserialized);
|
||||
assertEquals(ZoneId.of("UT" + resolvedId), deserialized);
|
||||
}
|
||||
|
||||
private ZoneId deserialize(String id) throws Exception {
|
||||
@ -186,7 +195,6 @@ public class TCKZoneIdSerialization extends AbstractTCKTest {
|
||||
//-----------------------------------------------------------------------
|
||||
// regular factory and .normalized()
|
||||
//-----------------------------------------------------------------------
|
||||
@DataProvider(name="offsetBasedValid")
|
||||
Object[][] data_offsetBasedValid() {
|
||||
return new Object[][] {
|
||||
{"Z", "Z"},
|
||||
@ -223,7 +231,6 @@ public class TCKZoneIdSerialization extends AbstractTCKTest {
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
@DataProvider(name="offsetBasedValidPrefix")
|
||||
Object[][] data_offsetBasedValidPrefix() {
|
||||
return new Object[][] {
|
||||
{"", "", "Z"},
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2012, 2013, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2012, 2025, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
@ -59,17 +59,17 @@
|
||||
*/
|
||||
package tck.java.time.serial;
|
||||
|
||||
import org.testng.annotations.Test;
|
||||
import tck.java.time.AbstractTCKTest;
|
||||
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.DataOutputStream;
|
||||
import java.time.ZoneOffset;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
/**
|
||||
* Test serialization of ZoneOffset.
|
||||
*/
|
||||
@Test
|
||||
public class TCKZoneOffsetSerialization extends AbstractTCKTest {
|
||||
|
||||
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2012, 2013, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2012, 2025, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
@ -59,8 +59,6 @@
|
||||
*/
|
||||
package tck.java.time.serial;
|
||||
|
||||
import org.testng.annotations.BeforeMethod;
|
||||
import org.testng.annotations.Test;
|
||||
import tck.java.time.AbstractTCKTest;
|
||||
|
||||
import java.io.ByteArrayOutputStream;
|
||||
@ -71,10 +69,12 @@ import java.time.ZoneId;
|
||||
import java.time.ZoneOffset;
|
||||
import java.time.ZonedDateTime;
|
||||
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
/**
|
||||
* Test serialization of ZonedDateTime.
|
||||
*/
|
||||
@Test
|
||||
public class TCKZonedDateTimeSerialization extends AbstractTCKTest {
|
||||
|
||||
private static final ZoneOffset OFFSET_0100 = ZoneOffset.ofHours(1);
|
||||
@ -84,7 +84,7 @@ public class TCKZonedDateTimeSerialization extends AbstractTCKTest {
|
||||
private ZonedDateTime TEST_DATE_TIME;
|
||||
|
||||
|
||||
@BeforeMethod
|
||||
@BeforeEach
|
||||
public void setUp() {
|
||||
TEST_LOCAL_2008_06_30_11_30_59_500 = LocalDateTime.of(2008, 6, 30, 11, 30, 59, 500);
|
||||
TEST_DATE_TIME = ZonedDateTime.of(TEST_LOCAL_2008_06_30_11_30_59_500, ZONE_0100);
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2012, 2024, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2012, 2025, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
@ -93,9 +93,8 @@ import static java.time.temporal.ChronoUnit.NANOS;
|
||||
import static java.time.temporal.ChronoUnit.SECONDS;
|
||||
import static java.time.temporal.ChronoUnit.WEEKS;
|
||||
import static java.time.temporal.ChronoUnit.YEARS;
|
||||
import static org.testng.Assert.assertEquals;
|
||||
import static org.testng.Assert.assertTrue;
|
||||
import static org.testng.Assert.fail;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
|
||||
import java.time.Instant;
|
||||
import java.time.LocalDate;
|
||||
@ -106,19 +105,20 @@ import java.time.temporal.ChronoUnit;
|
||||
import java.time.temporal.TemporalAccessor;
|
||||
import java.time.temporal.ValueRange;
|
||||
|
||||
import org.testng.annotations.DataProvider;
|
||||
import org.testng.annotations.Test;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.TestInstance;
|
||||
import org.junit.jupiter.params.ParameterizedTest;
|
||||
import org.junit.jupiter.params.provider.MethodSource;
|
||||
|
||||
/**
|
||||
* Test.
|
||||
*/
|
||||
@Test
|
||||
@TestInstance(TestInstance.Lifecycle.PER_CLASS)
|
||||
public class TCKChronoField {
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
// getBaseUnit() and getRangeUnit()
|
||||
//-----------------------------------------------------------------------
|
||||
@DataProvider(name="fieldUnit")
|
||||
Object[][] data_fieldUnit() {
|
||||
return new Object[][] {
|
||||
{YEAR, YEARS, FOREVER},
|
||||
@ -141,16 +141,16 @@ public class TCKChronoField {
|
||||
};
|
||||
}
|
||||
|
||||
@Test(dataProvider = "fieldUnit")
|
||||
@ParameterizedTest
|
||||
@MethodSource("data_fieldUnit")
|
||||
public void test_getBaseUnit(ChronoField field, ChronoUnit baseUnit, ChronoUnit rangeUnit) {
|
||||
assertEquals(field.getBaseUnit(), baseUnit);
|
||||
assertEquals(field.getRangeUnit(), rangeUnit);
|
||||
assertEquals(baseUnit, field.getBaseUnit());
|
||||
assertEquals(rangeUnit, field.getRangeUnit());
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
// isDateBased() and isTimeBased()
|
||||
//-----------------------------------------------------------------------
|
||||
@DataProvider(name="fieldBased")
|
||||
Object[][] data_fieldBased() {
|
||||
return new Object[][] {
|
||||
{DAY_OF_WEEK, true, false},
|
||||
@ -185,16 +185,16 @@ public class TCKChronoField {
|
||||
};
|
||||
}
|
||||
|
||||
@Test(dataProvider = "fieldBased")
|
||||
@ParameterizedTest
|
||||
@MethodSource("data_fieldBased")
|
||||
public void test_isDateBased(ChronoField field, boolean isDateBased, boolean isTimeBased) {
|
||||
assertEquals(field.isDateBased(), isDateBased);
|
||||
assertEquals(field.isTimeBased(), isTimeBased);
|
||||
assertEquals(isDateBased, field.isDateBased());
|
||||
assertEquals(isTimeBased, field.isTimeBased());
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
// isSupportedBy(TemporalAccessor temporal) and getFrom(TemporalAccessor temporal)
|
||||
//-----------------------------------------------------------------------
|
||||
@DataProvider(name="fieldAndAccessor")
|
||||
Object[][] data_fieldAndAccessor() {
|
||||
return new Object[][] {
|
||||
{YEAR, LocalDate.of(2000, 2, 29), true, 2000},
|
||||
@ -235,11 +235,12 @@ public class TCKChronoField {
|
||||
};
|
||||
}
|
||||
|
||||
@Test(dataProvider = "fieldAndAccessor")
|
||||
@ParameterizedTest
|
||||
@MethodSource("data_fieldAndAccessor")
|
||||
public void test_supportedAccessor(ChronoField field, TemporalAccessor accessor, boolean isSupported, long value) {
|
||||
assertEquals(field.isSupportedBy(accessor), isSupported);
|
||||
assertEquals(isSupported, field.isSupportedBy(accessor));
|
||||
if (isSupported) {
|
||||
assertEquals(field.getFrom(accessor), value);
|
||||
assertEquals(value, field.getFrom(accessor));
|
||||
}
|
||||
}
|
||||
|
||||
@ -248,11 +249,11 @@ public class TCKChronoField {
|
||||
//-----------------------------------------------------------------------
|
||||
@Test
|
||||
public void test_range() {
|
||||
assertEquals(MONTH_OF_YEAR.range(), ValueRange.of(1, 12));
|
||||
assertEquals(MONTH_OF_YEAR.rangeRefinedBy(LocalDate.of(2000, 2, 29)), ValueRange.of(1, 12));
|
||||
assertEquals(ValueRange.of(1, 12), MONTH_OF_YEAR.range());
|
||||
assertEquals(ValueRange.of(1, 12), MONTH_OF_YEAR.rangeRefinedBy(LocalDate.of(2000, 2, 29)));
|
||||
|
||||
assertEquals(DAY_OF_MONTH.range(), ValueRange.of(1, 28, 31));
|
||||
assertEquals(DAY_OF_MONTH.rangeRefinedBy(LocalDate.of(2000, 2, 29)), ValueRange.of(1, 29));
|
||||
assertEquals(ValueRange.of(1, 28, 31), DAY_OF_MONTH.range());
|
||||
assertEquals(ValueRange.of(1, 29), DAY_OF_MONTH.rangeRefinedBy(LocalDate.of(2000, 2, 29)));
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
@ -261,7 +262,7 @@ public class TCKChronoField {
|
||||
@Test
|
||||
public void test_valueOf() {
|
||||
for (ChronoField field : ChronoField.values()) {
|
||||
assertEquals(ChronoField.valueOf(field.name()), field);
|
||||
assertEquals(field, ChronoField.valueOf(field.name()));
|
||||
}
|
||||
}
|
||||
|
||||
@ -269,9 +270,7 @@ public class TCKChronoField {
|
||||
// matches the minimum and maximum supported epoch second by Instant.
|
||||
@Test
|
||||
public void testMinMaxInstantSeconds() {
|
||||
assertEquals(ChronoField.INSTANT_SECONDS.range().getMinimum(),
|
||||
Instant.MIN.getLong(ChronoField.INSTANT_SECONDS));
|
||||
assertEquals(ChronoField.INSTANT_SECONDS.range().getMaximum(),
|
||||
Instant.MAX.getLong(ChronoField.INSTANT_SECONDS));
|
||||
assertEquals(Instant.MIN.getLong(ChronoField.INSTANT_SECONDS), ChronoField.INSTANT_SECONDS.range().getMinimum());
|
||||
assertEquals(Instant.MAX.getLong(ChronoField.INSTANT_SECONDS), ChronoField.INSTANT_SECONDS.range().getMaximum());
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2012, 2013, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2012, 2025, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
@ -70,30 +70,28 @@ import static java.time.temporal.ChronoUnit.NANOS;
|
||||
import static java.time.temporal.ChronoUnit.SECONDS;
|
||||
import static java.time.temporal.ChronoUnit.WEEKS;
|
||||
import static java.time.temporal.ChronoUnit.YEARS;
|
||||
import static org.testng.Assert.assertEquals;
|
||||
import static org.testng.Assert.assertTrue;
|
||||
import static org.testng.Assert.fail;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
|
||||
import java.time.LocalDate;
|
||||
import java.time.LocalTime;
|
||||
import java.time.temporal.ChronoField;
|
||||
import java.time.temporal.ChronoUnit;
|
||||
import java.time.temporal.Temporal;
|
||||
import java.time.temporal.TemporalAccessor;
|
||||
|
||||
import org.testng.annotations.DataProvider;
|
||||
import org.testng.annotations.Test;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.TestInstance;
|
||||
import org.junit.jupiter.params.ParameterizedTest;
|
||||
import org.junit.jupiter.params.provider.MethodSource;
|
||||
|
||||
/**
|
||||
* Test.
|
||||
*/
|
||||
@Test
|
||||
@TestInstance(TestInstance.Lifecycle.PER_CLASS)
|
||||
public class TCKChronoUnit {
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
// isDateBased(), isTimeBased() and isDurationEstimated()
|
||||
//-----------------------------------------------------------------------
|
||||
@DataProvider(name="chronoUnit")
|
||||
Object[][] data_chronoUnit() {
|
||||
return new Object[][] {
|
||||
{FOREVER, false, false, true},
|
||||
@ -117,17 +115,17 @@ public class TCKChronoUnit {
|
||||
};
|
||||
}
|
||||
|
||||
@Test(dataProvider = "chronoUnit")
|
||||
@ParameterizedTest
|
||||
@MethodSource("data_chronoUnit")
|
||||
public void test_unitType(ChronoUnit unit, boolean isDateBased, boolean isTimeBased, boolean isDurationEstimated) {
|
||||
assertEquals(unit.isDateBased(), isDateBased);
|
||||
assertEquals(unit.isTimeBased(), isTimeBased);
|
||||
assertEquals(unit.isDurationEstimated(), isDurationEstimated);
|
||||
assertEquals(isDateBased, unit.isDateBased());
|
||||
assertEquals(isTimeBased, unit.isTimeBased());
|
||||
assertEquals(isDurationEstimated, unit.isDurationEstimated());
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
// isSupportedBy(), addTo() and between()
|
||||
//-----------------------------------------------------------------------
|
||||
@DataProvider(name="unitAndTemporal")
|
||||
Object[][] data_unitAndTemporal() {
|
||||
return new Object[][] {
|
||||
{CENTURIES, LocalDate.of(2000, 1, 10), true, 1, LocalDate.of(2100, 1, 10)},
|
||||
@ -163,13 +161,14 @@ public class TCKChronoUnit {
|
||||
};
|
||||
}
|
||||
|
||||
@Test(dataProvider = "unitAndTemporal")
|
||||
@ParameterizedTest
|
||||
@MethodSource("data_unitAndTemporal")
|
||||
public void test_unitAndTemporal(ChronoUnit unit, Temporal base, boolean isSupportedBy, long amount, Temporal target) {
|
||||
assertEquals(unit.isSupportedBy(base), isSupportedBy);
|
||||
assertEquals(isSupportedBy, unit.isSupportedBy(base));
|
||||
if (isSupportedBy) {
|
||||
Temporal result = unit.addTo(base, amount);
|
||||
assertEquals(result, target);
|
||||
assertEquals(unit.between(base, result), amount);
|
||||
assertEquals(target, result);
|
||||
assertEquals(amount, unit.between(base, result));
|
||||
}
|
||||
}
|
||||
|
||||
@ -179,7 +178,7 @@ public class TCKChronoUnit {
|
||||
@Test
|
||||
public void test_valueOf() {
|
||||
for (ChronoUnit unit : ChronoUnit.values()) {
|
||||
assertEquals(ChronoUnit.valueOf(unit.name()), unit);
|
||||
assertEquals(unit, ChronoUnit.valueOf(unit.name()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2012, 2022, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2012, 2025, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
@ -63,8 +63,9 @@ import static java.time.DayOfWeek.TUESDAY;
|
||||
import static java.time.DayOfWeek.WEDNESDAY;
|
||||
import static java.time.temporal.ChronoField.DAY_OF_WEEK;
|
||||
import static java.time.temporal.ChronoField.YEAR;
|
||||
import static org.testng.Assert.assertEquals;
|
||||
import static org.testng.Assert.fail;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.fail;
|
||||
|
||||
import java.time.DayOfWeek;
|
||||
import java.time.LocalDate;
|
||||
@ -80,16 +81,18 @@ import java.time.temporal.TemporalField;
|
||||
import java.time.temporal.UnsupportedTemporalTypeException;
|
||||
import java.time.temporal.ValueRange;
|
||||
|
||||
import org.testng.annotations.DataProvider;
|
||||
import org.testng.annotations.Test;
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.TestInstance;
|
||||
import org.junit.jupiter.params.ParameterizedTest;
|
||||
import org.junit.jupiter.params.provider.MethodSource;
|
||||
|
||||
/**
|
||||
* Test.
|
||||
*/
|
||||
@Test
|
||||
@TestInstance(TestInstance.Lifecycle.PER_CLASS)
|
||||
public class TCKIsoFields {
|
||||
|
||||
@DataProvider(name="quarter")
|
||||
Object[][] data_quarter() {
|
||||
return new Object[][] {
|
||||
{LocalDate.of(1969, 12, 29), 90, 4},
|
||||
@ -121,35 +124,40 @@ public class TCKIsoFields {
|
||||
//-----------------------------------------------------------------------
|
||||
// DAY_OF_QUARTER
|
||||
//-----------------------------------------------------------------------
|
||||
@Test(dataProvider = "quarter")
|
||||
@ParameterizedTest
|
||||
@MethodSource("data_quarter")
|
||||
public void test_DOQ(LocalDate date, int doq, int qoy) {
|
||||
assertEquals(IsoFields.DAY_OF_QUARTER.getFrom(date), doq);
|
||||
assertEquals(date.get(IsoFields.DAY_OF_QUARTER), doq);
|
||||
assertEquals(doq, IsoFields.DAY_OF_QUARTER.getFrom(date));
|
||||
assertEquals(doq, date.get(IsoFields.DAY_OF_QUARTER));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test_DOQ_basics() {
|
||||
assertEquals(IsoFields.DAY_OF_QUARTER.isDateBased(), true);
|
||||
assertEquals(IsoFields.DAY_OF_QUARTER.isTimeBased(), false);
|
||||
assertEquals(true, IsoFields.DAY_OF_QUARTER.isDateBased());
|
||||
assertEquals(false, IsoFields.DAY_OF_QUARTER.isTimeBased());
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
// QUARTER_OF_YEAR
|
||||
//-----------------------------------------------------------------------
|
||||
@Test(dataProvider = "quarter")
|
||||
@ParameterizedTest
|
||||
@MethodSource("data_quarter")
|
||||
public void test_QOY(LocalDate date, int doq, int qoy) {
|
||||
assertEquals(IsoFields.QUARTER_OF_YEAR.getFrom(date), qoy);
|
||||
assertEquals(date.get(IsoFields.QUARTER_OF_YEAR), qoy);
|
||||
assertEquals(qoy, IsoFields.QUARTER_OF_YEAR.getFrom(date));
|
||||
assertEquals(qoy, date.get(IsoFields.QUARTER_OF_YEAR));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test_QOY_basics() {
|
||||
assertEquals(IsoFields.QUARTER_OF_YEAR.isDateBased(), true);
|
||||
assertEquals(IsoFields.QUARTER_OF_YEAR.isTimeBased(), false);
|
||||
assertEquals(true, IsoFields.QUARTER_OF_YEAR.isDateBased());
|
||||
assertEquals(false, IsoFields.QUARTER_OF_YEAR.isTimeBased());
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
// parse quarters
|
||||
//-----------------------------------------------------------------------
|
||||
@Test(dataProvider = "quarter")
|
||||
@ParameterizedTest
|
||||
@MethodSource("data_quarter")
|
||||
public void test_parse_quarters(LocalDate date, int doq, int qoy) {
|
||||
DateTimeFormatter f = new DateTimeFormatterBuilder()
|
||||
.appendValue(YEAR).appendLiteral('-')
|
||||
@ -157,10 +165,11 @@ public class TCKIsoFields {
|
||||
.appendValue(IsoFields.DAY_OF_QUARTER)
|
||||
.toFormatter().withResolverStyle(ResolverStyle.STRICT);
|
||||
LocalDate parsed = LocalDate.parse(date.getYear() + "-" + qoy + "-" + doq, f);
|
||||
assertEquals(parsed, date);
|
||||
assertEquals(date, parsed);
|
||||
}
|
||||
|
||||
@Test(dataProvider = "quarter")
|
||||
@ParameterizedTest
|
||||
@MethodSource("data_quarter")
|
||||
public void test_parse_quarters_SMART(LocalDate date, int doq, int qoy) {
|
||||
DateTimeFormatter f = new DateTimeFormatterBuilder()
|
||||
.appendValue(YEAR).appendLiteral('-')
|
||||
@ -168,10 +177,11 @@ public class TCKIsoFields {
|
||||
.appendValue(IsoFields.DAY_OF_QUARTER)
|
||||
.toFormatter().withResolverStyle(ResolverStyle.SMART);
|
||||
LocalDate parsed = LocalDate.parse(date.getYear() + "-" + qoy + "-" + doq, f);
|
||||
assertEquals(parsed, date);
|
||||
assertEquals(date, parsed);
|
||||
}
|
||||
|
||||
@Test(dataProvider = "quarter")
|
||||
@ParameterizedTest
|
||||
@MethodSource("data_quarter")
|
||||
public void test_parse_quarters_LENIENT(LocalDate date, int doq, int qoy) {
|
||||
DateTimeFormatter f = new DateTimeFormatterBuilder()
|
||||
.appendValue(YEAR).appendLiteral('-')
|
||||
@ -179,11 +189,10 @@ public class TCKIsoFields {
|
||||
.appendValue(IsoFields.DAY_OF_QUARTER)
|
||||
.toFormatter().withResolverStyle(ResolverStyle.LENIENT);
|
||||
LocalDate parsed = LocalDate.parse(date.getYear() + "-" + qoy + "-" + doq, f);
|
||||
assertEquals(parsed, date);
|
||||
assertEquals(date, parsed);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
@DataProvider(name="parseLenientQuarter")
|
||||
Object[][] data_parseLenientQuarter() {
|
||||
return new Object[][] {
|
||||
{"2012:0:1", LocalDate.of(2011, 10, 1), false},
|
||||
@ -206,17 +215,21 @@ public class TCKIsoFields {
|
||||
};
|
||||
}
|
||||
|
||||
@Test(dataProvider = "parseLenientQuarter", expectedExceptions = DateTimeParseException.class)
|
||||
@ParameterizedTest
|
||||
@MethodSource("data_parseLenientQuarter")
|
||||
public void test_parse_parseLenientQuarter_STRICT(String str, LocalDate expected, boolean smart) {
|
||||
DateTimeFormatter f = new DateTimeFormatterBuilder()
|
||||
.appendValue(YEAR).appendLiteral(':')
|
||||
.appendValue(IsoFields.QUARTER_OF_YEAR).appendLiteral(':')
|
||||
.appendValue(IsoFields.DAY_OF_QUARTER)
|
||||
.toFormatter().withResolverStyle(ResolverStyle.STRICT);
|
||||
LocalDate.parse(str, f);
|
||||
Assertions.assertThrows(DateTimeParseException.class, () -> {
|
||||
DateTimeFormatter f = new DateTimeFormatterBuilder()
|
||||
.appendValue(YEAR).appendLiteral(':')
|
||||
.appendValue(IsoFields.QUARTER_OF_YEAR).appendLiteral(':')
|
||||
.appendValue(IsoFields.DAY_OF_QUARTER)
|
||||
.toFormatter().withResolverStyle(ResolverStyle.STRICT);
|
||||
LocalDate.parse(str, f);
|
||||
});
|
||||
}
|
||||
|
||||
@Test(dataProvider = "parseLenientQuarter")
|
||||
@ParameterizedTest
|
||||
@MethodSource("data_parseLenientQuarter")
|
||||
public void test_parse_parseLenientQuarter_SMART(String str, LocalDate expected, boolean smart) {
|
||||
DateTimeFormatter f = new DateTimeFormatterBuilder()
|
||||
.appendValue(YEAR).appendLiteral(':')
|
||||
@ -225,7 +238,7 @@ public class TCKIsoFields {
|
||||
.toFormatter().withResolverStyle(ResolverStyle.SMART);
|
||||
if (smart) {
|
||||
LocalDate parsed = LocalDate.parse(str, f);
|
||||
assertEquals(parsed, expected);
|
||||
assertEquals(expected, parsed);
|
||||
} else {
|
||||
try {
|
||||
LocalDate.parse(str, f);
|
||||
@ -236,7 +249,8 @@ public class TCKIsoFields {
|
||||
}
|
||||
}
|
||||
|
||||
@Test(dataProvider = "parseLenientQuarter")
|
||||
@ParameterizedTest
|
||||
@MethodSource("data_parseLenientQuarter")
|
||||
public void test_parse_parseLenientQuarter_LENIENT(String str, LocalDate expected, boolean smart) {
|
||||
DateTimeFormatter f = new DateTimeFormatterBuilder()
|
||||
.appendValue(YEAR).appendLiteral(':')
|
||||
@ -244,13 +258,12 @@ public class TCKIsoFields {
|
||||
.appendValue(IsoFields.DAY_OF_QUARTER)
|
||||
.toFormatter().withResolverStyle(ResolverStyle.LENIENT);
|
||||
LocalDate parsed = LocalDate.parse(str, f);
|
||||
assertEquals(parsed, expected);
|
||||
assertEquals(expected, parsed);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
// quarters between
|
||||
//-----------------------------------------------------------------------
|
||||
@DataProvider(name="quartersBetween")
|
||||
Object[][] data_quartersBetween() {
|
||||
return new Object[][] {
|
||||
{LocalDate.of(2000, 1, 1), LocalDate.of(2000, 1, 1), 0},
|
||||
@ -284,20 +297,21 @@ public class TCKIsoFields {
|
||||
};
|
||||
}
|
||||
|
||||
@Test(dataProvider="quartersBetween")
|
||||
@ParameterizedTest
|
||||
@MethodSource("data_quartersBetween")
|
||||
public void test_quarters_between(LocalDate start, Temporal end, long expected) {
|
||||
assertEquals(IsoFields.QUARTER_YEARS.between(start, end), expected);
|
||||
assertEquals(expected, IsoFields.QUARTER_YEARS.between(start, end));
|
||||
}
|
||||
|
||||
@Test(dataProvider="quartersBetween")
|
||||
@ParameterizedTest
|
||||
@MethodSource("data_quartersBetween")
|
||||
public void test_quarters_between_until(LocalDate start, Temporal end, long expected) {
|
||||
assertEquals(start.until(end, IsoFields.QUARTER_YEARS), expected);
|
||||
assertEquals(expected, start.until(end, IsoFields.QUARTER_YEARS));
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------
|
||||
@DataProvider(name="week")
|
||||
Object[][] data_week() {
|
||||
return new Object[][] {
|
||||
{LocalDate.of(1969, 12, 29), MONDAY, 1, 1970},
|
||||
@ -318,37 +332,42 @@ public class TCKIsoFields {
|
||||
//-----------------------------------------------------------------------
|
||||
// WEEK_OF_WEEK_BASED_YEAR
|
||||
//-----------------------------------------------------------------------
|
||||
@Test(dataProvider="week")
|
||||
@ParameterizedTest
|
||||
@MethodSource("data_week")
|
||||
public void test_WOWBY(LocalDate date, DayOfWeek dow, int week, int wby) {
|
||||
assertEquals(date.getDayOfWeek(), dow);
|
||||
assertEquals(IsoFields.WEEK_OF_WEEK_BASED_YEAR.getFrom(date), week);
|
||||
assertEquals(date.get(IsoFields.WEEK_OF_WEEK_BASED_YEAR), week);
|
||||
assertEquals(dow, date.getDayOfWeek());
|
||||
assertEquals(week, IsoFields.WEEK_OF_WEEK_BASED_YEAR.getFrom(date));
|
||||
assertEquals(week, date.get(IsoFields.WEEK_OF_WEEK_BASED_YEAR));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test_WOWBY_basics() {
|
||||
assertEquals(IsoFields.WEEK_OF_WEEK_BASED_YEAR.isDateBased(), true);
|
||||
assertEquals(IsoFields.WEEK_OF_WEEK_BASED_YEAR.isTimeBased(), false);
|
||||
assertEquals(true, IsoFields.WEEK_OF_WEEK_BASED_YEAR.isDateBased());
|
||||
assertEquals(false, IsoFields.WEEK_OF_WEEK_BASED_YEAR.isTimeBased());
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
// WEEK_BASED_YEAR
|
||||
//-----------------------------------------------------------------------
|
||||
@Test(dataProvider="week")
|
||||
@ParameterizedTest
|
||||
@MethodSource("data_week")
|
||||
public void test_WBY(LocalDate date, DayOfWeek dow, int week, int wby) {
|
||||
assertEquals(date.getDayOfWeek(), dow);
|
||||
assertEquals(IsoFields.WEEK_BASED_YEAR.getFrom(date), wby);
|
||||
assertEquals(date.get(IsoFields.WEEK_BASED_YEAR), wby);
|
||||
assertEquals(dow, date.getDayOfWeek());
|
||||
assertEquals(wby, IsoFields.WEEK_BASED_YEAR.getFrom(date));
|
||||
assertEquals(wby, date.get(IsoFields.WEEK_BASED_YEAR));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test_WBY_basics() {
|
||||
assertEquals(IsoFields.WEEK_BASED_YEAR.isDateBased(), true);
|
||||
assertEquals(IsoFields.WEEK_BASED_YEAR.isTimeBased(), false);
|
||||
assertEquals(true, IsoFields.WEEK_BASED_YEAR.isDateBased());
|
||||
assertEquals(false, IsoFields.WEEK_BASED_YEAR.isTimeBased());
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
// parse weeks
|
||||
//-----------------------------------------------------------------------
|
||||
@Test(dataProvider="week")
|
||||
@ParameterizedTest
|
||||
@MethodSource("data_week")
|
||||
public void test_parse_weeks_STRICT(LocalDate date, DayOfWeek dow, int week, int wby) {
|
||||
DateTimeFormatter f = new DateTimeFormatterBuilder()
|
||||
.appendValue(IsoFields.WEEK_BASED_YEAR).appendLiteral('-')
|
||||
@ -356,10 +375,11 @@ public class TCKIsoFields {
|
||||
.appendValue(DAY_OF_WEEK)
|
||||
.toFormatter().withResolverStyle(ResolverStyle.STRICT);
|
||||
LocalDate parsed = LocalDate.parse(wby + "-" + week + "-" + dow.getValue(), f);
|
||||
assertEquals(parsed, date);
|
||||
assertEquals(date, parsed);
|
||||
}
|
||||
|
||||
@Test(dataProvider="week")
|
||||
@ParameterizedTest
|
||||
@MethodSource("data_week")
|
||||
public void test_parse_weeks_SMART(LocalDate date, DayOfWeek dow, int week, int wby) {
|
||||
DateTimeFormatter f = new DateTimeFormatterBuilder()
|
||||
.appendValue(IsoFields.WEEK_BASED_YEAR).appendLiteral('-')
|
||||
@ -367,10 +387,11 @@ public class TCKIsoFields {
|
||||
.appendValue(DAY_OF_WEEK)
|
||||
.toFormatter().withResolverStyle(ResolverStyle.SMART);
|
||||
LocalDate parsed = LocalDate.parse(wby + "-" + week + "-" + dow.getValue(), f);
|
||||
assertEquals(parsed, date);
|
||||
assertEquals(date, parsed);
|
||||
}
|
||||
|
||||
@Test(dataProvider="week")
|
||||
@ParameterizedTest
|
||||
@MethodSource("data_week")
|
||||
public void test_parse_weeks_LENIENT(LocalDate date, DayOfWeek dow, int week, int wby) {
|
||||
DateTimeFormatter f = new DateTimeFormatterBuilder()
|
||||
.appendValue(IsoFields.WEEK_BASED_YEAR).appendLiteral('-')
|
||||
@ -378,11 +399,10 @@ public class TCKIsoFields {
|
||||
.appendValue(DAY_OF_WEEK)
|
||||
.toFormatter().withResolverStyle(ResolverStyle.LENIENT);
|
||||
LocalDate parsed = LocalDate.parse(wby + "-" + week + "-" + dow.getValue(), f);
|
||||
assertEquals(parsed, date);
|
||||
assertEquals(date, parsed);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
@DataProvider(name="parseLenientWeek")
|
||||
Object[][] data_parseLenientWeek() {
|
||||
return new Object[][] {
|
||||
{"2012:52:-1", LocalDate.of(2012, 12, 22), false},
|
||||
@ -398,17 +418,21 @@ public class TCKIsoFields {
|
||||
};
|
||||
}
|
||||
|
||||
@Test(dataProvider = "parseLenientWeek", expectedExceptions = DateTimeParseException.class)
|
||||
@ParameterizedTest
|
||||
@MethodSource("data_parseLenientWeek")
|
||||
public void test_parse_parseLenientWeek_STRICT(String str, LocalDate expected, boolean smart) {
|
||||
DateTimeFormatter f = new DateTimeFormatterBuilder()
|
||||
.appendValue(IsoFields.WEEK_BASED_YEAR).appendLiteral(':')
|
||||
.appendValue(IsoFields.WEEK_OF_WEEK_BASED_YEAR).appendLiteral(':')
|
||||
.appendValue(DAY_OF_WEEK)
|
||||
.toFormatter().withResolverStyle(ResolverStyle.STRICT);
|
||||
LocalDate.parse(str, f);
|
||||
Assertions.assertThrows(DateTimeParseException.class, () -> {
|
||||
DateTimeFormatter f = new DateTimeFormatterBuilder()
|
||||
.appendValue(IsoFields.WEEK_BASED_YEAR).appendLiteral(':')
|
||||
.appendValue(IsoFields.WEEK_OF_WEEK_BASED_YEAR).appendLiteral(':')
|
||||
.appendValue(DAY_OF_WEEK)
|
||||
.toFormatter().withResolverStyle(ResolverStyle.STRICT);
|
||||
LocalDate.parse(str, f);
|
||||
});
|
||||
}
|
||||
|
||||
@Test(dataProvider = "parseLenientWeek")
|
||||
@ParameterizedTest
|
||||
@MethodSource("data_parseLenientWeek")
|
||||
public void test_parse_parseLenientWeek_SMART(String str, LocalDate expected, boolean smart) {
|
||||
DateTimeFormatter f = new DateTimeFormatterBuilder()
|
||||
.appendValue(IsoFields.WEEK_BASED_YEAR).appendLiteral(':')
|
||||
@ -417,7 +441,7 @@ public class TCKIsoFields {
|
||||
.toFormatter().withResolverStyle(ResolverStyle.SMART);
|
||||
if (smart) {
|
||||
LocalDate parsed = LocalDate.parse(str, f);
|
||||
assertEquals(parsed, expected);
|
||||
assertEquals(expected, parsed);
|
||||
} else {
|
||||
try {
|
||||
LocalDate.parse(str, f);
|
||||
@ -428,7 +452,8 @@ public class TCKIsoFields {
|
||||
}
|
||||
}
|
||||
|
||||
@Test(dataProvider = "parseLenientWeek")
|
||||
@ParameterizedTest
|
||||
@MethodSource("data_parseLenientWeek")
|
||||
public void test_parse_parseLenientWeek_LENIENT(String str, LocalDate expected, boolean smart) {
|
||||
DateTimeFormatter f = new DateTimeFormatterBuilder()
|
||||
.appendValue(IsoFields.WEEK_BASED_YEAR).appendLiteral(':')
|
||||
@ -436,13 +461,12 @@ public class TCKIsoFields {
|
||||
.appendValue(DAY_OF_WEEK)
|
||||
.toFormatter().withResolverStyle(ResolverStyle.LENIENT);
|
||||
LocalDate parsed = LocalDate.parse(str, f);
|
||||
assertEquals(parsed, expected);
|
||||
assertEquals(expected, parsed);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
// rangeRefinedBy
|
||||
//-----------------------------------------------------------------------
|
||||
@DataProvider(name="isofields")
|
||||
Object[][] data_isofields() {
|
||||
return new Object[][] {
|
||||
{IsoFields.DAY_OF_QUARTER, 49, ValueRange.of(1, 91)},
|
||||
@ -453,32 +477,37 @@ public class TCKIsoFields {
|
||||
};
|
||||
}
|
||||
|
||||
@Test(dataProvider = "isofields")
|
||||
@ParameterizedTest
|
||||
@MethodSource("data_isofields")
|
||||
public void test_isofields_rangerefinedby(TemporalField field, int value, ValueRange valueRange) {
|
||||
LocalDate date = LocalDate.of(2016, 5, 19);
|
||||
assertEquals(field.rangeRefinedBy(date), valueRange);
|
||||
assertEquals(valueRange, field.rangeRefinedBy(date));
|
||||
}
|
||||
|
||||
@Test(dataProvider = "isofields", expectedExceptions = UnsupportedTemporalTypeException.class)
|
||||
@ParameterizedTest
|
||||
@MethodSource("data_isofields")
|
||||
public void test_nonisofields_rangerefinedby(TemporalField field, int value, ValueRange valueRange) {
|
||||
field.rangeRefinedBy(HijrahDate.now());
|
||||
Assertions.assertThrows(UnsupportedTemporalTypeException.class, () -> field.rangeRefinedBy(HijrahDate.now()));
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
// getFrom
|
||||
//-----------------------------------------------------------------------
|
||||
@Test(dataProvider = "isofields")
|
||||
@ParameterizedTest
|
||||
@MethodSource("data_isofields")
|
||||
public void test_isofields_getFrom(TemporalField field, int value, ValueRange valueRange) {
|
||||
LocalDate date = LocalDate.of(2016, 5, 19);
|
||||
assertEquals(field.getFrom(date), value);
|
||||
assertEquals(value, field.getFrom(date));
|
||||
}
|
||||
|
||||
@Test(dataProvider = "isofields", expectedExceptions = UnsupportedTemporalTypeException.class)
|
||||
@ParameterizedTest
|
||||
@MethodSource("data_isofields")
|
||||
public void test_nonisofields_getFrom(TemporalField field, int value, ValueRange valueRange) {
|
||||
field.getFrom(HijrahDate.now());
|
||||
Assertions.assertThrows(UnsupportedTemporalTypeException.class, () -> field.getFrom(HijrahDate.now()));
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
@Test
|
||||
public void test_loop() {
|
||||
// loop round at least one 400 year cycle, including before 1970
|
||||
LocalDate date = LocalDate.of(1960, 1, 5); // Tuseday of week 1 1960
|
||||
@ -501,11 +530,11 @@ public class TCKIsoFields {
|
||||
wby++;
|
||||
}
|
||||
}
|
||||
assertEquals(IsoFields.WEEK_OF_WEEK_BASED_YEAR.rangeRefinedBy(date), ValueRange.of(1, weekLen), "Failed on " + date + " " + date.getDayOfWeek());
|
||||
assertEquals(IsoFields.WEEK_OF_WEEK_BASED_YEAR.getFrom(date), week, "Failed on " + date + " " + date.getDayOfWeek());
|
||||
assertEquals(date.get(IsoFields.WEEK_OF_WEEK_BASED_YEAR), week, "Failed on " + date + " " + date.getDayOfWeek());
|
||||
assertEquals(IsoFields.WEEK_BASED_YEAR.getFrom(date), wby, "Failed on " + date + " " + date.getDayOfWeek());
|
||||
assertEquals(date.get(IsoFields.WEEK_BASED_YEAR), wby, "Failed on " + date + " " + date.getDayOfWeek());
|
||||
assertEquals(ValueRange.of(1, weekLen), IsoFields.WEEK_OF_WEEK_BASED_YEAR.rangeRefinedBy(date), "Failed on " + date + " " + date.getDayOfWeek());
|
||||
assertEquals(week, IsoFields.WEEK_OF_WEEK_BASED_YEAR.getFrom(date), "Failed on " + date + " " + date.getDayOfWeek());
|
||||
assertEquals(week, date.get(IsoFields.WEEK_OF_WEEK_BASED_YEAR), "Failed on " + date + " " + date.getDayOfWeek());
|
||||
assertEquals(wby, IsoFields.WEEK_BASED_YEAR.getFrom(date), "Failed on " + date + " " + date.getDayOfWeek());
|
||||
assertEquals(wby, date.get(IsoFields.WEEK_BASED_YEAR), "Failed on " + date + " " + date.getDayOfWeek());
|
||||
date = date.plusDays(1);
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2012, 2013, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2012, 2025, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
@ -59,7 +59,7 @@
|
||||
*/
|
||||
package tck.java.time.temporal;
|
||||
|
||||
import static org.testng.Assert.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.time.LocalDate;
|
||||
@ -71,14 +71,17 @@ import java.time.temporal.IsoFields;
|
||||
import java.time.temporal.JulianFields;
|
||||
import java.time.temporal.TemporalField;
|
||||
|
||||
import org.testng.annotations.DataProvider;
|
||||
import org.testng.annotations.Test;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.TestInstance;
|
||||
import org.junit.jupiter.params.ParameterizedTest;
|
||||
import org.junit.jupiter.params.provider.MethodSource;
|
||||
|
||||
import tck.java.time.AbstractTCKTest;
|
||||
|
||||
/**
|
||||
* Test Julian Fields.
|
||||
*/
|
||||
@Test
|
||||
@TestInstance(TestInstance.Lifecycle.PER_CLASS)
|
||||
public class TCKJulianFields extends AbstractTCKTest {
|
||||
|
||||
private static final LocalDate JAN01_1970 = LocalDate.of(1970, 1, 1);
|
||||
@ -86,7 +89,6 @@ public class TCKJulianFields extends AbstractTCKTest {
|
||||
private static final LocalDate NOV12_1945 = LocalDate.of(1945, 11, 12);
|
||||
private static final LocalDate JAN01_0001 = LocalDate.of(1, 1, 1);
|
||||
|
||||
@DataProvider(name="samples")
|
||||
Object[][] data_samples() {
|
||||
return new Object[][] {
|
||||
{ChronoField.EPOCH_DAY, JAN01_1970, 0L},
|
||||
@ -112,55 +114,61 @@ public class TCKJulianFields extends AbstractTCKTest {
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
@Test
|
||||
public void test_basics() {
|
||||
assertEquals(JulianFields.JULIAN_DAY.isDateBased(), true);
|
||||
assertEquals(JulianFields.JULIAN_DAY.isTimeBased(), false);
|
||||
assertEquals(true, JulianFields.JULIAN_DAY.isDateBased());
|
||||
assertEquals(false, JulianFields.JULIAN_DAY.isTimeBased());
|
||||
|
||||
assertEquals(JulianFields.MODIFIED_JULIAN_DAY.isDateBased(), true);
|
||||
assertEquals(JulianFields.MODIFIED_JULIAN_DAY.isTimeBased(), false);
|
||||
assertEquals(true, JulianFields.MODIFIED_JULIAN_DAY.isDateBased());
|
||||
assertEquals(false, JulianFields.MODIFIED_JULIAN_DAY.isTimeBased());
|
||||
|
||||
assertEquals(JulianFields.RATA_DIE.isDateBased(), true);
|
||||
assertEquals(JulianFields.RATA_DIE.isTimeBased(), false);
|
||||
assertEquals(true, JulianFields.RATA_DIE.isDateBased());
|
||||
assertEquals(false, JulianFields.RATA_DIE.isTimeBased());
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
@Test(dataProvider="samples")
|
||||
@ParameterizedTest
|
||||
@MethodSource("data_samples")
|
||||
public void test_samples_get(TemporalField field, LocalDate date, long expected) {
|
||||
assertEquals(date.getLong(field), expected);
|
||||
assertEquals(expected, date.getLong(field));
|
||||
}
|
||||
|
||||
@Test(dataProvider="samples")
|
||||
@ParameterizedTest
|
||||
@MethodSource("data_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);
|
||||
assertEquals(date, field.adjustInto(LocalDate.MAX, value));
|
||||
assertEquals(date, field.adjustInto(LocalDate.MIN, value));
|
||||
assertEquals(date, field.adjustInto(JAN01_1970, value));
|
||||
assertEquals(date, field.adjustInto(DEC31_1969, value));
|
||||
assertEquals(date, field.adjustInto(NOV12_1945, value));
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
@Test(dataProvider="samples")
|
||||
@ParameterizedTest
|
||||
@MethodSource("data_samples")
|
||||
public void test_samples_parse_STRICT(TemporalField field, LocalDate date, long value) {
|
||||
DateTimeFormatter f = new DateTimeFormatterBuilder().appendValue(field)
|
||||
.toFormatter().withResolverStyle(ResolverStyle.STRICT);
|
||||
LocalDate parsed = LocalDate.parse(Long.toString(value), f);
|
||||
assertEquals(parsed, date);
|
||||
assertEquals(date, parsed);
|
||||
}
|
||||
|
||||
@Test(dataProvider="samples")
|
||||
@ParameterizedTest
|
||||
@MethodSource("data_samples")
|
||||
public void test_samples_parse_SMART(TemporalField field, LocalDate date, long value) {
|
||||
DateTimeFormatter f = new DateTimeFormatterBuilder().appendValue(field)
|
||||
.toFormatter().withResolverStyle(ResolverStyle.SMART);
|
||||
LocalDate parsed = LocalDate.parse(Long.toString(value), f);
|
||||
assertEquals(parsed, date);
|
||||
assertEquals(date, parsed);
|
||||
}
|
||||
|
||||
@Test(dataProvider="samples")
|
||||
@ParameterizedTest
|
||||
@MethodSource("data_samples")
|
||||
public void test_samples_parse_LENIENT(TemporalField field, LocalDate date, long value) {
|
||||
DateTimeFormatter f = new DateTimeFormatterBuilder().appendValue(field)
|
||||
.toFormatter().withResolverStyle(ResolverStyle.LENIENT);
|
||||
LocalDate parsed = LocalDate.parse(Long.toString(value), f);
|
||||
assertEquals(parsed, date);
|
||||
assertEquals(date, parsed);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2012, 2013, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2012, 2025, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
@ -63,11 +63,12 @@ import static java.time.DayOfWeek.MONDAY;
|
||||
import static java.time.DayOfWeek.TUESDAY;
|
||||
import static java.time.Month.DECEMBER;
|
||||
import static java.time.Month.JANUARY;
|
||||
import static org.testng.Assert.assertEquals;
|
||||
import static org.testng.Assert.assertFalse;
|
||||
import static org.testng.Assert.assertNotNull;
|
||||
import static org.testng.Assert.assertSame;
|
||||
import static org.testng.Assert.assertTrue;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||
import static org.junit.jupiter.api.Assertions.assertSame;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
import java.time.DayOfWeek;
|
||||
import java.time.LocalDate;
|
||||
@ -75,13 +76,16 @@ import java.time.Month;
|
||||
import java.time.temporal.TemporalAdjuster;
|
||||
import java.time.temporal.TemporalAdjusters;
|
||||
|
||||
import org.testng.annotations.DataProvider;
|
||||
import org.testng.annotations.Test;
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.TestInstance;
|
||||
import org.junit.jupiter.params.ParameterizedTest;
|
||||
import org.junit.jupiter.params.provider.MethodSource;
|
||||
|
||||
/**
|
||||
* Test TemporalAdjusters.
|
||||
*/
|
||||
@Test
|
||||
@TestInstance(TestInstance.Lifecycle.PER_CLASS)
|
||||
public class TCKTemporalAdjusters {
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
@ -90,12 +94,12 @@ public class TCKTemporalAdjusters {
|
||||
@Test
|
||||
public void factory_ofDateAdjuster() {
|
||||
TemporalAdjuster test = TemporalAdjusters.ofDateAdjuster(date -> date.plusDays(2));
|
||||
assertEquals(LocalDate.of(2012, 6, 30).with(test), LocalDate.of(2012, 7, 2));
|
||||
assertEquals(LocalDate.of(2012, 7, 2), LocalDate.of(2012, 6, 30).with(test));
|
||||
}
|
||||
|
||||
@Test(expectedExceptions = NullPointerException.class)
|
||||
@Test
|
||||
public void factory_ofDateAdjuster_null() {
|
||||
TemporalAdjusters.ofDateAdjuster(null);
|
||||
Assertions.assertThrows(NullPointerException.class, () -> TemporalAdjusters.ofDateAdjuster(null));
|
||||
}
|
||||
|
||||
|
||||
@ -113,9 +117,9 @@ public class TCKTemporalAdjusters {
|
||||
for (int i = 1; i <= month.length(false); i++) {
|
||||
LocalDate date = date(2007, month, i);
|
||||
LocalDate test = (LocalDate) TemporalAdjusters.firstDayOfMonth().adjustInto(date);
|
||||
assertEquals(test.getYear(), 2007);
|
||||
assertEquals(test.getMonth(), month);
|
||||
assertEquals(test.getDayOfMonth(), 1);
|
||||
assertEquals(2007, test.getYear());
|
||||
assertEquals(month, test.getMonth());
|
||||
assertEquals(1, test.getDayOfMonth());
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -126,9 +130,9 @@ public class TCKTemporalAdjusters {
|
||||
for (int i = 1; i <= month.length(true); i++) {
|
||||
LocalDate date = date(2008, month, i);
|
||||
LocalDate test = (LocalDate) TemporalAdjusters.firstDayOfMonth().adjustInto(date);
|
||||
assertEquals(test.getYear(), 2008);
|
||||
assertEquals(test.getMonth(), month);
|
||||
assertEquals(test.getDayOfMonth(), 1);
|
||||
assertEquals(2008, test.getYear());
|
||||
assertEquals(month, test.getMonth());
|
||||
assertEquals(1, test.getDayOfMonth());
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -147,9 +151,9 @@ public class TCKTemporalAdjusters {
|
||||
for (int i = 1; i <= month.length(false); i++) {
|
||||
LocalDate date = date(2007, month, i);
|
||||
LocalDate test = (LocalDate) TemporalAdjusters.lastDayOfMonth().adjustInto(date);
|
||||
assertEquals(test.getYear(), 2007);
|
||||
assertEquals(test.getMonth(), month);
|
||||
assertEquals(test.getDayOfMonth(), month.length(false));
|
||||
assertEquals(2007, test.getYear());
|
||||
assertEquals(month, test.getMonth());
|
||||
assertEquals(month.length(false), test.getDayOfMonth());
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -160,9 +164,9 @@ public class TCKTemporalAdjusters {
|
||||
for (int i = 1; i <= month.length(true); i++) {
|
||||
LocalDate date = date(2008, month, i);
|
||||
LocalDate test = (LocalDate) TemporalAdjusters.lastDayOfMonth().adjustInto(date);
|
||||
assertEquals(test.getYear(), 2008);
|
||||
assertEquals(test.getMonth(), month);
|
||||
assertEquals(test.getDayOfMonth(), month.length(true));
|
||||
assertEquals(2008, test.getYear());
|
||||
assertEquals(month, test.getMonth());
|
||||
assertEquals(month.length(true), test.getDayOfMonth());
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -181,9 +185,9 @@ public class TCKTemporalAdjusters {
|
||||
for (int i = 1; i <= month.length(false); i++) {
|
||||
LocalDate date = date(2007, month, i);
|
||||
LocalDate test = (LocalDate) TemporalAdjusters.firstDayOfNextMonth().adjustInto(date);
|
||||
assertEquals(test.getYear(), month == DECEMBER ? 2008 : 2007);
|
||||
assertEquals(test.getMonth(), month.plus(1));
|
||||
assertEquals(test.getDayOfMonth(), 1);
|
||||
assertEquals(month == DECEMBER ? 2008 : 2007, test.getYear());
|
||||
assertEquals(month.plus(1), test.getMonth());
|
||||
assertEquals(1, test.getDayOfMonth());
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -194,9 +198,9 @@ public class TCKTemporalAdjusters {
|
||||
for (int i = 1; i <= month.length(true); i++) {
|
||||
LocalDate date = date(2008, month, i);
|
||||
LocalDate test = (LocalDate) TemporalAdjusters.firstDayOfNextMonth().adjustInto(date);
|
||||
assertEquals(test.getYear(), month == DECEMBER ? 2009 : 2008);
|
||||
assertEquals(test.getMonth(), month.plus(1));
|
||||
assertEquals(test.getDayOfMonth(), 1);
|
||||
assertEquals(month == DECEMBER ? 2009 : 2008, test.getYear());
|
||||
assertEquals(month.plus(1), test.getMonth());
|
||||
assertEquals(1, test.getDayOfMonth());
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -215,9 +219,9 @@ public class TCKTemporalAdjusters {
|
||||
for (int i = 1; i <= month.length(false); i++) {
|
||||
LocalDate date = date(2007, month, i);
|
||||
LocalDate test = (LocalDate) TemporalAdjusters.firstDayOfYear().adjustInto(date);
|
||||
assertEquals(test.getYear(), 2007);
|
||||
assertEquals(test.getMonth(), Month.JANUARY);
|
||||
assertEquals(test.getDayOfMonth(), 1);
|
||||
assertEquals(2007, test.getYear());
|
||||
assertEquals(Month.JANUARY, test.getMonth());
|
||||
assertEquals(1, test.getDayOfMonth());
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -228,9 +232,9 @@ public class TCKTemporalAdjusters {
|
||||
for (int i = 1; i <= month.length(true); i++) {
|
||||
LocalDate date = date(2008, month, i);
|
||||
LocalDate test = (LocalDate) TemporalAdjusters.firstDayOfYear().adjustInto(date);
|
||||
assertEquals(test.getYear(), 2008);
|
||||
assertEquals(test.getMonth(), Month.JANUARY);
|
||||
assertEquals(test.getDayOfMonth(), 1);
|
||||
assertEquals(2008, test.getYear());
|
||||
assertEquals(Month.JANUARY, test.getMonth());
|
||||
assertEquals(1, test.getDayOfMonth());
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -249,9 +253,9 @@ public class TCKTemporalAdjusters {
|
||||
for (int i = 1; i <= month.length(false); i++) {
|
||||
LocalDate date = date(2007, month, i);
|
||||
LocalDate test = (LocalDate) TemporalAdjusters.lastDayOfYear().adjustInto(date);
|
||||
assertEquals(test.getYear(), 2007);
|
||||
assertEquals(test.getMonth(), Month.DECEMBER);
|
||||
assertEquals(test.getDayOfMonth(), 31);
|
||||
assertEquals(2007, test.getYear());
|
||||
assertEquals(Month.DECEMBER, test.getMonth());
|
||||
assertEquals(31, test.getDayOfMonth());
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -262,9 +266,9 @@ public class TCKTemporalAdjusters {
|
||||
for (int i = 1; i <= month.length(true); i++) {
|
||||
LocalDate date = date(2008, month, i);
|
||||
LocalDate test = (LocalDate) TemporalAdjusters.lastDayOfYear().adjustInto(date);
|
||||
assertEquals(test.getYear(), 2008);
|
||||
assertEquals(test.getMonth(), Month.DECEMBER);
|
||||
assertEquals(test.getDayOfMonth(), 31);
|
||||
assertEquals(2008, test.getYear());
|
||||
assertEquals(Month.DECEMBER, test.getMonth());
|
||||
assertEquals(31, test.getDayOfMonth());
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -283,9 +287,9 @@ public class TCKTemporalAdjusters {
|
||||
for (int i = 1; i <= month.length(false); i++) {
|
||||
LocalDate date = date(2007, month, i);
|
||||
LocalDate test = (LocalDate) TemporalAdjusters.firstDayOfNextYear().adjustInto(date);
|
||||
assertEquals(test.getYear(), 2008);
|
||||
assertEquals(test.getMonth(), JANUARY);
|
||||
assertEquals(test.getDayOfMonth(), 1);
|
||||
assertEquals(2008, test.getYear());
|
||||
assertEquals(JANUARY, test.getMonth());
|
||||
assertEquals(1, test.getDayOfMonth());
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -296,9 +300,9 @@ public class TCKTemporalAdjusters {
|
||||
for (int i = 1; i <= month.length(true); i++) {
|
||||
LocalDate date = date(2008, month, i);
|
||||
LocalDate test = (LocalDate) TemporalAdjusters.firstDayOfNextYear().adjustInto(date);
|
||||
assertEquals(test.getYear(), 2009);
|
||||
assertEquals(test.getMonth(), JANUARY);
|
||||
assertEquals(test.getDayOfMonth(), 1);
|
||||
assertEquals(2009, test.getYear());
|
||||
assertEquals(JANUARY, test.getMonth());
|
||||
assertEquals(1, test.getDayOfMonth());
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -311,12 +315,11 @@ public class TCKTemporalAdjusters {
|
||||
assertNotNull(TemporalAdjusters.dayOfWeekInMonth(1, MONDAY));
|
||||
}
|
||||
|
||||
@Test(expectedExceptions=NullPointerException.class)
|
||||
@Test
|
||||
public void factory_dayOfWeekInMonth_nullDayOfWeek() {
|
||||
TemporalAdjusters.dayOfWeekInMonth(1, null);
|
||||
Assertions.assertThrows(NullPointerException.class, () -> TemporalAdjusters.dayOfWeekInMonth(1, null));
|
||||
}
|
||||
|
||||
@DataProvider(name = "dayOfWeekInMonth_positive")
|
||||
Object[][] data_dayOfWeekInMonth_positive() {
|
||||
return new Object[][] {
|
||||
{2011, 1, TUESDAY, date(2011, 1, 4)},
|
||||
@ -334,18 +337,18 @@ public class TCKTemporalAdjusters {
|
||||
};
|
||||
}
|
||||
|
||||
@Test(dataProvider = "dayOfWeekInMonth_positive")
|
||||
@ParameterizedTest
|
||||
@MethodSource("data_dayOfWeekInMonth_positive")
|
||||
public void test_dayOfWeekInMonth_positive(int year, int month, DayOfWeek dow, LocalDate expected) {
|
||||
for (int ordinal = 1; ordinal <= 5; ordinal++) {
|
||||
for (int day = 1; day <= Month.of(month).length(false); day++) {
|
||||
LocalDate date = date(year, month, day);
|
||||
LocalDate test = (LocalDate) TemporalAdjusters.dayOfWeekInMonth(ordinal, dow).adjustInto(date);
|
||||
assertEquals(test, expected.plusWeeks(ordinal - 1));
|
||||
assertEquals(expected.plusWeeks(ordinal - 1), test);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@DataProvider(name = "dayOfWeekInMonth_zero")
|
||||
Object[][] data_dayOfWeekInMonth_zero() {
|
||||
return new Object[][] {
|
||||
{2011, 1, TUESDAY, date(2010, 12, 28)},
|
||||
@ -363,16 +366,16 @@ public class TCKTemporalAdjusters {
|
||||
};
|
||||
}
|
||||
|
||||
@Test(dataProvider = "dayOfWeekInMonth_zero")
|
||||
@ParameterizedTest
|
||||
@MethodSource("data_dayOfWeekInMonth_zero")
|
||||
public void test_dayOfWeekInMonth_zero(int year, int month, DayOfWeek dow, LocalDate expected) {
|
||||
for (int day = 1; day <= Month.of(month).length(false); day++) {
|
||||
LocalDate date = date(year, month, day);
|
||||
LocalDate test = (LocalDate) TemporalAdjusters.dayOfWeekInMonth(0, dow).adjustInto(date);
|
||||
assertEquals(test, expected);
|
||||
assertEquals(expected, test);
|
||||
}
|
||||
}
|
||||
|
||||
@DataProvider(name = "dayOfWeekInMonth_negative")
|
||||
Object[][] data_dayOfWeekInMonth_negative() {
|
||||
return new Object[][] {
|
||||
{2011, 1, TUESDAY, date(2011, 1, 25)},
|
||||
@ -390,13 +393,14 @@ public class TCKTemporalAdjusters {
|
||||
};
|
||||
}
|
||||
|
||||
@Test(dataProvider = "dayOfWeekInMonth_negative")
|
||||
@ParameterizedTest
|
||||
@MethodSource("data_dayOfWeekInMonth_negative")
|
||||
public void test_dayOfWeekInMonth_negative(int year, int month, DayOfWeek dow, LocalDate expected) {
|
||||
for (int ordinal = 0; ordinal < 5; ordinal++) {
|
||||
for (int day = 1; day <= Month.of(month).length(false); day++) {
|
||||
LocalDate date = date(year, month, day);
|
||||
LocalDate test = (LocalDate) TemporalAdjusters.dayOfWeekInMonth(-1 - ordinal, dow).adjustInto(date);
|
||||
assertEquals(test, expected.minusWeeks(ordinal));
|
||||
assertEquals(expected.minusWeeks(ordinal), test);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -409,17 +413,18 @@ public class TCKTemporalAdjusters {
|
||||
assertNotNull(TemporalAdjusters.firstInMonth(MONDAY));
|
||||
}
|
||||
|
||||
@Test(expectedExceptions=NullPointerException.class)
|
||||
@Test
|
||||
public void factory_firstInMonth_nullDayOfWeek() {
|
||||
TemporalAdjusters.firstInMonth(null);
|
||||
Assertions.assertThrows(NullPointerException.class, () -> TemporalAdjusters.firstInMonth(null));
|
||||
}
|
||||
|
||||
@Test(dataProvider = "dayOfWeekInMonth_positive")
|
||||
@ParameterizedTest
|
||||
@MethodSource("data_dayOfWeekInMonth_positive")
|
||||
public void test_firstInMonth(int year, int month, DayOfWeek dow, LocalDate expected) {
|
||||
for (int day = 1; day <= Month.of(month).length(false); day++) {
|
||||
LocalDate date = date(year, month, day);
|
||||
LocalDate test = (LocalDate) TemporalAdjusters.firstInMonth(dow).adjustInto(date);
|
||||
assertEquals(test, expected, "day-of-month=" + day);
|
||||
assertEquals(expected, test, "day-of-month=" + day);
|
||||
}
|
||||
}
|
||||
|
||||
@ -431,17 +436,18 @@ public class TCKTemporalAdjusters {
|
||||
assertNotNull(TemporalAdjusters.lastInMonth(MONDAY));
|
||||
}
|
||||
|
||||
@Test(expectedExceptions=NullPointerException.class)
|
||||
@Test
|
||||
public void factory_lastInMonth_nullDayOfWeek() {
|
||||
TemporalAdjusters.lastInMonth(null);
|
||||
Assertions.assertThrows(NullPointerException.class, () -> TemporalAdjusters.lastInMonth(null));
|
||||
}
|
||||
|
||||
@Test(dataProvider = "dayOfWeekInMonth_negative")
|
||||
@ParameterizedTest
|
||||
@MethodSource("data_dayOfWeekInMonth_negative")
|
||||
public void test_lastInMonth(int year, int month, DayOfWeek dow, LocalDate expected) {
|
||||
for (int day = 1; day <= Month.of(month).length(false); day++) {
|
||||
LocalDate date = date(year, month, day);
|
||||
LocalDate test = (LocalDate) TemporalAdjusters.lastInMonth(dow).adjustInto(date);
|
||||
assertEquals(test, expected, "day-of-month=" + day);
|
||||
assertEquals(expected, test, "day-of-month=" + day);
|
||||
}
|
||||
}
|
||||
|
||||
@ -453,9 +459,9 @@ public class TCKTemporalAdjusters {
|
||||
assertNotNull(TemporalAdjusters.next(MONDAY));
|
||||
}
|
||||
|
||||
@Test(expectedExceptions = NullPointerException.class)
|
||||
@Test
|
||||
public void factory_next_nullDayOfWeek() {
|
||||
TemporalAdjusters.next(null);
|
||||
Assertions.assertThrows(NullPointerException.class, () -> TemporalAdjusters.next(null));
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -475,7 +481,7 @@ public class TCKTemporalAdjusters {
|
||||
} else {
|
||||
assertSame(month, Month.DECEMBER);
|
||||
assertTrue(date.getDayOfMonth() > 24);
|
||||
assertEquals(test.getYear(), 2008);
|
||||
assertEquals(2008, test.getYear());
|
||||
assertSame(test.getMonth(), Month.JANUARY);
|
||||
assertTrue(test.getDayOfMonth() < 8);
|
||||
}
|
||||
@ -492,9 +498,9 @@ public class TCKTemporalAdjusters {
|
||||
assertNotNull(TemporalAdjusters.nextOrSame(MONDAY));
|
||||
}
|
||||
|
||||
@Test(expectedExceptions = NullPointerException.class)
|
||||
@Test
|
||||
public void factory_nextOrCurrent_nullDayOfWeek() {
|
||||
TemporalAdjusters.nextOrSame(null);
|
||||
Assertions.assertThrows(NullPointerException.class, () -> TemporalAdjusters.nextOrSame(null));
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -511,12 +517,12 @@ public class TCKTemporalAdjusters {
|
||||
if (test.getYear() == 2007) {
|
||||
int dayDiff = test.getDayOfYear() - date.getDayOfYear();
|
||||
assertTrue(dayDiff < 8);
|
||||
assertEquals(date.equals(test), date.getDayOfWeek() == dow);
|
||||
assertEquals(date.getDayOfWeek() == dow, date.equals(test));
|
||||
} else {
|
||||
assertFalse(date.getDayOfWeek() == dow);
|
||||
assertSame(month, Month.DECEMBER);
|
||||
assertTrue(date.getDayOfMonth() > 24);
|
||||
assertEquals(test.getYear(), 2008);
|
||||
assertEquals(2008, test.getYear());
|
||||
assertSame(test.getMonth(), Month.JANUARY);
|
||||
assertTrue(test.getDayOfMonth() < 8);
|
||||
}
|
||||
@ -533,9 +539,9 @@ public class TCKTemporalAdjusters {
|
||||
assertNotNull(TemporalAdjusters.previous(MONDAY));
|
||||
}
|
||||
|
||||
@Test(expectedExceptions = NullPointerException.class)
|
||||
@Test
|
||||
public void factory_previous_nullDayOfWeek() {
|
||||
TemporalAdjusters.previous(null);
|
||||
Assertions.assertThrows(NullPointerException.class, () -> TemporalAdjusters.previous(null));
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -555,7 +561,7 @@ public class TCKTemporalAdjusters {
|
||||
} else {
|
||||
assertSame(month, Month.JANUARY);
|
||||
assertTrue(date.getDayOfMonth() < 8);
|
||||
assertEquals(test.getYear(), 2006);
|
||||
assertEquals(2006, test.getYear());
|
||||
assertSame(test.getMonth(), Month.DECEMBER);
|
||||
assertTrue(test.getDayOfMonth() > 24);
|
||||
}
|
||||
@ -572,9 +578,9 @@ public class TCKTemporalAdjusters {
|
||||
assertNotNull(TemporalAdjusters.previousOrSame(MONDAY));
|
||||
}
|
||||
|
||||
@Test(expectedExceptions = NullPointerException.class)
|
||||
@Test
|
||||
public void factory_previousOrCurrent_nullDayOfWeek() {
|
||||
TemporalAdjusters.previousOrSame(null);
|
||||
Assertions.assertThrows(NullPointerException.class, () -> TemporalAdjusters.previousOrSame(null));
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -591,12 +597,12 @@ public class TCKTemporalAdjusters {
|
||||
if (test.getYear() == 2007) {
|
||||
int dayDiff = test.getDayOfYear() - date.getDayOfYear();
|
||||
assertTrue(dayDiff <= 0 && dayDiff > -7);
|
||||
assertEquals(date.equals(test), date.getDayOfWeek() == dow);
|
||||
assertEquals(date.getDayOfWeek() == dow, date.equals(test));
|
||||
} else {
|
||||
assertFalse(date.getDayOfWeek() == dow);
|
||||
assertSame(month, Month.JANUARY);
|
||||
assertTrue(date.getDayOfMonth() < 7);
|
||||
assertEquals(test.getYear(), 2006);
|
||||
assertEquals(2006, test.getYear());
|
||||
assertSame(test.getMonth(), Month.DECEMBER);
|
||||
assertTrue(test.getDayOfMonth() > 25);
|
||||
}
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2012, 2013, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2012, 2025, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
@ -62,11 +62,12 @@ import static java.time.temporal.ChronoField.DAY_OF_WEEK;
|
||||
import static java.time.temporal.ChronoField.DAY_OF_YEAR;
|
||||
import static java.time.temporal.ChronoField.MONTH_OF_YEAR;
|
||||
import static java.time.temporal.ChronoField.YEAR;
|
||||
import static org.testng.Assert.assertEquals;
|
||||
import static org.testng.Assert.assertFalse;
|
||||
import static org.testng.Assert.assertNotEquals;
|
||||
import static org.testng.Assert.assertSame;
|
||||
import static org.testng.Assert.assertTrue;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||
import static org.junit.jupiter.api.Assertions.assertNotEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertSame;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.time.DateTimeException;
|
||||
@ -79,85 +80,92 @@ import java.time.temporal.TemporalField;
|
||||
import java.time.temporal.ValueRange;
|
||||
import java.time.temporal.WeekFields;
|
||||
|
||||
import org.testng.annotations.DataProvider;
|
||||
import org.testng.annotations.Test;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.TestInstance;
|
||||
import org.junit.jupiter.params.ParameterizedTest;
|
||||
import org.junit.jupiter.params.provider.MethodSource;
|
||||
|
||||
import tck.java.time.AbstractTCKTest;
|
||||
|
||||
/**
|
||||
* Test WeekFields.
|
||||
*/
|
||||
@Test
|
||||
@TestInstance(TestInstance.Lifecycle.PER_CLASS)
|
||||
public class TCKWeekFields extends AbstractTCKTest {
|
||||
|
||||
@Test(dataProvider="weekFields")
|
||||
@ParameterizedTest
|
||||
@MethodSource("data_weekFields")
|
||||
public void test_of_DayOfWeek_int_singleton(DayOfWeek firstDayOfWeek, int minDays) {
|
||||
WeekFields week = WeekFields.of(firstDayOfWeek, minDays);
|
||||
assertEquals(week.getFirstDayOfWeek(), firstDayOfWeek, "Incorrect firstDayOfWeek");
|
||||
assertEquals(week.getMinimalDaysInFirstWeek(), minDays, "Incorrect MinimalDaysInFirstWeek");
|
||||
assertEquals(firstDayOfWeek, week.getFirstDayOfWeek(), "Incorrect firstDayOfWeek");
|
||||
assertEquals(minDays, week.getMinimalDaysInFirstWeek(), "Incorrect MinimalDaysInFirstWeek");
|
||||
assertSame(WeekFields.of(firstDayOfWeek, minDays), week);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
@Test(dataProvider="weekFields")
|
||||
@ParameterizedTest
|
||||
@MethodSource("data_weekFields")
|
||||
public void test_basics(DayOfWeek firstDayOfWeek, int minDays) {
|
||||
WeekFields week = WeekFields.of(firstDayOfWeek, minDays);
|
||||
assertEquals(week.dayOfWeek().isDateBased(), true);
|
||||
assertEquals(week.dayOfWeek().isTimeBased(), false);
|
||||
assertEquals(true, week.dayOfWeek().isDateBased());
|
||||
assertEquals(false, week.dayOfWeek().isTimeBased());
|
||||
|
||||
assertEquals(week.weekOfMonth().isDateBased(), true);
|
||||
assertEquals(week.weekOfMonth().isTimeBased(), false);
|
||||
assertEquals(true, week.weekOfMonth().isDateBased());
|
||||
assertEquals(false, week.weekOfMonth().isTimeBased());
|
||||
|
||||
assertEquals(week.weekOfYear().isDateBased(), true);
|
||||
assertEquals(week.weekOfYear().isTimeBased(), false);
|
||||
assertEquals(true, week.weekOfYear().isDateBased());
|
||||
assertEquals(false, week.weekOfYear().isTimeBased());
|
||||
|
||||
assertEquals(week.weekOfWeekBasedYear().isDateBased(), true);
|
||||
assertEquals(week.weekOfWeekBasedYear().isTimeBased(), false);
|
||||
assertEquals(true, week.weekOfWeekBasedYear().isDateBased());
|
||||
assertEquals(false, week.weekOfWeekBasedYear().isTimeBased());
|
||||
|
||||
assertEquals(week.weekBasedYear().isDateBased(), true);
|
||||
assertEquals(week.weekBasedYear().isTimeBased(), false);
|
||||
assertEquals(true, week.weekBasedYear().isDateBased());
|
||||
assertEquals(false, week.weekBasedYear().isTimeBased());
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
@Test
|
||||
public void test_dayOfWeekField_simpleGet() {
|
||||
LocalDate date = LocalDate.of(2000, 1, 10); // Known to be ISO Monday
|
||||
assertEquals(date.get(WeekFields.ISO.dayOfWeek()), 1);
|
||||
assertEquals(date.get(WeekFields.of(DayOfWeek.MONDAY, 1).dayOfWeek()), 1);
|
||||
assertEquals(date.get(WeekFields.of(DayOfWeek.MONDAY, 7).dayOfWeek()), 1);
|
||||
assertEquals(date.get(WeekFields.SUNDAY_START.dayOfWeek()), 2);
|
||||
assertEquals(date.get(WeekFields.of(DayOfWeek.SUNDAY, 1).dayOfWeek()), 2);
|
||||
assertEquals(date.get(WeekFields.of(DayOfWeek.SUNDAY, 7).dayOfWeek()), 2);
|
||||
assertEquals(date.get(WeekFields.of(DayOfWeek.SATURDAY, 1).dayOfWeek()), 3);
|
||||
assertEquals(date.get(WeekFields.of(DayOfWeek.FRIDAY, 1).dayOfWeek()), 4);
|
||||
assertEquals(date.get(WeekFields.of(DayOfWeek.TUESDAY, 1).dayOfWeek()), 7);
|
||||
assertEquals(1, date.get(WeekFields.ISO.dayOfWeek()));
|
||||
assertEquals(1, date.get(WeekFields.of(DayOfWeek.MONDAY, 1).dayOfWeek()));
|
||||
assertEquals(1, date.get(WeekFields.of(DayOfWeek.MONDAY, 7).dayOfWeek()));
|
||||
assertEquals(2, date.get(WeekFields.SUNDAY_START.dayOfWeek()));
|
||||
assertEquals(2, date.get(WeekFields.of(DayOfWeek.SUNDAY, 1).dayOfWeek()));
|
||||
assertEquals(2, date.get(WeekFields.of(DayOfWeek.SUNDAY, 7).dayOfWeek()));
|
||||
assertEquals(3, date.get(WeekFields.of(DayOfWeek.SATURDAY, 1).dayOfWeek()));
|
||||
assertEquals(4, date.get(WeekFields.of(DayOfWeek.FRIDAY, 1).dayOfWeek()));
|
||||
assertEquals(7, date.get(WeekFields.of(DayOfWeek.TUESDAY, 1).dayOfWeek()));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test_dayOfWeekField_simpleSet() {
|
||||
LocalDate date = LocalDate.of(2000, 1, 10); // Known to be ISO Monday
|
||||
assertEquals(date.with(WeekFields.ISO.dayOfWeek(), 2), LocalDate.of(2000, 1, 11));
|
||||
assertEquals(date.with(WeekFields.ISO.dayOfWeek(), 7), LocalDate.of(2000, 1, 16));
|
||||
assertEquals(LocalDate.of(2000, 1, 11), date.with(WeekFields.ISO.dayOfWeek(), 2));
|
||||
assertEquals(LocalDate.of(2000, 1, 16), date.with(WeekFields.ISO.dayOfWeek(), 7));
|
||||
|
||||
assertEquals(date.with(WeekFields.SUNDAY_START.dayOfWeek(), 3), LocalDate.of(2000, 1, 11));
|
||||
assertEquals(date.with(WeekFields.SUNDAY_START.dayOfWeek(), 7), LocalDate.of(2000, 1, 15));
|
||||
assertEquals(LocalDate.of(2000, 1, 11), date.with(WeekFields.SUNDAY_START.dayOfWeek(), 3));
|
||||
assertEquals(LocalDate.of(2000, 1, 15), date.with(WeekFields.SUNDAY_START.dayOfWeek(), 7));
|
||||
|
||||
assertEquals(date.with(WeekFields.of(DayOfWeek.SATURDAY, 1).dayOfWeek(), 4), LocalDate.of(2000, 1, 11));
|
||||
assertEquals(date.with(WeekFields.of(DayOfWeek.TUESDAY, 1).dayOfWeek(), 1), LocalDate.of(2000, 1, 4));
|
||||
assertEquals(LocalDate.of(2000, 1, 11), date.with(WeekFields.of(DayOfWeek.SATURDAY, 1).dayOfWeek(), 4));
|
||||
assertEquals(LocalDate.of(2000, 1, 4), date.with(WeekFields.of(DayOfWeek.TUESDAY, 1).dayOfWeek(), 1));
|
||||
}
|
||||
|
||||
@Test(dataProvider="weekFields")
|
||||
@ParameterizedTest
|
||||
@MethodSource("data_weekFields")
|
||||
public void test_dayOfWeekField(DayOfWeek firstDayOfWeek, int minDays) {
|
||||
LocalDate day = LocalDate.of(2000, 1, 10); // Known to be ISO Monday
|
||||
WeekFields week = WeekFields.of(firstDayOfWeek, minDays);
|
||||
TemporalField f = week.dayOfWeek();
|
||||
|
||||
for (int i = 1; i <= 7; i++) {
|
||||
assertEquals(day.get(f), (7 + day.getDayOfWeek().getValue() - firstDayOfWeek.getValue()) % 7 + 1);
|
||||
assertEquals((7 + day.getDayOfWeek().getValue() - firstDayOfWeek.getValue()) % 7 + 1, day.get(f));
|
||||
day = day.plusDays(1);
|
||||
}
|
||||
}
|
||||
|
||||
@Test(dataProvider="weekFields")
|
||||
@ParameterizedTest
|
||||
@MethodSource("data_weekFields")
|
||||
public void test_weekOfMonthField(DayOfWeek firstDayOfWeek, int minDays) {
|
||||
LocalDate day = LocalDate.of(2012, 12, 31); // Known to be ISO Monday
|
||||
WeekFields week = WeekFields.of(firstDayOfWeek, minDays);
|
||||
@ -183,14 +191,15 @@ public class TCKWeekFields extends AbstractTCKTest {
|
||||
offset += (actualWOM - 1) * 7;
|
||||
LocalDate result = day1.plusDays(offset);
|
||||
|
||||
assertEquals(result, day, "Incorrect dayOfWeek or weekOfMonth: "
|
||||
assertEquals(day, result, "Incorrect dayOfWeek or weekOfMonth: "
|
||||
+ String.format("%s, ISO Dow: %s, offset: %s, actualDOW: %s, actualWOM: %s, expected: %s, result: %s%n",
|
||||
week, day.getDayOfWeek(), offset, actualDOW, actualWOM, day, result));
|
||||
day = day.plusDays(1);
|
||||
}
|
||||
}
|
||||
|
||||
@Test(dataProvider="weekFields")
|
||||
@ParameterizedTest
|
||||
@MethodSource("data_weekFields")
|
||||
public void test_weekOfYearField(DayOfWeek firstDayOfWeek, int minDays) {
|
||||
LocalDate day = LocalDate.of(2012, 12, 31); // Known to be ISO Monday
|
||||
WeekFields week = WeekFields.of(firstDayOfWeek, minDays);
|
||||
@ -214,7 +223,7 @@ public class TCKWeekFields extends AbstractTCKTest {
|
||||
offset += (actualWOY - 1) * 7;
|
||||
LocalDate result = day1.plusDays(offset);
|
||||
|
||||
assertEquals(result, day, "Incorrect dayOfWeek or weekOfYear "
|
||||
assertEquals(day, result, "Incorrect dayOfWeek or weekOfYear "
|
||||
+ String.format("%s, ISO Dow: %s, offset: %s, actualDOW: %s, actualWOM: %s, expected: %s, result: %s%n",
|
||||
week, day.getDayOfWeek(), offset, actualDOW, actualWOY, day, result));
|
||||
day = day.plusDays(1);
|
||||
@ -228,7 +237,8 @@ public class TCKWeekFields extends AbstractTCKTest {
|
||||
* @param firstDayOfWeek the first day of the week
|
||||
* @param minDays the minimum number of days in the week
|
||||
*/
|
||||
@Test(dataProvider="weekFields")
|
||||
@ParameterizedTest
|
||||
@MethodSource("data_weekFields")
|
||||
public void test_weekOfWeekBasedYearField(DayOfWeek firstDayOfWeek, int minDays) {
|
||||
LocalDate day = LocalDate.of(2012, 12, 31); // Known to be ISO Monday
|
||||
WeekFields weekDef = WeekFields.of(firstDayOfWeek, minDays);
|
||||
@ -256,14 +266,15 @@ public class TCKWeekFields extends AbstractTCKTest {
|
||||
weekStart += (actualWOWBY - 1) * 7;
|
||||
LocalDate result = day1.plusDays(weekStart);
|
||||
|
||||
assertEquals(result, day, "Incorrect dayOfWeek or weekOfYear "
|
||||
assertEquals(day, result, "Incorrect dayOfWeek or weekOfYear "
|
||||
+ String.format("%s, ISO Dow: %s, weekStart: %s, actualDOW: %s, actualWOWBY: %s, YearOfWBY: %d, expected day: %s, result: %s%n",
|
||||
weekDef, day.getDayOfWeek(), weekStart, actualDOW, actualWOWBY, actualYOWBY, day, result));
|
||||
day = day.plusDays(1);
|
||||
}
|
||||
}
|
||||
|
||||
@Test(dataProvider="weekFields")
|
||||
@ParameterizedTest
|
||||
@MethodSource("data_weekFields")
|
||||
public void test_fieldRanges(DayOfWeek firstDayOfWeek, int minDays) {
|
||||
WeekFields weekDef = WeekFields.of(firstDayOfWeek, minDays);
|
||||
TemporalField womField = weekDef.weekOfMonth();
|
||||
@ -277,10 +288,10 @@ public class TCKWeekFields extends AbstractTCKTest {
|
||||
LocalDate first = day.with(DAY_OF_MONTH, 1);
|
||||
int firstWOM = first.get(womField);
|
||||
ValueRange rangeWOM = day.range(womField);
|
||||
assertEquals(rangeWOM.getMinimum(), firstWOM,
|
||||
assertEquals(firstWOM, rangeWOM.getMinimum(),
|
||||
"Range min should be same as WeekOfMonth for first day of month: "
|
||||
+ first + ", " + weekDef);
|
||||
assertEquals(rangeWOM.getMaximum(), lastWOM,
|
||||
assertEquals(lastWOM, rangeWOM.getMaximum(),
|
||||
"Range max should be same as WeekOfMonth for last day of month: "
|
||||
+ last + ", " + weekDef);
|
||||
|
||||
@ -289,10 +300,10 @@ public class TCKWeekFields extends AbstractTCKTest {
|
||||
first = day.with(DAY_OF_YEAR, 1);
|
||||
int firstWOY = first.get(woyField);
|
||||
ValueRange rangeWOY = day.range(woyField);
|
||||
assertEquals(rangeWOY.getMinimum(), firstWOY,
|
||||
assertEquals(firstWOY, rangeWOY.getMinimum(),
|
||||
"Range min should be same as WeekOfYear for first day of Year: "
|
||||
+ day + ", " + weekDef);
|
||||
assertEquals(rangeWOY.getMaximum(), lastWOY,
|
||||
assertEquals(lastWOY, rangeWOY.getMaximum(),
|
||||
"Range max should be same as WeekOfYear for last day of Year: "
|
||||
+ day + ", " + weekDef);
|
||||
|
||||
@ -303,7 +314,8 @@ public class TCKWeekFields extends AbstractTCKTest {
|
||||
//-----------------------------------------------------------------------
|
||||
// withDayOfWeek()
|
||||
//-----------------------------------------------------------------------
|
||||
@Test(dataProvider="weekFields")
|
||||
@ParameterizedTest
|
||||
@MethodSource("data_weekFields")
|
||||
public void test_withDayOfWeek(DayOfWeek firstDayOfWeek, int minDays) {
|
||||
LocalDate day = LocalDate.of(2012, 12, 15); // Safely in the middle of a month
|
||||
WeekFields week = WeekFields.of(firstDayOfWeek, minDays);
|
||||
@ -315,13 +327,14 @@ public class TCKWeekFields extends AbstractTCKTest {
|
||||
int woy = day.get(woyField);
|
||||
for (int dow = 1; dow <= 7; dow++) {
|
||||
LocalDate result = day.with(dowField, dow);
|
||||
assertEquals(result.get(dowField), dow, String.format("Incorrect new Day of week: %s", result));
|
||||
assertEquals(result.get(womField), wom, "Week of Month should not change");
|
||||
assertEquals(result.get(woyField), woy, "Week of Year should not change");
|
||||
assertEquals(dow, result.get(dowField), String.format("Incorrect new Day of week: %s", result));
|
||||
assertEquals(wom, result.get(womField), "Week of Month should not change");
|
||||
assertEquals(woy, result.get(woyField), "Week of Year should not change");
|
||||
}
|
||||
}
|
||||
|
||||
@Test(dataProvider="weekFields")
|
||||
@ParameterizedTest
|
||||
@MethodSource("data_weekFields")
|
||||
public void test_rangeWeekOfWeekBasedYear(DayOfWeek firstDayOfWeek, int minDays) {
|
||||
WeekFields weekFields = WeekFields.of(firstDayOfWeek, minDays);
|
||||
TemporalField dowField = weekFields.dayOfWeek();
|
||||
@ -336,10 +349,11 @@ public class TCKWeekFields extends AbstractTCKTest {
|
||||
int expectedWeeks = (int)ChronoUnit.DAYS.between(day1, day2) / 7;
|
||||
|
||||
ValueRange range = day1.range(wowByField);
|
||||
assertEquals(range.getMaximum(), expectedWeeks, "Range incorrect");
|
||||
assertEquals(expectedWeeks, range.getMaximum(), "Range incorrect");
|
||||
}
|
||||
|
||||
@Test(dataProvider="weekFields")
|
||||
@ParameterizedTest
|
||||
@MethodSource("data_weekFields")
|
||||
public void test_withWeekOfWeekBasedYear(DayOfWeek firstDayOfWeek, int minDays) {
|
||||
LocalDate day = LocalDate.of(2012, 12, 31);
|
||||
WeekFields week = WeekFields.of(firstDayOfWeek, minDays);
|
||||
@ -350,30 +364,31 @@ public class TCKWeekFields extends AbstractTCKTest {
|
||||
int dowExpected = (day.get(dowField) - 1) % 7 + 1;
|
||||
LocalDate dowDate = day.with(dowField, dowExpected);
|
||||
int dowResult = dowDate.get(dowField);
|
||||
assertEquals(dowResult, dowExpected, "Localized DayOfWeek not correct; " + day + " -->" + dowDate);
|
||||
assertEquals(dowExpected, dowResult, "Localized DayOfWeek not correct; " + day + " -->" + dowDate);
|
||||
|
||||
int weekExpected = day.get(wowbyField) + 1;
|
||||
ValueRange range = day.range(wowbyField);
|
||||
weekExpected = ((weekExpected - 1) % (int)range.getMaximum()) + 1;
|
||||
LocalDate weekDate = day.with(wowbyField, weekExpected);
|
||||
int weekResult = weekDate.get(wowbyField);
|
||||
assertEquals(weekResult, weekExpected, "Localized WeekOfWeekBasedYear not correct; " + day + " -->" + weekDate);
|
||||
assertEquals(weekExpected, weekResult, "Localized WeekOfWeekBasedYear not correct; " + day + " -->" + weekDate);
|
||||
|
||||
int yearExpected = day.get(yowbyField) + 1;
|
||||
|
||||
LocalDate yearDate = day.with(yowbyField, yearExpected);
|
||||
int yearResult = yearDate.get(yowbyField);
|
||||
assertEquals(yearResult, yearExpected, "Localized WeekBasedYear not correct; " + day + " --> " + yearDate);
|
||||
assertEquals(yearExpected, yearResult, "Localized WeekBasedYear not correct; " + day + " --> " + yearDate);
|
||||
|
||||
range = yearDate.range(wowbyField);
|
||||
weekExpected = Math.min(day.get(wowbyField), (int)range.getMaximum());
|
||||
|
||||
int weekActual = yearDate.get(wowbyField);
|
||||
assertEquals(weekActual, weekExpected, "Localized WeekOfWeekBasedYear week should not change; " + day + " --> " + yearDate + ", actual: " + weekActual + ", weekExpected: " + weekExpected);
|
||||
assertEquals(weekExpected, weekActual, "Localized WeekOfWeekBasedYear week should not change; " + day + " --> " + yearDate + ", actual: " + weekActual + ", weekExpected: " + weekExpected);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
@Test(dataProvider="weekFields")
|
||||
@ParameterizedTest
|
||||
@MethodSource("data_weekFields")
|
||||
public void test_parse_resolve_localizedWom(DayOfWeek firstDayOfWeek, int minDays) {
|
||||
LocalDate date = LocalDate.of(2012, 12, 15);
|
||||
WeekFields week = WeekFields.of(firstDayOfWeek, minDays);
|
||||
@ -388,13 +403,14 @@ public class TCKWeekFields extends AbstractTCKTest {
|
||||
String str = date.getYear() + ":" + date.getMonthValue() + ":" +
|
||||
date.get(womField) + ":" + date.get(DAY_OF_WEEK);
|
||||
LocalDate parsed = LocalDate.parse(str, f);
|
||||
assertEquals(parsed, date, " ::" + str + "::" + i);
|
||||
assertEquals(date, parsed, " ::" + str + "::" + i);
|
||||
|
||||
date = date.plusDays(1);
|
||||
}
|
||||
}
|
||||
|
||||
@Test(dataProvider="weekFields")
|
||||
@ParameterizedTest
|
||||
@MethodSource("data_weekFields")
|
||||
public void test_parse_resolve_localizedWom_lenient(DayOfWeek firstDayOfWeek, int minDays) {
|
||||
LocalDate date = LocalDate.of(2012, 12, 15);
|
||||
WeekFields week = WeekFields.of(firstDayOfWeek, minDays);
|
||||
@ -411,14 +427,15 @@ public class TCKWeekFields extends AbstractTCKTest {
|
||||
for (int j = wom - 10; j < wom + 10; j++) {
|
||||
String str = date.getYear() + ":" + date.getMonthValue() + ":" + j + ":" + dow;
|
||||
LocalDate parsed = LocalDate.parse(str, f);
|
||||
assertEquals(parsed, date.plusWeeks(j - wom), " ::" + str + ": :" + i + "::" + j);
|
||||
assertEquals(date.plusWeeks(j - wom), parsed, " ::" + str + ": :" + i + "::" + j);
|
||||
}
|
||||
|
||||
date = date.plusDays(1);
|
||||
}
|
||||
}
|
||||
|
||||
@Test(dataProvider="weekFields")
|
||||
@ParameterizedTest
|
||||
@MethodSource("data_weekFields")
|
||||
public void test_parse_resolve_localizedWom_strict(DayOfWeek firstDayOfWeek, int minDays) {
|
||||
WeekFields week = WeekFields.of(firstDayOfWeek, minDays);
|
||||
TemporalField womField = week.weekOfMonth();
|
||||
@ -430,17 +447,18 @@ public class TCKWeekFields extends AbstractTCKTest {
|
||||
String str = "2012:1:0:1";
|
||||
try {
|
||||
LocalDate date = LocalDate.parse(str, f);
|
||||
assertEquals(date.getYear(), 2012);
|
||||
assertEquals(date.getMonthValue(), 1);
|
||||
assertEquals(date.get(womField), 0);
|
||||
assertEquals(date.get(DAY_OF_WEEK), 1);
|
||||
assertEquals(2012, date.getYear());
|
||||
assertEquals(1, date.getMonthValue());
|
||||
assertEquals(0, date.get(womField));
|
||||
assertEquals(1, date.get(DAY_OF_WEEK));
|
||||
} catch (DateTimeException ex) {
|
||||
// expected
|
||||
}
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
@Test(dataProvider="weekFields")
|
||||
@ParameterizedTest
|
||||
@MethodSource("data_weekFields")
|
||||
public void test_parse_resolve_localizedWomDow(DayOfWeek firstDayOfWeek, int minDays) {
|
||||
LocalDate date = LocalDate.of(2012, 12, 15);
|
||||
WeekFields week = WeekFields.of(firstDayOfWeek, minDays);
|
||||
@ -456,13 +474,14 @@ public class TCKWeekFields extends AbstractTCKTest {
|
||||
String str = date.getYear() + ":" + date.getMonthValue() + ":" +
|
||||
date.get(womField) + ":" + date.get(dowField);
|
||||
LocalDate parsed = LocalDate.parse(str, f);
|
||||
assertEquals(parsed, date, " :: " + str + " " + i);
|
||||
assertEquals(date, parsed, " :: " + str + " " + i);
|
||||
|
||||
date = date.plusDays(1);
|
||||
}
|
||||
}
|
||||
|
||||
@Test(dataProvider="weekFields")
|
||||
@ParameterizedTest
|
||||
@MethodSource("data_weekFields")
|
||||
public void test_parse_resolve_localizedWomDow_lenient(DayOfWeek firstDayOfWeek, int minDays) {
|
||||
LocalDate date = LocalDate.of(2012, 12, 15);
|
||||
WeekFields week = WeekFields.of(firstDayOfWeek, minDays);
|
||||
@ -480,7 +499,7 @@ public class TCKWeekFields extends AbstractTCKTest {
|
||||
for (int j = wom - 10; j < wom + 10; j++) {
|
||||
String str = date.getYear() + ":" + date.getMonthValue() + ":" + j + ":" + dow;
|
||||
LocalDate parsed = LocalDate.parse(str, f);
|
||||
assertEquals(parsed, date.plusWeeks(j - wom), " ::" + str + ": :" + i + "::" + j);
|
||||
assertEquals(date.plusWeeks(j - wom), parsed, " ::" + str + ": :" + i + "::" + j);
|
||||
}
|
||||
|
||||
date = date.plusDays(1);
|
||||
@ -488,7 +507,8 @@ public class TCKWeekFields extends AbstractTCKTest {
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
@Test(dataProvider="weekFields")
|
||||
@ParameterizedTest
|
||||
@MethodSource("data_weekFields")
|
||||
public void test_parse_resolve_localizedWoy(DayOfWeek firstDayOfWeek, int minDays) {
|
||||
LocalDate date = LocalDate.of(2012, 12, 15);
|
||||
WeekFields week = WeekFields.of(firstDayOfWeek, minDays);
|
||||
@ -502,13 +522,14 @@ public class TCKWeekFields extends AbstractTCKTest {
|
||||
String str = date.getYear() + ":" +
|
||||
date.get(woyField) + ":" + date.get(DAY_OF_WEEK);
|
||||
LocalDate parsed = LocalDate.parse(str, f);
|
||||
assertEquals(parsed, date, " :: " + str + " " + i);
|
||||
assertEquals(date, parsed, " :: " + str + " " + i);
|
||||
|
||||
date = date.plusDays(1);
|
||||
}
|
||||
}
|
||||
|
||||
@Test(dataProvider="weekFields")
|
||||
@ParameterizedTest
|
||||
@MethodSource("data_weekFields")
|
||||
public void test_parse_resolve_localizedWoy_lenient(DayOfWeek firstDayOfWeek, int minDays) {
|
||||
LocalDate date = LocalDate.of(2012, 12, 15);
|
||||
WeekFields week = WeekFields.of(firstDayOfWeek, minDays);
|
||||
@ -524,14 +545,15 @@ public class TCKWeekFields extends AbstractTCKTest {
|
||||
for (int j = woy - 60; j < woy + 60; j++) {
|
||||
String str = date.getYear() + ":" + j + ":" + dow;
|
||||
LocalDate parsed = LocalDate.parse(str, f);
|
||||
assertEquals(parsed, date.plusWeeks(j - woy), " ::" + str + ": :" + i + "::" + j);
|
||||
assertEquals(date.plusWeeks(j - woy), parsed, " ::" + str + ": :" + i + "::" + j);
|
||||
}
|
||||
|
||||
date = date.plusDays(1);
|
||||
}
|
||||
}
|
||||
|
||||
@Test(dataProvider="weekFields")
|
||||
@ParameterizedTest
|
||||
@MethodSource("data_weekFields")
|
||||
public void test_parse_resolve_localizedWoy_strict(DayOfWeek firstDayOfWeek, int minDays) {
|
||||
WeekFields week = WeekFields.of(firstDayOfWeek, minDays);
|
||||
TemporalField woyField = week.weekOfYear();
|
||||
@ -542,16 +564,17 @@ public class TCKWeekFields extends AbstractTCKTest {
|
||||
String str = "2012:0:1";
|
||||
try {
|
||||
LocalDate date = LocalDate.parse(str, f);
|
||||
assertEquals(date.getYear(), 2012);
|
||||
assertEquals(date.get(woyField), 0);
|
||||
assertEquals(date.get(DAY_OF_WEEK), 1);
|
||||
assertEquals(2012, date.getYear());
|
||||
assertEquals(0, date.get(woyField));
|
||||
assertEquals(1, date.get(DAY_OF_WEEK));
|
||||
} catch (DateTimeException ex) {
|
||||
// expected
|
||||
}
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
@Test(dataProvider="weekFields")
|
||||
@ParameterizedTest
|
||||
@MethodSource("data_weekFields")
|
||||
public void test_parse_resolve_localizedWoyDow(DayOfWeek firstDayOfWeek, int minDays) {
|
||||
LocalDate date = LocalDate.of(2012, 12, 15);
|
||||
WeekFields week = WeekFields.of(firstDayOfWeek, minDays);
|
||||
@ -567,13 +590,14 @@ public class TCKWeekFields extends AbstractTCKTest {
|
||||
String str = date.getYear() + ":" + date.getMonthValue() + ":" +
|
||||
date.get(woyField) + ":" + date.get(dowField);
|
||||
LocalDate parsed = LocalDate.parse(str, f);
|
||||
assertEquals(parsed, date, " :: " + str + " " + i);
|
||||
assertEquals(date, parsed, " :: " + str + " " + i);
|
||||
|
||||
date = date.plusDays(1);
|
||||
}
|
||||
}
|
||||
|
||||
@Test(dataProvider="weekFields")
|
||||
@ParameterizedTest
|
||||
@MethodSource("data_weekFields")
|
||||
public void test_parse_resolve_localizedWoyDow_lenient(DayOfWeek firstDayOfWeek, int minDays) {
|
||||
LocalDate date = LocalDate.of(2012, 12, 15);
|
||||
WeekFields week = WeekFields.of(firstDayOfWeek, minDays);
|
||||
@ -590,7 +614,7 @@ public class TCKWeekFields extends AbstractTCKTest {
|
||||
for (int j = woy - 60; j < woy + 60; j++) {
|
||||
String str = date.getYear() + ":" + j + ":" + dow;
|
||||
LocalDate parsed = LocalDate.parse(str, f);
|
||||
assertEquals(parsed, date.plusWeeks(j - woy), " ::" + str + ": :" + i + "::" + j);
|
||||
assertEquals(date.plusWeeks(j - woy), parsed, " ::" + str + ": :" + i + "::" + j);
|
||||
}
|
||||
|
||||
date = date.plusDays(1);
|
||||
@ -598,7 +622,8 @@ public class TCKWeekFields extends AbstractTCKTest {
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
@Test(dataProvider="weekFields")
|
||||
@ParameterizedTest
|
||||
@MethodSource("data_weekFields")
|
||||
public void test_parse_resolve_localizedWoWBY(DayOfWeek firstDayOfWeek, int minDays) {
|
||||
LocalDate date = LocalDate.of(2012, 12, 31);
|
||||
WeekFields week = WeekFields.of(firstDayOfWeek, minDays);
|
||||
@ -613,13 +638,14 @@ public class TCKWeekFields extends AbstractTCKTest {
|
||||
String str = date.get(yowbyField) + ":" + date.get(wowbyField) + ":" +
|
||||
date.get(DAY_OF_WEEK);
|
||||
LocalDate parsed = LocalDate.parse(str, f);
|
||||
assertEquals(parsed, date, " :: " + str + " " + i);
|
||||
assertEquals(date, parsed, " :: " + str + " " + i);
|
||||
|
||||
date = date.plusDays(1);
|
||||
}
|
||||
}
|
||||
|
||||
@Test(dataProvider="weekFields")
|
||||
@ParameterizedTest
|
||||
@MethodSource("data_weekFields")
|
||||
public void test_parse_resolve_localizedWoWBY_lenient(DayOfWeek firstDayOfWeek, int minDays) {
|
||||
LocalDate date = LocalDate.of(2012, 12, 31);
|
||||
WeekFields week = WeekFields.of(firstDayOfWeek, minDays);
|
||||
@ -636,14 +662,15 @@ public class TCKWeekFields extends AbstractTCKTest {
|
||||
for (int j = wowby - 60; j < wowby + 60; j++) {
|
||||
String str = date.get(yowbyField) + ":" + j + ":" + dow;
|
||||
LocalDate parsed = LocalDate.parse(str, f);
|
||||
assertEquals(parsed, date.plusWeeks(j - wowby), " ::" + str + ": :" + i + "::" + j);
|
||||
assertEquals(date.plusWeeks(j - wowby), parsed, " ::" + str + ": :" + i + "::" + j);
|
||||
}
|
||||
|
||||
date = date.plusDays(1);
|
||||
}
|
||||
}
|
||||
|
||||
@Test(dataProvider="weekFields")
|
||||
@ParameterizedTest
|
||||
@MethodSource("data_weekFields")
|
||||
public void test_parse_resolve_localizedWoWBY_strict(DayOfWeek firstDayOfWeek, int minDays) {
|
||||
WeekFields week = WeekFields.of(firstDayOfWeek, minDays);
|
||||
TemporalField wowbyField = week.weekOfWeekBasedYear();
|
||||
@ -655,16 +682,17 @@ public class TCKWeekFields extends AbstractTCKTest {
|
||||
String str = "2012:0:1";
|
||||
try {
|
||||
LocalDate date = LocalDate.parse(str, f);
|
||||
assertEquals(date.get(yowbyField), 2012);
|
||||
assertEquals(date.get(wowbyField), 0);
|
||||
assertEquals(date.get(DAY_OF_WEEK), 1);
|
||||
assertEquals(2012, date.get(yowbyField));
|
||||
assertEquals(0, date.get(wowbyField));
|
||||
assertEquals(1, date.get(DAY_OF_WEEK));
|
||||
} catch (DateTimeException ex) {
|
||||
// expected
|
||||
}
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
@Test(dataProvider="weekFields")
|
||||
@ParameterizedTest
|
||||
@MethodSource("data_weekFields")
|
||||
public void test_parse_resolve_localizedWoWBYDow(DayOfWeek firstDayOfWeek, int minDays) {
|
||||
LocalDate date = LocalDate.of(2012, 12, 31);
|
||||
WeekFields week = WeekFields.of(firstDayOfWeek, minDays);
|
||||
@ -680,13 +708,14 @@ public class TCKWeekFields extends AbstractTCKTest {
|
||||
String str = date.get(yowbyField) + ":" + date.get(wowbyField) + ":" +
|
||||
date.get(dowField);
|
||||
LocalDate parsed = LocalDate.parse(str, f);
|
||||
assertEquals(parsed, date, " :: " + str + " " + i);
|
||||
assertEquals(date, parsed, " :: " + str + " " + i);
|
||||
|
||||
date = date.plusDays(1);
|
||||
}
|
||||
}
|
||||
|
||||
@Test(dataProvider="weekFields")
|
||||
@ParameterizedTest
|
||||
@MethodSource("data_weekFields")
|
||||
public void test_parse_resolve_localizedWoWBYDow_lenient(DayOfWeek firstDayOfWeek, int minDays) {
|
||||
LocalDate date = LocalDate.of(2012, 12, 31);
|
||||
WeekFields week = WeekFields.of(firstDayOfWeek, minDays);
|
||||
@ -704,7 +733,7 @@ public class TCKWeekFields extends AbstractTCKTest {
|
||||
for (int j = wowby - 60; j < wowby + 60; j++) {
|
||||
String str = date.get(yowbyField) + ":" + j + ":" + dow;
|
||||
LocalDate parsed = LocalDate.parse(str, f);
|
||||
assertEquals(parsed, date.plusWeeks(j - wowby), " ::" + str + ": :" + i + "::" + j);
|
||||
assertEquals(date.plusWeeks(j - wowby), parsed, " ::" + str + ": :" + i + "::" + j);
|
||||
}
|
||||
|
||||
date = date.plusDays(1);
|
||||
@ -713,7 +742,6 @@ public class TCKWeekFields extends AbstractTCKTest {
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
@DataProvider(name="weekFields")
|
||||
Object[][] data_weekFields() {
|
||||
Object[][] objects = new Object[49][];
|
||||
int i = 0;
|
||||
@ -726,7 +754,6 @@ public class TCKWeekFields extends AbstractTCKTest {
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
@DataProvider(name="WeekBasedYearData")
|
||||
Object[][] provider_WeekBasedYearData() {
|
||||
return new Object[][] {
|
||||
{WeekFields.of(DayOfWeek.SUNDAY, 1), 2008, 52, 7, LocalDate.of(2008, 12, 27)},
|
||||
@ -741,20 +768,20 @@ public class TCKWeekFields extends AbstractTCKTest {
|
||||
};
|
||||
}
|
||||
|
||||
@Test(dataProvider="WeekBasedYearData")
|
||||
@ParameterizedTest
|
||||
@MethodSource("provider_WeekBasedYearData")
|
||||
public void test_weekBasedYears(WeekFields weekDef, int weekBasedYear,
|
||||
int weekOfWeekBasedYear, int dayOfWeek, LocalDate date) {
|
||||
TemporalField dowField = weekDef.dayOfWeek();
|
||||
TemporalField wowbyField = weekDef.weekOfWeekBasedYear();
|
||||
TemporalField yowbyField = weekDef.weekBasedYear();
|
||||
assertEquals(date.get(dowField), dayOfWeek, "DayOfWeek mismatch");
|
||||
assertEquals(date.get(wowbyField), weekOfWeekBasedYear, "Week of WeekBasedYear mismatch");
|
||||
assertEquals(date.get(yowbyField), weekBasedYear, "Year of WeekBasedYear mismatch");
|
||||
assertEquals(dayOfWeek, date.get(dowField), "DayOfWeek mismatch");
|
||||
assertEquals(weekOfWeekBasedYear, date.get(wowbyField), "Week of WeekBasedYear mismatch");
|
||||
assertEquals(weekBasedYear, date.get(yowbyField), "Year of WeekBasedYear mismatch");
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
@DataProvider(name="IsoWeekData")
|
||||
Object[][] data_week() {
|
||||
return new Object[][] {
|
||||
{LocalDate.of(1969, 12, 29), DayOfWeek.MONDAY, 1, 1970},
|
||||
@ -776,16 +803,17 @@ public class TCKWeekFields extends AbstractTCKTest {
|
||||
// WEEK_OF_WEEK_BASED_YEAR
|
||||
// Validate with the same data used by IsoFields.
|
||||
//-----------------------------------------------------------------------
|
||||
@Test(dataProvider="IsoWeekData")
|
||||
@ParameterizedTest
|
||||
@MethodSource("data_week")
|
||||
public void test_WOWBY(LocalDate date, DayOfWeek dow, int week, int wby) {
|
||||
WeekFields weekDef = WeekFields.ISO;
|
||||
TemporalField dowField = weekDef.dayOfWeek();
|
||||
TemporalField wowbyField = weekDef.weekOfWeekBasedYear();
|
||||
TemporalField yowbyField = weekDef.weekBasedYear();
|
||||
|
||||
assertEquals(date.get(dowField), dow.getValue());
|
||||
assertEquals(date.get(wowbyField), week);
|
||||
assertEquals(date.get(yowbyField), wby);
|
||||
assertEquals(dow.getValue(), date.get(dowField));
|
||||
assertEquals(week, date.get(wowbyField));
|
||||
assertEquals(wby, date.get(yowbyField));
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
@ -798,11 +826,11 @@ public class TCKWeekFields extends AbstractTCKTest {
|
||||
|
||||
assertTrue(weekDef_iso.equals(WeekFields.of(DayOfWeek.MONDAY, 4)));
|
||||
assertTrue(weekDef_sundayStart.equals(WeekFields.of(DayOfWeek.SUNDAY, 1)));
|
||||
assertEquals(weekDef_iso.hashCode(), WeekFields.of(DayOfWeek.MONDAY, 4).hashCode());
|
||||
assertEquals(weekDef_sundayStart.hashCode(), WeekFields.of(DayOfWeek.SUNDAY, 1).hashCode());
|
||||
assertEquals(WeekFields.of(DayOfWeek.MONDAY, 4).hashCode(), weekDef_iso.hashCode());
|
||||
assertEquals(WeekFields.of(DayOfWeek.SUNDAY, 1).hashCode(), weekDef_sundayStart.hashCode());
|
||||
|
||||
assertFalse(weekDef_iso.equals(weekDef_sundayStart));
|
||||
assertNotEquals(weekDef_iso.hashCode(), weekDef_sundayStart.hashCode());
|
||||
assertNotEquals(weekDef_sundayStart.hashCode(), weekDef_iso.hashCode());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2012, 2013, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2012, 2025, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
@ -86,21 +86,21 @@ import static java.time.temporal.ChronoField.ERA;
|
||||
import java.io.IOException;
|
||||
import java.time.temporal.ChronoField;
|
||||
|
||||
import org.testng.annotations.DataProvider;
|
||||
import org.testng.annotations.Test;
|
||||
import org.junit.jupiter.api.TestInstance;
|
||||
import org.junit.jupiter.params.ParameterizedTest;
|
||||
import org.junit.jupiter.params.provider.MethodSource;
|
||||
|
||||
import tck.java.time.AbstractTCKTest;
|
||||
|
||||
/**
|
||||
* Test serialization of ChronoField.
|
||||
*/
|
||||
@Test
|
||||
@TestInstance(TestInstance.Lifecycle.PER_CLASS)
|
||||
public class TCKChronoFieldSerialization extends AbstractTCKTest {
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
// List of Fields
|
||||
//-----------------------------------------------------------------------
|
||||
@DataProvider(name="fieldBased")
|
||||
Object[][] data_fieldBased() {
|
||||
return new Object[][] {
|
||||
{DAY_OF_WEEK},
|
||||
@ -135,7 +135,8 @@ public class TCKChronoFieldSerialization extends AbstractTCKTest {
|
||||
};
|
||||
}
|
||||
|
||||
@Test(dataProvider = "fieldBased")
|
||||
@ParameterizedTest
|
||||
@MethodSource("data_fieldBased")
|
||||
public void test_fieldSerializable(ChronoField field) throws IOException, ClassNotFoundException {
|
||||
assertSerializableSame(field);
|
||||
}
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2012, 2013, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2012, 2025, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
@ -74,21 +74,21 @@ import static java.time.temporal.ChronoUnit.YEARS;
|
||||
import java.io.IOException;
|
||||
import java.time.temporal.ChronoUnit;
|
||||
|
||||
import org.testng.annotations.DataProvider;
|
||||
import org.testng.annotations.Test;
|
||||
import org.junit.jupiter.api.TestInstance;
|
||||
import org.junit.jupiter.params.ParameterizedTest;
|
||||
import org.junit.jupiter.params.provider.MethodSource;
|
||||
|
||||
import tck.java.time.AbstractTCKTest;
|
||||
|
||||
/**
|
||||
* Test.
|
||||
*/
|
||||
@Test
|
||||
@TestInstance(TestInstance.Lifecycle.PER_CLASS)
|
||||
public class TCKChronoUnitSerialization extends AbstractTCKTest {
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
// ChronoUnits
|
||||
//-----------------------------------------------------------------------
|
||||
@DataProvider(name="chronoUnit")
|
||||
Object[][] data_chronoUnit() {
|
||||
return new Object[][] {
|
||||
{FOREVER},
|
||||
@ -112,7 +112,8 @@ public class TCKChronoUnitSerialization extends AbstractTCKTest {
|
||||
};
|
||||
}
|
||||
|
||||
@Test(dataProvider = "chronoUnit")
|
||||
@ParameterizedTest
|
||||
@MethodSource("data_chronoUnit")
|
||||
public void test_unitType(ChronoUnit unit) throws IOException, ClassNotFoundException {
|
||||
assertSerializableSame(unit);
|
||||
}
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2012, 2013, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2012, 2025, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
@ -63,19 +63,19 @@ import java.io.IOException;
|
||||
import java.time.temporal.JulianFields;
|
||||
import java.time.temporal.TemporalField;
|
||||
|
||||
import org.testng.annotations.DataProvider;
|
||||
import org.testng.annotations.Test;
|
||||
import org.junit.jupiter.api.TestInstance;
|
||||
import org.junit.jupiter.params.ParameterizedTest;
|
||||
import org.junit.jupiter.params.provider.MethodSource;
|
||||
|
||||
import tck.java.time.AbstractTCKTest;
|
||||
|
||||
/**
|
||||
* Test serialization of JulianFields
|
||||
*/
|
||||
@Test
|
||||
@TestInstance(TestInstance.Lifecycle.PER_CLASS)
|
||||
public class TCKJulianFieldsSerialization extends AbstractTCKTest {
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
@DataProvider(name="julian_fields")
|
||||
Object[][] julian_samples() {
|
||||
return new Object[][] {
|
||||
{JulianFields.JULIAN_DAY},
|
||||
@ -86,7 +86,8 @@ public class TCKJulianFieldsSerialization extends AbstractTCKTest {
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
@Test(dataProvider="julian_fields")
|
||||
@ParameterizedTest
|
||||
@MethodSource("julian_samples")
|
||||
public void test_serializable(TemporalField field) throws IOException, ClassNotFoundException {
|
||||
assertSerializable(field);
|
||||
}
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2012, 2013, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2012, 2025, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
@ -59,8 +59,7 @@
|
||||
*/
|
||||
package tck.java.time.temporal.serial;
|
||||
|
||||
import static org.testng.Assert.assertEquals;
|
||||
import static org.testng.Assert.fail;
|
||||
import static org.junit.jupiter.api.Assertions.fail;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
@ -71,19 +70,20 @@ import java.io.ObjectOutputStream;
|
||||
import java.time.temporal.ValueRange;
|
||||
import java.util.Arrays;
|
||||
|
||||
import org.testng.annotations.Test;
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import tck.java.time.AbstractTCKTest;
|
||||
|
||||
/**
|
||||
* Test serialization of ValueRange.
|
||||
*/
|
||||
@Test
|
||||
public class TCKValueRangeSerialization extends AbstractTCKTest {
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
// Serialization
|
||||
//-----------------------------------------------------------------------
|
||||
@Test
|
||||
public void test_serialization() throws Exception {
|
||||
ValueRange range = ValueRange.of(1, 2, 3, 4);
|
||||
assertSerializable(range);
|
||||
@ -94,6 +94,7 @@ public class TCKValueRangeSerialization extends AbstractTCKTest {
|
||||
* Verify Serialized bytes of a ValueRange.
|
||||
* @throws IOException if thrown during serialization is an unexpected test tailure
|
||||
*/
|
||||
@Test
|
||||
public void test_valueRangeSerialized() throws IOException {
|
||||
byte[] expected = {
|
||||
(byte)172, (byte)237, 0, 5, 115, 114, 0, 29, 106, 97, /* \u00ac \u00ed \u0000 \u0005 s r \u0000 \u001d j a */
|
||||
@ -118,7 +119,7 @@ public class TCKValueRangeSerialization extends AbstractTCKTest {
|
||||
oos.writeObject(range);
|
||||
|
||||
byte[] actual = baos.toByteArray();
|
||||
assertEquals(actual, expected, "Serialized bytes incorrect");
|
||||
Assertions.assertArrayEquals(expected, actual, "Serialized bytes incorrect");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Loading…
x
Reference in New Issue
Block a user