|
1 /* |
|
2 * Copyright (c) 2011, 2016, 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 com.sun.swingset3.demos.spinner.SpinnerDemo; |
|
25 import static com.sun.swingset3.demos.spinner.SpinnerDemo.DEMO_TITLE; |
|
26 import java.text.DecimalFormat; |
|
27 import static org.testng.AssertJUnit.*; |
|
28 import org.testng.annotations.Test; |
|
29 import org.netbeans.jemmy.ClassReference; |
|
30 import org.netbeans.jemmy.operators.JFrameOperator; |
|
31 import org.netbeans.jemmy.operators.JSpinnerOperator; |
|
32 import org.netbeans.jemmy.operators.JTextFieldOperator; |
|
33 import static org.jemmy2ext.JemmyExt.captureDebugInfoOnFail; |
|
34 |
|
35 /* |
|
36 * @test |
|
37 * @key headful |
|
38 * @summary Verifies SwingSet3 SpinnerDemo by adjusting each spinner value via |
|
39 * the spinner button and checking text field value. |
|
40 * |
|
41 * @library /sanity/client/lib/jemmy/src |
|
42 * @library /sanity/client/lib/Jemmy2Ext/src |
|
43 * @library /sanity/client/lib/SwingSet3/src |
|
44 * @build org.jemmy2ext.JemmyExt |
|
45 * @build com.sun.swingset3.demos.spinner.SpinnerDemo |
|
46 * @run testng SpinnerDemoTest |
|
47 */ |
|
48 public class SpinnerDemoTest { |
|
49 |
|
50 private static final int SPINNERS_COUNT = 9; |
|
51 private static final DecimalFormat decimalFormat = new DecimalFormat(); |
|
52 |
|
53 @Test |
|
54 public void test() throws Exception { |
|
55 captureDebugInfoOnFail(() -> { |
|
56 new ClassReference(SpinnerDemo.class.getCanonicalName()).startApplication(); |
|
57 |
|
58 JFrameOperator frame = new JFrameOperator(DEMO_TITLE); |
|
59 |
|
60 // Check changing different spinners |
|
61 for (int i = 0; i < SPINNERS_COUNT; i++) { |
|
62 changeValues(frame, i); |
|
63 } |
|
64 }); |
|
65 } |
|
66 |
|
67 private void changeValues(JFrameOperator jfo, int spinnerIndex) throws Exception { |
|
68 JSpinnerOperator spinner = new JSpinnerOperator(jfo, spinnerIndex); |
|
69 JTextFieldOperator jtfo = new JTextFieldOperator(spinner); |
|
70 float originalFieldValue = decimalFormat.parse(jtfo.getText()).floatValue(); |
|
71 float finalFieldValue; |
|
72 |
|
73 // increment by one the value via spinner |
|
74 spinner.getIncreaseOperator().push(); |
|
75 finalFieldValue = decimalFormat.parse(jtfo.getText()).floatValue(); |
|
76 |
|
77 // check that the value was increased |
|
78 assertTrue("Increment Spinner " + spinner |
|
79 + " (originalFieldValue, actual value: " + originalFieldValue + " " |
|
80 + "< finalFieldValue, actual value = " + finalFieldValue + ")", |
|
81 originalFieldValue < finalFieldValue); |
|
82 |
|
83 // decrease value via spinner |
|
84 spinner.getDecreaseOperator().push(); |
|
85 finalFieldValue = decimalFormat.parse(jtfo.getText()).floatValue(); |
|
86 |
|
87 // check that the value was decrimented |
|
88 assertTrue("Decrement Spinner " + spinner |
|
89 + " (originalFieldValue, actual value: " + originalFieldValue + " " |
|
90 + ">= finalFieldValue, actual value = " + finalFieldValue + ")", |
|
91 originalFieldValue >= finalFieldValue); |
|
92 } |
|
93 |
|
94 } |