Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/jdk/sanity/client/SwingSet/src/SpinnerDemoTest.java
41153 views
1
/*
2
* Copyright (c) 2011, 2018, 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
import org.jtregext.GuiTestListener;
25
import com.sun.swingset3.demos.spinner.SpinnerDemo;
26
import static com.sun.swingset3.demos.spinner.SpinnerDemo.DEMO_TITLE;
27
import java.text.DecimalFormat;
28
import javax.swing.UIManager;
29
import static org.testng.AssertJUnit.*;
30
import org.testng.annotations.Test;
31
import org.netbeans.jemmy.ClassReference;
32
import org.netbeans.jemmy.operators.JFrameOperator;
33
import org.netbeans.jemmy.operators.JSpinnerOperator;
34
import org.netbeans.jemmy.operators.JTextFieldOperator;
35
import org.testng.annotations.Listeners;
36
37
/*
38
* @test
39
* @key headful
40
* @summary Verifies SwingSet3 SpinnerDemo by adjusting each spinner value via
41
* the spinner button and checking text field value.
42
*
43
* @library /sanity/client/lib/jemmy/src
44
* @library /sanity/client/lib/Extensions/src
45
* @library /sanity/client/lib/SwingSet3/src
46
* @modules java.desktop
47
* java.logging
48
* @build org.jemmy2ext.JemmyExt
49
* @build com.sun.swingset3.demos.spinner.SpinnerDemo
50
* @run testng/timeout=600 SpinnerDemoTest
51
*/
52
@Listeners(GuiTestListener.class)
53
public class SpinnerDemoTest {
54
55
private static final int SPINNERS_COUNT = 9;
56
private static final DecimalFormat decimalFormat = new DecimalFormat();
57
58
@Test(dataProvider = "availableLookAndFeels", dataProviderClass = TestHelpers.class)
59
public void test(String lookAndFeel) throws Exception {
60
UIManager.setLookAndFeel(lookAndFeel);
61
new ClassReference(SpinnerDemo.class.getCanonicalName()).startApplication();
62
63
JFrameOperator frame = new JFrameOperator(DEMO_TITLE);
64
65
// Check changing different spinners
66
for (int i = 0; i < SPINNERS_COUNT; i++) {
67
changeValues(frame, i);
68
}
69
}
70
71
private void changeValues(JFrameOperator jfo, int spinnerIndex) throws Exception {
72
JSpinnerOperator spinner = new JSpinnerOperator(jfo, spinnerIndex);
73
JTextFieldOperator jtfo = new JTextFieldOperator(spinner);
74
float originalFieldValue = decimalFormat.parse(jtfo.getText()).floatValue();
75
float finalFieldValue;
76
77
// increment by one the value via spinner
78
spinner.getIncreaseOperator().push();
79
finalFieldValue = decimalFormat.parse(jtfo.getText()).floatValue();
80
81
// check that the value was increased
82
assertTrue("Increment Spinner " + spinner
83
+ " (originalFieldValue, actual value: " + originalFieldValue + " "
84
+ "< finalFieldValue, actual value = " + finalFieldValue + ")",
85
originalFieldValue < finalFieldValue);
86
87
// decrease value via spinner
88
spinner.getDecreaseOperator().push();
89
finalFieldValue = decimalFormat.parse(jtfo.getText()).floatValue();
90
91
// check that the value was decrimented
92
assertTrue("Decrement Spinner " + spinner
93
+ " (originalFieldValue, actual value: " + originalFieldValue + " "
94
+ ">= finalFieldValue, actual value = " + finalFieldValue + ")",
95
originalFieldValue >= finalFieldValue);
96
}
97
98
}
99
100