Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/test/java/beans/XMLEncoder/Test6437265.java
38812 views
/*1* Copyright (c) 2006, 2007, 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* @bug 643726526* @summary Tests encoding of container with BorderLayout27* @author Sergey Malenkov28*/2930import java.awt.BorderLayout;31import java.awt.Component;32import javax.swing.JLabel;33import javax.swing.JPanel;3435public final class Test6437265 extends AbstractTest<JPanel> {36private static final String[] NAMES = {37BorderLayout.EAST,38BorderLayout.WEST,39BorderLayout.NORTH,40BorderLayout.SOUTH,41BorderLayout.CENTER,42BorderLayout.LINE_END,43BorderLayout.PAGE_END,44BorderLayout.LINE_START,45BorderLayout.PAGE_START};4647public static void main(String[] args) {48new Test6437265().test(true);49}5051protected JPanel getObject() {52JPanel panel = new MyPanel();53for (String name : NAMES) {54panel.add(name, new JLabel(name));55}56return panel;57}5859protected void validate(JPanel before, JPanel after) {60validate(before);61validate(after);62super.validate(before, after);63}6465private static void validate(JPanel panel) {66BorderLayout layout = (BorderLayout) panel.getLayout();67for (Component component : panel.getComponents()) {68String name = (String) layout.getConstraints(component);69if (name == null)70throw new Error("The component is not layed out: " + component);7172JLabel label = (JLabel) component;73if (!name.equals(label.getText()))74throw new Error("The component is layed out on " + name + ": " + component);75}76}7778public static final class MyPanel extends JPanel {79public MyPanel() {80// the bug is reproducible for containers81// that uses BorderLayout as default layout manager.82super(new BorderLayout(3, 3));83}84}85}868788