summaryrefslogtreecommitdiff
path: root/sql/src/test/java/org/apache/harmony/sql/tests/java/sql/TimestampTest.java
blob: bac077aee8e7f12c616077a7f1126bdb964a1737 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
/* 
 * Licensed to the Apache Software Foundation (ASF) under one or more
 * contributor license agreements.  See the NOTICE file distributed with
 * this work for additional information regarding copyright ownership.
 * The ASF licenses this file to You under the Apache License, Version 2.0
 * (the "License"); you may not use this file except in compliance with
 * the License.  You may obtain a copy of the License at
 * 
 *     http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package org.apache.harmony.sql.tests.java.sql;

import java.sql.Timestamp;
import java.util.Date;
import java.util.TimeZone;

import junit.framework.TestCase;

import org.apache.harmony.testframework.serialization.SerializationTest;

/**
 * JUnit Testcase for the java.sql.Timestamp class
 */

public class TimestampTest extends TestCase {

    static class MockTimestamp extends Timestamp {
        private String holiday;

        public MockTimestamp(long theTime) {
            super(theTime);
            holiday = "Christmas";
        }

        // Constructor should not call this public API,
        // since it may be overrided to use variables uninitialized.
        public void setTime(long theTime) {
            super.setTime(theTime);
            holiday.hashCode();
        }
    }

    static long TIME_TEST1 = 38720231; // 10:45:20.231 GMT

    static long TIME_TEST2 = 80279000; // 22:17:59.000 GMT

    static long TIME_TEST3 = -38720691; // 13:14:39.309 GMT

    static long TIME_COMPARE = 123498845;

    static long TIME_EARLY = -2347889122L;// A time well before the Epoch

    static long TIME_LATE = 2347889122L; // A time well after the Epoch

    static String STRING_TEST1 = "1970-01-01 10:45:20.231"; // "1970-01-01

    // 10:45:20.231000000";

    static String STRING_TEST2 = "1970-01-01 22:17:59.0"; // "1970-01-01

    // 22:17:59.000000000";

    static String STRING_TEST3 = "1969-12-31 13:14:39.309"; // "1969-12-31

    // 13:14:39.309000000";

    static String STRING_INVALID1 = "ABCDEFGHI";

    static String STRING_INVALID2 = "233104";

    static String STRING_INVALID3 = "21-43-48";

    // A timepoint in the correct format but with numeric values out of range.
    static String STRING_INVALID_OUTRANGE = "2999-15-99 35:99:66.875";

    static long[] TIME_ARRAY = { TIME_TEST1, TIME_TEST2, TIME_TEST3 };

    static int[] YEAR_ARRAY = { 70, 70, 69 };

    static int[] MONTH_ARRAY = { 0, 0, 11 };

    static int[] DATE_ARRAY = { 1, 1, 31 };

    static int[] HOURS_ARRAY = { 10, 22, 13 };

    static int[] MINUTES_ARRAY = { 45, 17, 14 };

    static int[] SECONDS_ARRAY = { 20, 59, 39 };

    static int[] NANOS_ARRAY = { 231000000, 000000000, 309000000 };

    static int[] NANOS_ARRAY2 = { 137891990, 635665198, 109985421 };

    static String[] STRING_NANOS_ARRAY = { "1970-01-01 10:45:20.13789199",
            "1970-01-01 22:17:59.635665198", "1969-12-31 13:14:39.109985421" };

    static String[] STRING_GMT_ARRAY = { STRING_TEST1, STRING_TEST2,
            STRING_TEST3 };

    static String[] STRING_LA_ARRAY = { "02:45:20", "14:17:59", "05:14:40" };

    static String[] STRING_JP_ARRAY = { "19:45:20", "07:17:59", "22:14:40" };

    static String[] INVALID_STRINGS = { STRING_INVALID1, STRING_INVALID2,
            STRING_INVALID3, STRING_INVALID_OUTRANGE };

    // Timezones
    static String TZ_LONDON = "GMT"; // GMT (!) PS London != GMT (?!?)

    static String TZ_PACIFIC = "America/Los_Angeles"; // GMT - 8

    static String TZ_JAPAN = "Asia/Tokyo"; // GMT + 9

    static String[] TIMEZONES = { TZ_LONDON, TZ_PACIFIC, TZ_JAPAN };

    static String[][] STRING_ARRAYS = { STRING_GMT_ARRAY, STRING_LA_ARRAY,
            STRING_JP_ARRAY };

    // Test ToString
    static String[][] STRING_TIMESTAMP_ARRAYS = {
            STRING_GMT_ARRAY,
            new String[] { "1970-01-01 02:45:20.231", "1970-01-01 14:17:59.0",
                    "1969-12-31 05:14:39.309" },
            new String[] { "1970-01-01 19:45:20.231", "1970-01-02 07:17:59.0", "1969-12-31 22:14:39.309" } };

    private TimeZone oldTimeZone;

    @Override
    public void setUp() {
        oldTimeZone = TimeZone.getDefault();
        // TIME_TESTN and corresponsing values in YEAR_ARRAY and MONTH_ARRAY
        // are time zone dependant. TIME_TESTN comments indicate that
        // they are interpreted as GMT, hence setting time zone to GMT.
        TimeZone.setDefault(TimeZone.getTimeZone("GMT"));
    }

    @Override
    public void tearDown() {
        TimeZone.setDefault(oldTimeZone);
    }

    /*
    * Constructor test
    */
    public void testTimestamplong() {
        Timestamp theTimestamp = new Timestamp(TIME_TEST1);
        // The Timestamp should have been created
        assertNotNull(theTimestamp);

        Timestamp mockTimestamp = new MockTimestamp(TIME_TEST1);
        assertNotNull(theTimestamp);
    } // end method testTimestamplong

    /*
     * Constructor test
     */
    @SuppressWarnings("deprecation")
    public void testTimestampintintintintintintint() {
        int[][] valid = { { 99, 2, 14, 17, 52, 3, 213577212 }, // 0 valid
                { 0, 0, 1, 0, 0, 0, 0 }, // 1 valid
                { 106, 11, 31, 23, 59, 59, 999999999 }, // 2 valid
                { 106, 11, 31, 23, 59, 61, 999999999 }, // 5 Seconds out of
                // range
                { 106, 11, 31, 23, 59, -1, 999999999 }, // 6 Seconds out of
                // range
                { 106, 11, 31, 23, 61, 59, 999999999 }, // 7 Minutes out of
                // range
                { 106, 11, 31, 23, -1, 59, 999999999 }, // 8 Minutes out of
                // range
                { 106, 11, 31, 25, 59, 59, 999999999 }, // 9 Hours out of range
                { 106, 11, 31, -1, 59, 59, 999999999 }, // 10 Hours out of range
                { 106, 11, 35, 23, 59, 59, 999999999 }, // 11 Days out of range
                { 106, 11, -1, 23, 59, 59, 999999999 }, // 12 Days out of range
                { 106, 15, 31, 23, 59, 59, 999999999 }, // 13 Months out of
                // range
                { 106, -1, 31, 23, 59, 59, 999999999 }, // 14 Months out of
                // range
                { -10, 11, 31, 23, 59, 59, 999999999 }, // 15 valid - Years
                // negative
        };

        for (int[] element : valid) {
            Timestamp theTimestamp = new Timestamp(element[0], element[1],
                    element[2], element[3], element[4], element[5], element[6]);
            assertNotNull("Timestamp not generated: ", theTimestamp);
        } // end for

        int[][] invalid = { { 106, 11, 31, 23, 59, 59, 1999999999 },
                { 106, 11, 31, 23, 59, 59, -999999999 }, };
        for (int[] element : invalid) {
            try {
                new Timestamp(element[0], element[1], element[2], element[3],
                        element[4], element[5], element[6]);
                fail("Should throw IllegalArgumentException");
            } catch (IllegalArgumentException e) {
                // expected
            }
        }

    } // end method testTimestampintintintintintintint

    /*
     * Method test for setTime
     */
    public void testSetTimelong() {
        // First set the timezone to GMT
        TimeZone.setDefault(TimeZone.getTimeZone("GMT"));

        Timestamp theTimestamp = new Timestamp(TIME_TEST1);

        for (int i = 0; i < TIME_ARRAY.length; i++) {
            theTimestamp.setTime(TIME_ARRAY[i]);

            assertEquals(TIME_ARRAY[i], theTimestamp.getTime());
            assertEquals(NANOS_ARRAY[i], theTimestamp.getNanos());
        } // end for

    } // end method testsetTimelong

    /*
     * Method test for getTime
     */
    public void testGetTime() {
        // First set the timezone to GMT
        TimeZone.setDefault(TimeZone.getTimeZone("GMT"));

        for (long element : TIME_ARRAY) {
            Timestamp theTimestamp = new Timestamp(element);
            assertEquals(element, theTimestamp.getTime());
        } // end for

    } // end method testgetTime

    /*
     * Method test for getYear
     */
    @SuppressWarnings("deprecation")
    public void testGetYear() {
        for (int i = 0; i < TIME_ARRAY.length; i++) {
            Timestamp theTimestamp = new Timestamp(TIME_ARRAY[i]);
            assertEquals(YEAR_ARRAY[i], theTimestamp.getYear());
        } // end for

    } // end method testgetYear

    /*
     * Method test for getMonth
     */
    @SuppressWarnings("deprecation")
    public void testGetMonth() {
        for (int i = 0; i < TIME_ARRAY.length; i++) {
            Timestamp theTimestamp = new Timestamp(TIME_ARRAY[i]);
            assertEquals(MONTH_ARRAY[i], theTimestamp.getMonth());
        } // end for

    } // end method testgetMonth

    /*
     * Method test for getDate
     */
    @SuppressWarnings("deprecation")
    public void testGetDate() {
        TimeZone.setDefault(TimeZone.getTimeZone("GMT"));
        for (int i = 0; i < TIME_ARRAY.length; i++) {
            Timestamp theTimestamp = new Timestamp(TIME_ARRAY[i]);
            assertEquals(DATE_ARRAY[i], theTimestamp.getDate());
        } // end for

    } // end method testgetDate

    /*
     * Method test for getHours
     */
    @SuppressWarnings("deprecation")
    public void testGetHours() {
        TimeZone.setDefault(TimeZone.getTimeZone("GMT"));
        for (int i = 0; i < TIME_ARRAY.length; i++) {
            Timestamp theTimestamp = new Timestamp(TIME_ARRAY[i]);
            assertEquals(HOURS_ARRAY[i], theTimestamp.getHours());
        } // end for

    } // end method testgetHours

    /*
     * Method test for getMinutes
     */
    @SuppressWarnings("deprecation")
    public void testGetMinutes() {
        TimeZone.setDefault(TimeZone.getTimeZone("GMT"));
        for (int i = 0; i < TIME_ARRAY.length; i++) {
            Timestamp theTimestamp = new Timestamp(TIME_ARRAY[i]);
            assertEquals(MINUTES_ARRAY[i], theTimestamp.getMinutes());
        } // end for

    } // end method testgetMinutes

    /*
     * Method test for getSeconds
     */
    @SuppressWarnings("deprecation")
    public void testGetSeconds() {
        TimeZone.setDefault(TimeZone.getTimeZone("GMT"));
        for (int i = 0; i < TIME_ARRAY.length; i++) {
            Timestamp theTimestamp = new Timestamp(TIME_ARRAY[i]);
            assertEquals(SECONDS_ARRAY[i], theTimestamp.getSeconds());
        } // end for

    } // end method testgetSeconds

    /*
     * Method test for valueOf
     */
    static String theExceptionMessage = "Timestamp format must be yyyy-mm-dd hh:mm:ss.fffffffff";

    public void testValueOfString() {
        TimeZone.setDefault(TimeZone.getTimeZone("GMT"));
        for (int i = 0; i < TIME_ARRAY.length; i++) {
            Timestamp theTimestamp = new Timestamp(TIME_ARRAY[i]);
            Timestamp theTimestamp2 = Timestamp.valueOf(STRING_GMT_ARRAY[i]);
            assertEquals(theTimestamp, theTimestamp2);
        } // end for

        for (String element : INVALID_STRINGS) {
            try {
                Timestamp.valueOf(element);
                fail("Should throw IllegalArgumentException.");
            } catch (IllegalArgumentException e) {
                // expected
            } // end try

        } // end for

    } // end method testvalueOfString

    /*
     * Method test for valueOf
     */
    public void testValueOfString1() {
        TimeZone.setDefault(TimeZone.getTimeZone("GMT"));

        Timestamp theReturn;
        long[] theReturnTime = { 38720231, 38720231, 80279000, -38720691,
                38720000 };
        int[] theReturnNanos = { 231000000, 231987654, 0, 309000000, 0, };

        String[] valid = { "1970-01-01 10:45:20.231",
                "1970-01-01 10:45:20.231987654", "1970-01-01 22:17:59.0",
                "1969-12-31 13:14:39.309", "1970-01-01 10:45:20", };
        String[] invalid = { null, "ABCDEFGHI", "233104",
                "1970-01-01 22:17:59.",
                "1970-01-01 10:45:20.231987654690645322",
                "1970-01-01 10:45:20&231987654",
                "1970-01-01 10:45:20.-31987654",
                "1970-01-01 10:45:20.ABCD87654", "21-43-48", };

        for (int i = 0; i < valid.length; i++) {
            theReturn = Timestamp.valueOf(valid[i]);
            assertEquals(theReturnTime[i], theReturn.getTime());
            assertEquals(theReturnNanos[i], theReturn.getNanos());
        } // end for

        for (String element : invalid) {
            try {
                theReturn = Timestamp.valueOf(element);
                fail("Should throw IllegalArgumentException.");
            } catch (IllegalArgumentException e) {
                // expected
            }
        }

        // Regression test for HARMONY-5506
        String date = "1970-01-01 22:17:59.0                 ";
        Timestamp t = Timestamp.valueOf(date);
        assertEquals(80279000, t.getTime());

    } // end method testValueOfString

    public void testValueOf_IAE() {
        try {
            java.sql.Timestamp.valueOf("2008-12-22 15:00:01.");
            fail("should throw IllegalArgumentException");
        } catch (IllegalArgumentException e) {
            // Expected
        }

        try {
            // bug of RI 5, passed on RI 6
            java.sql.Timestamp.valueOf("178548938-12-22 15:00:01.000000001");
            fail("should throw IllegalArgumentException");
        } catch (IllegalArgumentException e) {
            // Expected
        }

        try {
            java.sql.Timestamp.valueOf("2008-12-22 15:00:01.0000000011");
            fail("should throw IllegalArgumentException");
        } catch (IllegalArgumentException e) {
            // Expected
        }
    }

    /*
     * Method test for toString
     */
    public void testToString() {
        for (int i = 0; i < TIME_ARRAY.length; i++) {
            testToString(TIMEZONES[i], TIME_ARRAY, STRING_TIMESTAMP_ARRAYS[i]);
        } // end for

        TimeZone.setDefault(TimeZone.getTimeZone("GMT"));

        Timestamp t1 = new Timestamp(Long.MIN_VALUE);
        assertEquals("292278994-08-17 07:12:55.192", t1.toString()); //$NON-NLS-1$

        Timestamp t2 = new Timestamp(Long.MIN_VALUE + 1);
        assertEquals("292278994-08-17 07:12:55.193", t2.toString()); //$NON-NLS-1$

        Timestamp t3 = new Timestamp(Long.MIN_VALUE + 807);
        assertEquals("292278994-08-17 07:12:55.999", t3.toString()); //$NON-NLS-1$

        Timestamp t4 = new Timestamp(Long.MIN_VALUE + 808);
        assertEquals("292269055-12-02 16:47:05.0", t4.toString()); //$NON-NLS-1$
    } // end method testtoString

    private void testToString(String timeZone, long[] theTimeStamps, String[] theTimeStampStrings) {
        TimeZone.setDefault(TimeZone.getTimeZone(timeZone));
        for (int i = 0; i < TIME_ARRAY.length; i++) {
            Timestamp theTimestamp = new Timestamp(theTimeStamps[i]);
            assertEquals(theTimeStampStrings[i], theTimestamp.toString());
        } // end for

    }

    /*
    * Method test for getNanos
    */
    public void testGetNanos() {
        for (int i = 0; i < TIME_ARRAY.length; i++) {
            Timestamp theTimestamp = new Timestamp(TIME_ARRAY[i]);
            assertEquals(NANOS_ARRAY[i], theTimestamp.getNanos());
        } // end for

    } // end method testgetNanos

    /*
     * Method test for setNanos
     */
    public void testSetNanosint() {
        TimeZone.setDefault(TimeZone.getTimeZone("GMT"));

        int[] NANOS_INVALID = { -137891990, 1635665198, -1 };
        for (int i = 0; i < TIME_ARRAY.length; i++) {
            Timestamp theTimestamp = new Timestamp(TIME_ARRAY[i]);

            theTimestamp.setNanos(NANOS_ARRAY2[i]);

            assertEquals(NANOS_ARRAY2[i], theTimestamp.getNanos());
            // Also check that these Timestamps with detailed nanos values
            // convert to
            // strings correctly
            assertEquals(STRING_NANOS_ARRAY[i], theTimestamp.toString());
        } // end for

        for (int i = 0; i < NANOS_INVALID.length; i++) {
            Timestamp theTimestamp = new Timestamp(TIME_ARRAY[i]);
            int originalNanos = theTimestamp.getNanos();
            try {
                theTimestamp.setNanos(NANOS_INVALID[i]);
                fail("Should throw IllegalArgumentException");
            } catch (IllegalArgumentException e) {
                // expected
            } // end try

            assertEquals(originalNanos, theTimestamp.getNanos());
        } // end for

    } // end method testsetNanosint

    /*
     * Method test for equals
     */
    public void testEqualsTimestamp() {
        for (long element : TIME_ARRAY) {
            Timestamp theTimestamp = new Timestamp(element);
            Timestamp theTimestamp2 = new Timestamp(element);

            assertTrue(theTimestamp.equals(theTimestamp2));
        } // end for

        Timestamp theTest = new Timestamp(TIME_COMPARE);

        for (long element : TIME_ARRAY) {
            Timestamp theTimestamp = new Timestamp(element);
            assertFalse(theTimestamp.equals(theTest));
        } // end for

        // Regression for HARMONY-526
        assertFalse(new Timestamp(0).equals((Timestamp) null));
    } // end method testequalsTimestamp

    /*
     * Method test for equals
     */
    public void testEqualsObject() {
        for (long element : TIME_ARRAY) {
            Timestamp theTimestamp = new Timestamp(element);

            Object theTimestamp2 = new Timestamp(element);

            assertTrue(theTimestamp.equals(theTimestamp2));
        } // end for

        Object theTest = new Timestamp(TIME_COMPARE);

        for (long element : TIME_ARRAY) {
            Timestamp theTimestamp = new Timestamp(element);

            assertFalse(theTimestamp.equals(theTest));
        } // end for

        Object nastyTest = new String("Test ");
        Timestamp theTimestamp = new Timestamp(TIME_ARRAY[1]);
        assertFalse(theTimestamp.equals(nastyTest));

        // Regression for HARMONY-526
        assertFalse(new Timestamp(0).equals((Object) null));
    } // end method testequalsObject

    /*
     * Method test for before
     */
    public void testBeforeTimestamp() {
        Timestamp theTest = new Timestamp(TIME_LATE);

        for (long element : TIME_ARRAY) {
            Timestamp theTimestamp = new Timestamp(element);

            assertTrue(theTimestamp.before(theTest));
        } // end for

        theTest = new Timestamp(TIME_EARLY);

        for (long element : TIME_ARRAY) {
            Timestamp theTimestamp = new Timestamp(element);

            assertFalse(theTimestamp.before(theTest));
        } // end for

        for (long element : TIME_ARRAY) {
            theTest = new Timestamp(element);
            Timestamp theTimestamp = new Timestamp(element);

            assertFalse(theTimestamp.before(theTest));
            theTest.setNanos(theTest.getNanos() + 1);
            assertTrue(theTimestamp.before(theTest));
        } // end for

    } // end method testbeforeTimestamp

    /*
     * Method test for after
     */
    public void testAfterTimestamp() {
        Timestamp theTest = new Timestamp(TIME_LATE);

        for (long element : TIME_ARRAY) {
            Timestamp theTimestamp = new Timestamp(element);

            assertFalse(theTimestamp.after(theTest));
        } // end for

        theTest = new Timestamp(TIME_EARLY);

        for (long element : TIME_ARRAY) {
            Timestamp theTimestamp = new Timestamp(element);

            assertTrue(theTimestamp.after(theTest));
        } // end for

        for (long element : TIME_ARRAY) {
            theTest = new Timestamp(element);
            Timestamp theTimestamp = new Timestamp(element);

            assertFalse(theTimestamp.after(theTest));
            theTimestamp.setNanos(theTimestamp.getNanos() + 1);
            assertTrue(theTimestamp.after(theTest));
        } // end for

    } // end method testafterTimestamp

    /*
     * Method test for compareTo
     */
    @SuppressWarnings("deprecation")
    public void testCompareToTimestamp() {
        Timestamp theTest = new Timestamp(TIME_EARLY);
        Timestamp theTest2 = new Timestamp(TIME_LATE);

        for (long element : TIME_ARRAY) {
            Timestamp theTimestamp = new Timestamp(element);
            Timestamp theTimestamp2 = new Timestamp(element);

            assertTrue(theTimestamp.compareTo(theTest) > 0);
            assertTrue(theTimestamp.compareTo(theTest2) < 0);
            assertEquals(0, theTimestamp.compareTo(theTimestamp2));
        } // end for

        Timestamp t1 = new Timestamp(-1L);
        Timestamp t2 = new Timestamp(-1L);

        t1.setTime(Long.MIN_VALUE);
        t2.setDate(Integer.MIN_VALUE);
        assertEquals(-1, t1.compareTo(t2));
        assertEquals(1, t2.compareTo(t1));

        t1.setTime(Long.MAX_VALUE);
        t2.setTime(Long.MAX_VALUE - 1);
        assertEquals(1, t1.compareTo(t2));
        assertEquals(-1, t2.compareTo(t1));

        t1.setTime(Integer.MAX_VALUE);
        t2.setTime(Integer.MAX_VALUE);
        assertEquals(0, t1.compareTo(t2));
        assertEquals(0, t2.compareTo(t1));

    } // end method testcompareToTimestamp

    /**
     * @tests java.sql.Timestamp#compareTo(java.util.Date)
     */
    public void testCompareToDate() {
        Date theTest = new Timestamp(TIME_EARLY);
        Date theTest2 = new Timestamp(TIME_LATE);

        for (long element : TIME_ARRAY) {
            Timestamp theTimestamp = new Timestamp(element);
            Date theTimestamp2 = new Timestamp(element);

            assertTrue(theTimestamp.compareTo(theTest) > 0);
            assertTrue(theTimestamp.compareTo(theTest2) < 0);
            assertEquals(0, theTimestamp.compareTo(theTimestamp2));
        } // end for

        Timestamp timestamp = new Timestamp(1000000);
        Date date = new Date(1000000);

        assertEquals(0, timestamp.compareTo(date));
        timestamp.setNanos(10);
        assertEquals(1, timestamp.compareTo(date));

        long time = System.currentTimeMillis();
        Date date2 = new Date(time);
        Timestamp timestamp2 = new Timestamp(date2.getTime());
        assertEquals(0, timestamp2.compareTo(date2));
    } // end method testcompareToObject

    /**
     * @tests serialization/deserialization compatibility.
     */
    public void testSerializationSelf() throws Exception {
        Timestamp object = new Timestamp(100L);
        SerializationTest.verifySelf(object);
    }

    /**
     * @tests serialization/deserialization compatibility with RI.
     */
    public void testSerializationCompatibility() throws Exception {
        Timestamp object = new Timestamp(100L);
        SerializationTest.verifyGolden(this, object);
    }

    /**
     * @tests overriding Timestamp to create an immutable class.
     */
    public void testOverridingTimestamp() {
        Timestamp ts = new Timestamp(8392418) {
            @Override
            public void setNanos(int n) {
                throw new RuntimeException("Overridden method shouldn't be called");
            }
        };
    }
} // end class TimestampTest