Path: blob/master/test/jdk/javax/swing/JLayer/SerializationTest/SerializationTest.java
41153 views
/*1* Copyright (c) 2008, 2010, 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*/2223/*24* @test25* @summary Makes sure that JLayer is synchronizable26* @author Alexander Potochkin27* @run main SerializationTest28*/2930import javax.swing.*;31import javax.swing.plaf.LayerUI;32import java.io.ByteArrayInputStream;33import java.io.ObjectOutputStream;34import java.io.ObjectInputStream;35import java.io.ByteArrayOutputStream;3637public class SerializationTest {3839public static void main(String[] args) throws Exception {40ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();41ObjectOutputStream outputStream = new ObjectOutputStream(byteArrayOutputStream);4243JLayer<JButton> layer = new JLayer<JButton>(new JButton("Hello"));4445layer.setUI(new TestLayerUI<JButton>());4647outputStream.writeObject(layer);48outputStream.flush();4950ByteArrayInputStream byteArrayInputStream =51new ByteArrayInputStream(byteArrayOutputStream.toByteArray());52ObjectInputStream inputStream = new ObjectInputStream(byteArrayInputStream);5354JLayer newLayer = (JLayer) inputStream.readObject();5556if (newLayer.getGlassPane() == null) {57throw new RuntimeException("JLayer's glassPane is null");58}59if (newLayer.getUI().getClass() != layer.getUI().getClass()) {60throw new RuntimeException("Different UIs");61}62if (newLayer.getView().getClass() != layer.getView().getClass()) {63throw new RuntimeException("Different Views");64}65}6667static class TestLayerUI<V extends JComponent> extends LayerUI<V> {68public String toString() {69return "TestLayerUI";70}71}72}737475