Path: blob/master/test/jdk/java/util/Calendar/bug4316678.java
41149 views
/*1* Copyright (c) 2000, 2016, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/2223import java.io.*;24import java.util.*;25import java.text.*;2627/**28* @test29* @bug 431667830* @summary test that Calendar's Serializasion works correctly.31* @library /java/text/testlib32*/33public class bug4316678 extends IntlTest {3435public static void main(String[] args) throws Exception {36new bug4316678().run(args);37}3839public void Test4316678() throws Exception {40GregorianCalendar gc1;41GregorianCalendar gc2;42TimeZone saveZone = TimeZone.getDefault();4344try {45TimeZone.setDefault(TimeZone.getTimeZone("PST"));4647gc1 = new GregorianCalendar(2000, Calendar.OCTOBER, 10);48try (ObjectOutputStream out49= new ObjectOutputStream(new FileOutputStream("bug4316678.ser"))) {50out.writeObject(gc1);51}5253try (ObjectInputStream in54= new ObjectInputStream(new FileInputStream("bug4316678.ser"))) {55gc2 = (GregorianCalendar)in.readObject();56}5758gc1.set(Calendar.DATE, 16);59gc2.set(Calendar.DATE, 16);60if (!gc1.getTime().equals(gc2.getTime())) {61errln("Invalid Time :" + gc2.getTime() +62", expected :" + gc1.getTime());63}64} finally {65TimeZone.setDefault(saveZone);66}67}68}697071