Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/jdk/java/beans/XMLDecoder/spec/TestNew.java
41155 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
* @summary Tests <new> element
27
* @run main/othervm -Djava.security.manager=allow TestNew
28
* @author Sergey Malenkov
29
*/
30
31
import java.beans.XMLDecoder;
32
import java.util.ArrayList;
33
import java.util.List;
34
35
public final class TestNew extends AbstractTest {
36
public static final String XML
37
= "<java>\n"
38
+ " <new class=\"TestNew\"/>\n"
39
+ " <new class=\"TestNew\">\n"
40
+ " <null/>\n"
41
+ " </new>\n"
42
+ " <new class=\"TestNew\">\n"
43
+ " <string>single</string>\n"
44
+ " </new>\n"
45
+ " <new class=\"TestNew\">\n"
46
+ " <string>first</string>\n"
47
+ " <string>second</string>\n"
48
+ " <string>third</string>\n"
49
+ " </new>\n"
50
+ "</java>";
51
52
public static void main(String[] args) {
53
new TestNew().test(true);
54
}
55
56
private List<String> list;
57
58
public TestNew(String...messages) {
59
if (messages != null) {
60
this.list = new ArrayList<String>();
61
for (String message : messages) {
62
this.list.add(message);
63
}
64
}
65
}
66
67
@Override
68
public boolean equals(Object object) {
69
if (object instanceof TestNew) {
70
TestNew test = (TestNew) object;
71
return (test.list == null)
72
? this.list == null
73
: test.list.equals(this.list);
74
}
75
return false;
76
}
77
78
@Override
79
protected void validate(XMLDecoder decoder) {
80
validate(decoder.readObject());
81
validate(decoder.readObject(), null);
82
validate(decoder.readObject(), "single");
83
validate(decoder.readObject(), "first", "second", "third");
84
}
85
86
private static void validate(Object object, String...messages) {
87
if (!object.equals(new TestNew(messages))) {
88
throw new Error("expected object");
89
}
90
}
91
}
92
93