Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/jdk/javax/swing/JComboBox/7031551/bug7031551.java
41153 views
1
/*
2
* Copyright (c) 2011, 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
/* @test
25
* @bug 7031551
26
* @summary Generics: JComboBox
27
* @author Pavel Porvatov
28
*/
29
30
import javax.swing.*;
31
import java.util.Vector;
32
33
public class bug7031551 {
34
35
private static final String TEST_ELEMENT1 = "Test1";
36
private static final String TEST_ELEMENT2 = "Test2";
37
private static final String TEST_ELEMENT3 = "Test3";
38
39
/**
40
* @param args the command line arguments
41
*/
42
@SuppressWarnings("unchecked")
43
public static void main(String[] args) {
44
testRawSignatures();
45
testGenericSignatures();
46
}
47
48
@SuppressWarnings("unchecked")
49
private static void testRawSignatures() {
50
// Test JComboBox
51
ComboBoxModel rawTestModel = new DefaultComboBoxModel();
52
53
JComboBox rawTestComboBox = new JComboBox();
54
rawTestComboBox = new JComboBox(rawTestModel);
55
rawTestComboBox = new JComboBox(new Object[]{TEST_ELEMENT1});
56
rawTestComboBox = new JComboBox(new Vector());
57
58
Object unused1 = rawTestComboBox.getPrototypeDisplayValue();
59
rawTestComboBox.setPrototypeDisplayValue(TEST_ELEMENT1);
60
61
ListCellRenderer unused2 = rawTestComboBox.getRenderer();
62
rawTestComboBox.setRenderer(new DefaultListCellRenderer());
63
64
ComboBoxModel unused3 = rawTestComboBox.getModel();
65
rawTestComboBox.setModel(rawTestModel);
66
67
rawTestComboBox.addItem(TEST_ELEMENT2);
68
rawTestComboBox.insertItemAt(TEST_ELEMENT3, 1);
69
rawTestComboBox.removeItem(TEST_ELEMENT2);
70
assertEquals(rawTestComboBox.getItemAt(0), TEST_ELEMENT3);
71
rawTestComboBox.removeAllItems();
72
73
// Test DefaultComboBoxModel
74
DefaultComboBoxModel testModel = new DefaultComboBoxModel();
75
testModel = new DefaultComboBoxModel(new Vector());
76
testModel = new DefaultComboBoxModel(new Object[]{TEST_ELEMENT1});
77
78
testModel.addElement(TEST_ELEMENT2);
79
testModel.insertElementAt(TEST_ELEMENT3, 1);
80
assertEquals(testModel.getElementAt(2), TEST_ELEMENT2);
81
}
82
83
private static void testGenericSignatures() {
84
// Test JComboBox
85
ComboBoxModel<String> stringTestModel = new DefaultComboBoxModel<String>();
86
87
JComboBox<String> stringTestComboBox = new JComboBox<String>();
88
stringTestComboBox = new JComboBox<String>(stringTestModel);
89
stringTestComboBox = new JComboBox<String>(new String[]{TEST_ELEMENT1});
90
stringTestComboBox = new JComboBox<String>(new Vector<String>());
91
92
String unused1 = stringTestComboBox.getPrototypeDisplayValue();
93
stringTestComboBox.setPrototypeDisplayValue(TEST_ELEMENT1);
94
95
ListCellRenderer<? super String> unused2 = stringTestComboBox.getRenderer();
96
stringTestComboBox.setRenderer(new DefaultListCellRenderer());
97
98
ComboBoxModel unused3 = stringTestComboBox.getModel();
99
stringTestComboBox.setModel(stringTestModel);
100
101
stringTestComboBox.addItem(TEST_ELEMENT2);
102
stringTestComboBox.insertItemAt(TEST_ELEMENT3, 1);
103
stringTestComboBox.removeItem(TEST_ELEMENT2);
104
assertEquals(stringTestComboBox.getItemAt(0), TEST_ELEMENT3);
105
stringTestComboBox.removeAllItems();
106
107
// Test DefaultComboBoxModel
108
DefaultComboBoxModel<String> testModel = new DefaultComboBoxModel<String>();
109
testModel = new DefaultComboBoxModel<String>(new Vector<String>());
110
testModel = new DefaultComboBoxModel<String>(new String[]{TEST_ELEMENT1});
111
112
testModel.addElement(TEST_ELEMENT2);
113
testModel.insertElementAt(TEST_ELEMENT3, 1);
114
assertEquals(testModel.getElementAt(2), TEST_ELEMENT2);
115
}
116
117
private static void assertEquals(Object expectedObject, Object actualObject) {
118
if (!expectedObject.equals(actualObject)) {
119
throw new RuntimeException("Expected: " + expectedObject + " but was: " + actualObject);
120
}
121
}
122
}
123
124
125