Path: blob/master/test/jdk/javax/swing/GroupLayout/7071166/bug7071166.java
41153 views
/*1* Copyright (c) 2011, 2018, 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 707116626* @summary LayoutStyle.getPreferredGap() - IAE is expected but not thrown27* @author Pavel Porvatov28*/2930import java.awt.Container;3132import javax.swing.JButton;33import javax.swing.LayoutStyle;34import javax.swing.SwingUtilities;35import javax.swing.UIManager;36import javax.swing.UnsupportedLookAndFeelException;3738import static javax.swing.SwingConstants.EAST;39import static javax.swing.SwingConstants.NORTH;40import static javax.swing.SwingConstants.NORTH_EAST;41import static javax.swing.SwingConstants.NORTH_WEST;42import static javax.swing.SwingConstants.SOUTH;43import static javax.swing.SwingConstants.SOUTH_EAST;44import static javax.swing.SwingConstants.SOUTH_WEST;45import static javax.swing.SwingConstants.WEST;4647public class bug7071166 {48private static final int[] POSITIONS = {NORTH, EAST, SOUTH, WEST, // valid positions49NORTH_EAST, SOUTH_EAST, SOUTH_WEST, NORTH_WEST, 123, -456}; // invalid positions5051public static void main(String[] args) throws Exception {52for (UIManager.LookAndFeelInfo lookAndFeelInfo : UIManager.getInstalledLookAndFeels()) {53try {54UIManager.setLookAndFeel(lookAndFeelInfo.getClassName());55} catch (final UnsupportedLookAndFeelException ignored) {56continue;57}58System.out.println("LookAndFeel: " + lookAndFeelInfo.getName());5960SwingUtilities.invokeAndWait(new Runnable() {61public void run() {62LayoutStyle layoutStyle = LayoutStyle.getInstance();6364System.out.println("LayoutStyle: " + layoutStyle);6566for (int i = 0; i < POSITIONS.length; i++) {67int position = POSITIONS[i];6869try {70layoutStyle.getPreferredGap(new JButton(), new JButton(),71LayoutStyle.ComponentPlacement.RELATED, position, new Container());7273if (i > 3) {74throw new RuntimeException("IllegalArgumentException is not thrown for position " +75position);76}77} catch (IllegalArgumentException e) {78if (i <= 3) {79throw new RuntimeException("IllegalArgumentException is thrown for position " +80position);81}82}83}84}85});8687System.out.println("passed");88}89}90}919293