@ -11,7 +11,9 @@ import static com.google.common.truth.Truth.assertThat;
import static com.google.protobuf.util.DurationsTest.duration ;
import static com.google.protobuf.util.DurationsTest.duration ;
import static org.junit.Assert.fail ;
import static org.junit.Assert.fail ;
import com.google.common.annotations.GwtIncompatible ;
import com.google.common.collect.Lists ;
import com.google.common.collect.Lists ;
import com.google.j2objc.annotations.J2ObjCIncompatible ;
import com.google.protobuf.Duration ;
import com.google.protobuf.Duration ;
import com.google.protobuf.Timestamp ;
import com.google.protobuf.Timestamp ;
import java.text.ParseException ;
import java.text.ParseException ;
@ -51,6 +53,8 @@ public class TimestampsTest {
Timestamp . newBuilder ( ) . setSeconds ( Long . MIN_VALUE ) . setNanos ( Integer . MIN_VALUE ) . build ( ) ;
Timestamp . newBuilder ( ) . setSeconds ( Long . MIN_VALUE ) . setNanos ( Integer . MIN_VALUE ) . build ( ) ;
@Test
@Test
@GwtIncompatible ( "Uses reflection to access methods of java.time.Instant" )
@J2ObjCIncompatible
public void testNow ( ) {
public void testNow ( ) {
Timestamp now = Timestamps . now ( ) ;
Timestamp now = Timestamps . now ( ) ;
long epochSeconds = System . currentTimeMillis ( ) / 1000 ;
long epochSeconds = System . currentTimeMillis ( ) / 1000 ;
@ -59,6 +63,8 @@ public class TimestampsTest {
}
}
@Test
@Test
@GwtIncompatible ( "Uses reflection to access methods of java.time.Instant" )
@J2ObjCIncompatible
public void testNowWithSubMillisecondPrecision ( ) {
public void testNowWithSubMillisecondPrecision ( ) {
try {
try {
// throws if we're not on Java9+
// throws if we're not on Java9+
@ -110,6 +116,8 @@ public class TimestampsTest {
}
}
@Test
@Test
@GwtIncompatible ( "Depends on String.format which is not supported in Xplat." )
@J2ObjCIncompatible
public void testTimestampStringFormat ( ) throws Exception {
public void testTimestampStringFormat ( ) throws Exception {
Timestamp start = Timestamps . parse ( "0001-01-01T00:00:00Z" ) ;
Timestamp start = Timestamps . parse ( "0001-01-01T00:00:00Z" ) ;
Timestamp end = Timestamps . parse ( "9999-12-31T23:59:59.999999999Z" ) ;
Timestamp end = Timestamps . parse ( "9999-12-31T23:59:59.999999999Z" ) ;
@ -159,6 +167,8 @@ public class TimestampsTest {
private volatile boolean stopParsingThreads = false ;
private volatile boolean stopParsingThreads = false ;
private volatile String errorMessage = "" ;
private volatile String errorMessage = "" ;
@GwtIncompatible ( "ParseException is not supported in Xplat" )
@J2ObjCIncompatible
private class ParseTimestampThread extends Thread {
private class ParseTimestampThread extends Thread {
private final String [ ] strings ;
private final String [ ] strings ;
private final Timestamp [ ] values ;
private final Timestamp [ ] values ;
@ -192,6 +202,8 @@ public class TimestampsTest {
}
}
@Test
@Test
@GwtIncompatible ( "ParseException is not supported in Xplat" )
@J2ObjCIncompatible
public void testTimestampConcurrentParsing ( ) throws Exception {
public void testTimestampConcurrentParsing ( ) throws Exception {
String [ ] timestampStrings =
String [ ] timestampStrings =
new String [ ] {
new String [ ] {
@ -225,6 +237,8 @@ public class TimestampsTest {
}
}
@Test
@Test
@GwtIncompatible ( "Depends on String.format which is not supported in Xplat." )
@J2ObjCIncompatible
public void testTimestampInvalidFormatValueTooSmall ( ) throws Exception {
public void testTimestampInvalidFormatValueTooSmall ( ) throws Exception {
try {
try {
// Value too small.
// Value too small.
@ -237,6 +251,8 @@ public class TimestampsTest {
}
}
@Test
@Test
@GwtIncompatible ( "Depends on String.format which is not supported in Xplat." )
@J2ObjCIncompatible
public void testTimestampInvalidFormatValueTooLarge ( ) throws Exception {
public void testTimestampInvalidFormatValueTooLarge ( ) throws Exception {
try {
try {
// Value too large.
// Value too large.
@ -249,6 +265,8 @@ public class TimestampsTest {
}
}
@Test
@Test
@GwtIncompatible ( "Depends on String.format which is not supported in Xplat." )
@J2ObjCIncompatible
public void testTimestampInvalidFormatNanosTooSmall ( ) throws Exception {
public void testTimestampInvalidFormatNanosTooSmall ( ) throws Exception {
try {
try {
// Invalid nanos value.
// Invalid nanos value.
@ -260,6 +278,8 @@ public class TimestampsTest {
}
}
@Test
@Test
@GwtIncompatible ( "Depends on String.format which is not supported in Xplat." )
@J2ObjCIncompatible
public void testTimestampInvalidFormatNanosTooLarge ( ) throws Exception {
public void testTimestampInvalidFormatNanosTooLarge ( ) throws Exception {
try {
try {
// Invalid nanos value.
// Invalid nanos value.
@ -271,6 +291,8 @@ public class TimestampsTest {
}
}
@Test
@Test
@GwtIncompatible ( "ParseException is not supported in Xplat" )
@J2ObjCIncompatible
public void testTimestampInvalidFormatDateTooSmall ( ) {
public void testTimestampInvalidFormatDateTooSmall ( ) {
try {
try {
Timestamps . parse ( "0000-01-01T00:00:00Z" ) ;
Timestamps . parse ( "0000-01-01T00:00:00Z" ) ;
@ -288,6 +310,8 @@ public class TimestampsTest {
}
}
@Test
@Test
@GwtIncompatible ( "ParseException is not supported in Xplat" )
@J2ObjCIncompatible
public void testTimestampInvalidFormatDateTooLarge ( ) {
public void testTimestampInvalidFormatDateTooLarge ( ) {
try {
try {
Timestamps . parse ( "10000-01-01T00:00:00Z" ) ;
Timestamps . parse ( "10000-01-01T00:00:00Z" ) ;
@ -304,6 +328,8 @@ public class TimestampsTest {
}
}
@Test
@Test
@GwtIncompatible ( "ParseException is not supported in Xplat" )
@J2ObjCIncompatible
public void testTimestampInvalidFormatMissingT ( ) {
public void testTimestampInvalidFormatMissingT ( ) {
try {
try {
Timestamps . parse ( "1970-01-01 00:00:00Z" ) ;
Timestamps . parse ( "1970-01-01 00:00:00Z" ) ;
@ -320,6 +346,8 @@ public class TimestampsTest {
}
}
@Test
@Test
@GwtIncompatible ( "ParseException is not supported in Xplat" )
@J2ObjCIncompatible
public void testTimestampInvalidFormatMissingZ ( ) {
public void testTimestampInvalidFormatMissingZ ( ) {
try {
try {
Timestamps . parse ( "1970-01-01T00:00:00" ) ;
Timestamps . parse ( "1970-01-01T00:00:00" ) ;
@ -336,6 +364,8 @@ public class TimestampsTest {
}
}
@Test
@Test
@GwtIncompatible ( "ParseException is not supported in Xplat" )
@J2ObjCIncompatible
public void testTimestampInvalidOffset ( ) {
public void testTimestampInvalidOffset ( ) {
try {
try {
Timestamps . parse ( "1970-01-01T00:00:00+0000" ) ;
Timestamps . parse ( "1970-01-01T00:00:00+0000" ) ;
@ -352,6 +382,8 @@ public class TimestampsTest {
}
}
@Test
@Test
@GwtIncompatible ( "ParseException is not supported in Xplat" )
@J2ObjCIncompatible
public void testTimestampInvalidOffsetWithDot ( ) {
public void testTimestampInvalidOffsetWithDot ( ) {
try {
try {
Timestamps . parse ( "2021-08-19T10:24:25-07.:00" ) ;
Timestamps . parse ( "2021-08-19T10:24:25-07.:00" ) ;
@ -368,6 +400,8 @@ public class TimestampsTest {
}
}
@Test
@Test
@GwtIncompatible ( "ParseException is not supported in Xplat" )
@J2ObjCIncompatible
public void testTimestampInvalidTrailingText ( ) {
public void testTimestampInvalidTrailingText ( ) {
try {
try {
Timestamps . parse ( "1970-01-01T00:00:00Z0" ) ;
Timestamps . parse ( "1970-01-01T00:00:00Z0" ) ;
@ -384,6 +418,8 @@ public class TimestampsTest {
}
}
@Test
@Test
@GwtIncompatible ( "ParseException is not supported in Xplat" )
@J2ObjCIncompatible
public void testTimestampInvalidNanoSecond ( ) {
public void testTimestampInvalidNanoSecond ( ) {
try {
try {
Timestamps . parse ( "1970-01-01T00:00:00.ABCZ" ) ;
Timestamps . parse ( "1970-01-01T00:00:00.ABCZ" ) ;
@ -400,6 +436,8 @@ public class TimestampsTest {
}
}
@Test
@Test
@GwtIncompatible ( "Depends on String.format which is not supported in Xplat." )
@J2ObjCIncompatible
public void testTimestampConversion ( ) throws Exception {
public void testTimestampConversion ( ) throws Exception {
Timestamp timestamp = Timestamps . parse ( "1970-01-01T00:00:01.111111111Z" ) ;
Timestamp timestamp = Timestamps . parse ( "1970-01-01T00:00:01.111111111Z" ) ;
assertThat ( Timestamps . toNanos ( timestamp ) ) . isEqualTo ( 1111111111 ) ;
assertThat ( Timestamps . toNanos ( timestamp ) ) . isEqualTo ( 1111111111 ) ;
@ -431,6 +469,8 @@ public class TimestampsTest {
}
}
@Test
@Test
@GwtIncompatible ( "Depends on String.format which is not supported in Xplat." )
@J2ObjCIncompatible
public void testFromDate ( ) {
public void testFromDate ( ) {
Date date = new Date ( 1111 ) ;
Date date = new Date ( 1111 ) ;
Timestamp timestamp = Timestamps . fromDate ( date ) ;
Timestamp timestamp = Timestamps . fromDate ( date ) ;
@ -438,6 +478,8 @@ public class TimestampsTest {
}
}
@Test
@Test
@GwtIncompatible ( "Calendar is not supported in non JVM java.time" )
@J2ObjCIncompatible
public void testFromDate_after9999CE ( ) {
public void testFromDate_after9999CE ( ) {
// protobuf still requires Java 7 so no java.time :-(
// protobuf still requires Java 7 so no java.time :-(
Calendar calendar = Calendar . getInstance ( ) ;
Calendar calendar = Calendar . getInstance ( ) ;
@ -454,6 +496,8 @@ public class TimestampsTest {
}
}
@Test
@Test
@GwtIncompatible ( "Calendar is not supported in non JVM java.time" )
@J2ObjCIncompatible
public void testFromDate_beforeYear1 ( ) {
public void testFromDate_beforeYear1 ( ) {
// protobuf still requires Java 7 so no java.time :-(
// protobuf still requires Java 7 so no java.time :-(
Calendar calendar = Calendar . getInstance ( ) ;
Calendar calendar = Calendar . getInstance ( ) ;
@ -470,6 +514,8 @@ public class TimestampsTest {
}
}
@Test
@Test
@GwtIncompatible ( "Calendar is not supported in non JVM java.time" )
@J2ObjCIncompatible
public void testFromDate_after2262CE ( ) {
public void testFromDate_after2262CE ( ) {
// protobuf still requires Java 7 so no java.time :-(
// protobuf still requires Java 7 so no java.time :-(
Calendar calendar = Calendar . getInstance ( ) ;
Calendar calendar = Calendar . getInstance ( ) ;
@ -484,6 +530,8 @@ public class TimestampsTest {
/ * Timestamp only stores integral seconds in the Date parent class and stores the nanosecond
/ * Timestamp only stores integral seconds in the Date parent class and stores the nanosecond
* adjustment in the Timestamp class . * /
* adjustment in the Timestamp class . * /
@Test
@Test
@GwtIncompatible ( "Depends on String.format which is not supported in Xplat." )
@J2ObjCIncompatible
public void testFromSqlTimestampSubMillisecondPrecision ( ) {
public void testFromSqlTimestampSubMillisecondPrecision ( ) {
java . sql . Timestamp sqlTimestamp = new java . sql . Timestamp ( 1111 ) ;
java . sql . Timestamp sqlTimestamp = new java . sql . Timestamp ( 1111 ) ;
sqlTimestamp . setNanos ( sqlTimestamp . getNanos ( ) + 234567 ) ;
sqlTimestamp . setNanos ( sqlTimestamp . getNanos ( ) + 234567 ) ;
@ -492,6 +540,8 @@ public class TimestampsTest {
}
}
@Test
@Test
@GwtIncompatible ( "Depends on String.format which is not supported in Xplat." )
@J2ObjCIncompatible
public void testFromSqlTimestamp ( ) {
public void testFromSqlTimestamp ( ) {
Date date = new java . sql . Timestamp ( 1111 ) ;
Date date = new java . sql . Timestamp ( 1111 ) ;
Timestamp timestamp = Timestamps . fromDate ( date ) ;
Timestamp timestamp = Timestamps . fromDate ( date ) ;
@ -499,6 +549,8 @@ public class TimestampsTest {
}
}
@Test
@Test
@GwtIncompatible ( "Depends on String.format which is not supported in Xplat." )
@J2ObjCIncompatible
public void testFromSqlTimestamp_beforeEpoch ( ) {
public void testFromSqlTimestamp_beforeEpoch ( ) {
Date date = new java . sql . Timestamp ( - 1111 ) ;
Date date = new java . sql . Timestamp ( - 1111 ) ;
Timestamp timestamp = Timestamps . fromDate ( date ) ;
Timestamp timestamp = Timestamps . fromDate ( date ) ;
@ -506,6 +558,8 @@ public class TimestampsTest {
}
}
@Test
@Test
@GwtIncompatible ( "Depends on String.format which is not supported in Xplat." )
@J2ObjCIncompatible
public void testFromSqlTimestamp_beforeEpochWholeSecond ( ) {
public void testFromSqlTimestamp_beforeEpochWholeSecond ( ) {
Date date = new java . sql . Timestamp ( - 2000 ) ;
Date date = new java . sql . Timestamp ( - 2000 ) ;
Timestamp timestamp = Timestamps . fromDate ( date ) ;
Timestamp timestamp = Timestamps . fromDate ( date ) ;
@ -513,6 +567,8 @@ public class TimestampsTest {
}
}
@Test
@Test
@GwtIncompatible ( "ParseException is not supported in Xplat" )
@J2ObjCIncompatible
public void testTimeOperations ( ) throws Exception {
public void testTimeOperations ( ) throws Exception {
Timestamp start = Timestamps . parse ( "0001-01-01T00:00:00Z" ) ;
Timestamp start = Timestamps . parse ( "0001-01-01T00:00:00Z" ) ;
Timestamp end = Timestamps . parse ( "9999-12-31T23:59:59.999999999Z" ) ;
Timestamp end = Timestamps . parse ( "9999-12-31T23:59:59.999999999Z" ) ;
@ -603,6 +659,8 @@ public class TimestampsTest {
}
}
@Test
@Test
@GwtIncompatible ( "ParseException is not supported in Xplat" )
@J2ObjCIncompatible
public void testOverflowsArithmeticException ( ) throws Exception {
public void testOverflowsArithmeticException ( ) throws Exception {
try {
try {
Timestamps . toNanos ( Timestamps . parse ( "9999-12-31T23:59:59.999999999Z" ) ) ;
Timestamps . toNanos ( Timestamps . parse ( "9999-12-31T23:59:59.999999999Z" ) ) ;
@ -702,6 +760,8 @@ public class TimestampsTest {
}
}
@Test
@Test
@GwtIncompatible ( "Depends on String.format which is not supported in Xplat." )
@J2ObjCIncompatible
public void testMaxNanosecondsConversion ( ) {
public void testMaxNanosecondsConversion ( ) {
assertThat ( Timestamps . toString ( Timestamps . fromNanos ( Long . MAX_VALUE ) ) )
assertThat ( Timestamps . toString ( Timestamps . fromNanos ( Long . MAX_VALUE ) ) )
. isEqualTo ( "2262-04-11T23:47:16.854775807Z" ) ;
. isEqualTo ( "2262-04-11T23:47:16.854775807Z" ) ;
@ -726,6 +786,8 @@ public class TimestampsTest {
}
}
@Test
@Test
@GwtIncompatible ( "Depends on String.format which is not supported in Xplat." )
@J2ObjCIncompatible
public void testMinNanosecondsConversion ( ) {
public void testMinNanosecondsConversion ( ) {
assertThat ( Timestamps . toString ( Timestamps . fromNanos ( Long . MIN_VALUE ) ) )
assertThat ( Timestamps . toString ( Timestamps . fromNanos ( Long . MIN_VALUE ) ) )
. isEqualTo ( "1677-09-21T00:12:43.145224192Z" ) ;
. isEqualTo ( "1677-09-21T00:12:43.145224192Z" ) ;