Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/test/java/awt/Checkbox/SetStateExcessEvent/SetStateExcessEvent.java
38828 views
/*1* Copyright (c) 2015, 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.awt.Checkbox;24import java.awt.CheckboxGroup;25import java.awt.Frame;26import java.awt.GridBagLayout;27import java.awt.Robot;2829/**30* @test31* @bug 807450032* @summary Checkbox.setState() call should not post ItemEvent33* @author Sergey Bylokhov34*/35public final class SetStateExcessEvent {3637private static boolean failed;3839public static void main(final String[] args) throws Exception {40final Robot robot = new Robot();41final CheckboxGroup group = new CheckboxGroup();42final Checkbox[] cbs = {new Checkbox("checkbox1", true, group),43new Checkbox("checkbox2", false, group),44new Checkbox("checkbox3", true, group),4546new Checkbox("checkbox4", true),47new Checkbox("checkbox5", false),48new Checkbox("checkbox6", true)};49final Frame frame = new Frame();50frame.setLayout(new GridBagLayout());51try {52for (final Checkbox cb : cbs) {53cb.addItemListener(e -> {54failed = true;55});56}57for (final Checkbox cb : cbs) {58frame.add(cb);59}60frame.pack();6162for (final Checkbox cb : cbs) {63cb.setState(!cb.getState());64}6566for (final Checkbox cb : cbs) {67group.setSelectedCheckbox(cb);68}69robot.waitForIdle();70} finally {71frame.dispose();72}73if (failed) {74throw new RuntimeException("Listener should not be called");75}76System.out.println("Test passed");77}78}798081