Path: blob/master/test/jdk/java/awt/Checkbox/SetStateExcessEvent/SetStateExcessEvent.java
41153 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* @key headful32* @bug 807450033* @summary Checkbox.setState() call should not post ItemEvent34* @author Sergey Bylokhov35*/36public final class SetStateExcessEvent {3738private static boolean failed;3940public static void main(final String[] args) throws Exception {41final Robot robot = new Robot();42final CheckboxGroup group = new CheckboxGroup();43final Checkbox[] cbs = {new Checkbox("checkbox1", true, group),44new Checkbox("checkbox2", false, group),45new Checkbox("checkbox3", true, group),4647new Checkbox("checkbox4", true),48new Checkbox("checkbox5", false),49new Checkbox("checkbox6", true)};50final Frame frame = new Frame();51frame.setLayout(new GridBagLayout());52try {53for (final Checkbox cb : cbs) {54cb.addItemListener(e -> {55failed = true;56});57}58for (final Checkbox cb : cbs) {59frame.add(cb);60}61frame.pack();6263for (final Checkbox cb : cbs) {64cb.setState(!cb.getState());65}6667for (final Checkbox cb : cbs) {68group.setSelectedCheckbox(cb);69}70robot.waitForIdle();71} finally {72frame.dispose();73}74if (failed) {75throw new RuntimeException("Listener should not be called");76}77System.out.println("Test passed");78}79}808182