Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/jdk/java/beans/VetoableChangeSupport/Test6630275.java
41152 views
1
/*
2
* Copyright (c) 2008, Oracle and/or its affiliates. All rights reserved.
3
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4
*
5
* This code is free software; you can redistribute it and/or modify it
6
* under the terms of the GNU General Public License version 2 only, as
7
* published by the Free Software Foundation.
8
*
9
* This code is distributed in the hope that it will be useful, but WITHOUT
10
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12
* version 2 for more details (a copy is included in the LICENSE file that
13
* accompanied this code).
14
*
15
* You should have received a copy of the GNU General Public License version
16
* 2 along with this work; if not, write to the Free Software Foundation,
17
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18
*
19
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20
* or visit www.oracle.com if you need additional information or have any
21
* questions.
22
*/
23
24
/*
25
* @test
26
* @bug 6630275
27
* @summary Tests VetoableChangeSupport specification
28
* @author Sergey Malenkov
29
*/
30
31
import java.beans.PropertyChangeEvent;
32
import java.beans.PropertyVetoException;
33
import java.beans.VetoableChangeListener;
34
import java.beans.VetoableChangeSupport;
35
36
public class Test6630275 {
37
private static final String PROPERTY = "property"; // NON-NLS: predefined property name
38
39
public static void main(String[] args) {
40
CheckListener first = new CheckListener(false);
41
CheckListener second = new CheckListener(true);
42
CheckListener third = new CheckListener(false);
43
44
VetoableChangeSupport vcs = new VetoableChangeSupport(Test6630275.class);
45
vcs.addVetoableChangeListener(first);
46
vcs.addVetoableChangeListener(PROPERTY, first);
47
vcs.addVetoableChangeListener(PROPERTY, second);
48
vcs.addVetoableChangeListener(PROPERTY, third);
49
try {
50
vcs.fireVetoableChange(PROPERTY, true, false);
51
} catch (PropertyVetoException exception) {
52
first.validate();
53
second.validate();
54
third.validate();
55
return; // expected exception
56
}
57
throw new Error("exception should be thrown");
58
}
59
60
private static class CheckListener implements VetoableChangeListener {
61
private final boolean veto;
62
private boolean odd; // even/odd check for notification
63
64
private CheckListener(boolean veto) {
65
this.veto = veto;
66
}
67
68
private void validate() {
69
if (this.veto != this.odd)
70
throw new Error(this.odd
71
? "undo event expected"
72
: "unexpected undo event");
73
}
74
75
public void vetoableChange(PropertyChangeEvent event) throws PropertyVetoException {
76
this.odd = !this.odd;
77
if (this.veto)
78
throw new PropertyVetoException("disable all changes", event);
79
}
80
}
81
}
82
83