6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation. Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
23 * questions.
24 */
25
26 package javafx.css;
27
28 import javafx.scene.paint.Color;
29 import com.sun.javafx.css.ParsedValueImpl;
30
31 import java.util.ArrayList;
32 import java.util.Arrays;
33 import java.util.Collection;
34 import java.util.Collections;
35 import java.util.List;
36 import org.junit.Test;
37 import static org.junit.Assert.*;
38
39 import org.junit.runner.RunWith;
40 import org.junit.runners.Parameterized;
41 import org.junit.runners.Parameterized.Parameters;
42
43 @RunWith(Parameterized.class)
44 public class DeclarationTest {
45
46 private static class Data {
47 private final Declaration d1, d2;
48 private final boolean expected;
49 Data(Declaration d1, Declaration d2, boolean expected){
50 this.d1 = d1;
51 this.d2 = d2;
52 this.expected = expected;
53 }
54
55 @Override public String toString() {
59
60 public DeclarationTest(Data data) {
61 this.data = data;
62 }
63 private final Data data;
64
65
66 @Parameters
67 public static Collection data() {
68
69 int n = 0;
70 final int GI = n++; // green inline
71 final int YI = n++; // yellow inline
72 final int GA1 = n++; // green author 1
73 final int YA1 = n++; // yellow author 1
74 final int GA2 = n++; // green author 2
75 final int YA2 = n++; // yellow author 2
76
77 final Declaration[] DECLS = new Declaration[n];
78
79 Stylesheet inlineSS = new Stylesheet() {
80 {
81 setOrigin(StyleOrigin.INLINE);
82
83 DECLS[GI] = new Declaration("-fx-base", new ParsedValueImpl<Color,Color>(Color.GREEN, null), false);
84 DECLS[YI] = new Declaration("-fx-color", new ParsedValueImpl<Color,Color>(Color.YELLOW, null), false);
85
86 Collections.addAll(getRules(),
87 new Rule(Arrays.asList(SimpleSelector.getUniversalSelector()), Arrays.asList(DECLS[GI])),
88 new Rule(Arrays.asList(SimpleSelector.getUniversalSelector()), Arrays.asList(DECLS[YI]))
89 );
90 }
91 };
92
93 Stylesheet authorSS_1 = new Stylesheet() {
94 {
95 setOrigin(StyleOrigin.AUTHOR);
96
97 DECLS[GA1] = new Declaration("-fx-base", new ParsedValueImpl<Color,Color>(Color.GREEN, null), false);
98 DECLS[YA1] = new Declaration("-fx-color", new ParsedValueImpl<Color,Color>(Color.YELLOW, null), false);
99
100 Collections.addAll(getRules(),
101 new Rule(Arrays.asList(SimpleSelector.getUniversalSelector()), Arrays.asList(DECLS[GA1])),
102 new Rule(Arrays.asList(SimpleSelector.getUniversalSelector()), Arrays.asList(DECLS[YA1]))
103 );
104 }
105 };
106
107 Stylesheet authorSS_2 = new Stylesheet() {
108 {
109 setOrigin(StyleOrigin.AUTHOR);
110
111 DECLS[GA2] = new Declaration("-fx-base", new ParsedValueImpl<Color,Color>(Color.GREEN, null), false);
112 DECLS[YA2] = new Declaration("-fx-color", new ParsedValueImpl<Color,Color>(Color.YELLOW, null), false);
113
114 Collections.addAll(getRules(),
115 new Rule(Arrays.asList(SimpleSelector.getUniversalSelector()), Arrays.asList(DECLS[GA2])),
116 new Rule(Arrays.asList(SimpleSelector.getUniversalSelector()), Arrays.asList(DECLS[YA2]))
117 );
118 }
119 };
120
121 return Arrays.asList(new Object[] {
122 new Object[] { new Data(DECLS[GA1], DECLS[GA2], true) },
123 new Object[] { new Data(DECLS[GA1], DECLS[YA1], false) },
124 new Object[] { new Data(DECLS[GA1], DECLS[GI], false) }
125 });
126 }
127
128 @Test
129 public void testEquals() {
130
131 Declaration instance = data.d1;
132 Declaration obj = data.d2;
133 boolean expected = data.expected;
134 boolean actual = instance.equals(obj);
135 assertTrue(data.toString(), expected == actual);
136
|
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation. Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
23 * questions.
24 */
25
26 package test.javafx.css;
27
28 import javafx.scene.paint.Color;
29 import com.sun.javafx.css.ParsedValueImpl;
30
31 import java.util.ArrayList;
32 import java.util.Arrays;
33 import java.util.Collection;
34 import java.util.Collections;
35 import java.util.List;
36 import javafx.css.Declaration;
37 import javafx.css.DeclarationShim;
38 import javafx.css.Rule;
39 import javafx.css.RuleShim;
40 import javafx.css.SelectorShim;
41 import javafx.css.StyleOrigin;
42 import javafx.css.Stylesheet;
43 import javafx.css.StylesheetShim;
44 import org.junit.Test;
45 import static org.junit.Assert.*;
46
47 import org.junit.runner.RunWith;
48 import org.junit.runners.Parameterized;
49 import org.junit.runners.Parameterized.Parameters;
50
51 @RunWith(Parameterized.class)
52 public class DeclarationTest {
53
54 private static class Data {
55 private final Declaration d1, d2;
56 private final boolean expected;
57 Data(Declaration d1, Declaration d2, boolean expected){
58 this.d1 = d1;
59 this.d2 = d2;
60 this.expected = expected;
61 }
62
63 @Override public String toString() {
67
68 public DeclarationTest(Data data) {
69 this.data = data;
70 }
71 private final Data data;
72
73
74 @Parameters
75 public static Collection data() {
76
77 int n = 0;
78 final int GI = n++; // green inline
79 final int YI = n++; // yellow inline
80 final int GA1 = n++; // green author 1
81 final int YA1 = n++; // yellow author 1
82 final int GA2 = n++; // green author 2
83 final int YA2 = n++; // yellow author 2
84
85 final Declaration[] DECLS = new Declaration[n];
86
87 Stylesheet inlineSS = new StylesheetShim() {
88 {
89 setOrigin(StyleOrigin.INLINE);
90
91 DECLS[GI] = DeclarationShim.getDeclaration("-fx-base", new ParsedValueImpl<Color,Color>(Color.GREEN, null), false);
92 DECLS[YI] = DeclarationShim.getDeclaration("-fx-color", new ParsedValueImpl<Color,Color>(Color.YELLOW, null), false);
93
94 Collections.addAll(getRules(),
95 RuleShim.getRule(Arrays.asList(SelectorShim.getUniversalSelector()), Arrays.asList(DECLS[GI])),
96 RuleShim.getRule(Arrays.asList(SelectorShim.getUniversalSelector()), Arrays.asList(DECLS[YI]))
97 );
98 }
99 };
100
101 Stylesheet authorSS_1 = new StylesheetShim() {
102 {
103 setOrigin(StyleOrigin.AUTHOR);
104
105 DECLS[GA1] = DeclarationShim.getDeclaration("-fx-base", new ParsedValueImpl<Color,Color>(Color.GREEN, null), false);
106 DECLS[YA1] = DeclarationShim.getDeclaration("-fx-color", new ParsedValueImpl<Color,Color>(Color.YELLOW, null), false);
107
108 Collections.addAll(getRules(),
109 RuleShim.getRule(Arrays.asList(SelectorShim.getUniversalSelector()), Arrays.asList(DECLS[GA1])),
110 RuleShim.getRule(Arrays.asList(SelectorShim.getUniversalSelector()), Arrays.asList(DECLS[YA1]))
111 );
112 }
113 };
114
115 Stylesheet authorSS_2 = new StylesheetShim() {
116 {
117 setOrigin(StyleOrigin.AUTHOR);
118
119 DECLS[GA2] = DeclarationShim.getDeclaration("-fx-base", new ParsedValueImpl<Color,Color>(Color.GREEN, null), false);
120 DECLS[YA2] = DeclarationShim.getDeclaration("-fx-color", new ParsedValueImpl<Color,Color>(Color.YELLOW, null), false);
121
122 Collections.addAll(getRules(),
123 RuleShim.getRule(Arrays.asList(SelectorShim.getUniversalSelector()), Arrays.asList(DECLS[GA2])),
124 RuleShim.getRule(Arrays.asList(SelectorShim.getUniversalSelector()), Arrays.asList(DECLS[YA2]))
125 );
126 }
127 };
128
129 return Arrays.asList(new Object[] {
130 new Object[] { new Data(DECLS[GA1], DECLS[GA2], true) },
131 new Object[] { new Data(DECLS[GA1], DECLS[YA1], false) },
132 new Object[] { new Data(DECLS[GA1], DECLS[GI], false) }
133 });
134 }
135
136 @Test
137 public void testEquals() {
138
139 Declaration instance = data.d1;
140 Declaration obj = data.d2;
141 boolean expected = data.expected;
142 boolean actual = instance.equals(obj);
143 assertTrue(data.toString(), expected == actual);
144
|