-
-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathPropteryTest.java
More file actions
176 lines (151 loc) · 5.99 KB
/
PropteryTest.java
File metadata and controls
176 lines (151 loc) · 5.99 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
/*
* Copyright (c) 2019-2024 Ronald Brill.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.htmlunit.cssparser.dom;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertNull;
import static org.junit.jupiter.api.Assertions.assertTrue;
import org.htmlunit.cssparser.parser.LexicalUnit;
import org.htmlunit.cssparser.parser.LexicalUnitImpl;
import org.junit.jupiter.api.Test;
/**
* Unit tests for {@link Property}.
*
* @author Ronald Brill
*/
public class PropteryTest {
/**
* @throws Exception if any error occurs
*/
@Test
public void defaultConstructor() throws Exception {
final Property prop = new Property(null, null, false);
assertEquals("null", prop.toString());
assertNull(prop.getName());
assertNull(prop.getValue());
assertFalse(prop.isImportant());
prop.setName("MyName");
assertEquals("MyName", prop.toString());
assertEquals("MyName", prop.getName());
assertNull(prop.getValue());
assertFalse(prop.isImportant());
LexicalUnit lu = LexicalUnitImpl.createString(null, "MyValue");
prop.setValue(new CSSValueImpl(lu, true));
assertEquals("MyName: \"MyValue\"", prop.toString());
assertEquals("MyName", prop.getName());
assertEquals("\"MyValue\"", prop.getValue().toString());
assertFalse(prop.isImportant());
lu = LexicalUnitImpl.createPixel(null, 11);
prop.setValue(new CSSValueImpl(lu, true));
assertEquals("MyName: 11px", prop.toString());
assertEquals("MyName", prop.getName());
assertEquals("11px", prop.getValue().toString());
assertFalse(prop.isImportant());
prop.setImportant(true);
assertEquals("MyName: 11px !important", prop.toString());
assertEquals("MyName", prop.getName());
assertEquals("11px", prop.getValue().toString());
assertTrue(prop.isImportant());
}
/**
* @throws Exception if any error occurs
*/
@Test
public void defaultConstructorNoValueImportant() throws Exception {
final Property prop = new Property(null, null, false);
prop.setName("MyName");
prop.setImportant(true);
assertEquals("MyName !important", prop.toString());
assertEquals("MyName", prop.getName());
assertNull(prop.getValue());
assertTrue(prop.isImportant());
}
/**
* @throws Exception if any error occurs
*/
@Test
public void constructWithParams() throws Exception {
final LexicalUnit lu = LexicalUnitImpl.createCentimeter(null, 13.2);
final Property prop = new Property("MyName", new CSSValueImpl(lu, true), false);
assertEquals("MyName: 13.2cm", prop.toString());
assertEquals("MyName", prop.getName());
assertEquals("13.2cm", prop.getValue().toString());
assertFalse(prop.isImportant());
}
/**
* Test equals method with same object.
* @throws Exception if any error occurs
*/
@Test
public void equalsSameObject() throws Exception {
final LexicalUnit lu = LexicalUnitImpl.createPixel(null, 10);
final Property prop = new Property("color", new CSSValueImpl(lu, true), false);
assertTrue(prop.equals(prop));
}
/**
* Test equals method with different names.
* @throws Exception if any error occurs
*/
@Test
public void equalsDifferentNames() throws Exception {
final LexicalUnit lu1 = LexicalUnitImpl.createPixel(null, 10);
final Property prop1 = new Property("color", new CSSValueImpl(lu1, true), false);
final LexicalUnit lu2 = LexicalUnitImpl.createPixel(null, 10);
final Property prop2 = new Property("background", new CSSValueImpl(lu2, true), false);
assertFalse(prop1.equals(prop2));
}
/**
* Test equals method with different important flags.
* @throws Exception if any error occurs
*/
@Test
public void equalsDifferentImportant() throws Exception {
final Property prop1 = new Property("color", null, false);
final Property prop2 = new Property("color", null, true);
assertFalse(prop1.equals(prop2));
}
/**
* Test equals method with null.
* @throws Exception if any error occurs
*/
@Test
public void equalsWithNull() throws Exception {
final LexicalUnit lu = LexicalUnitImpl.createPixel(null, 10);
final Property prop = new Property("color", new CSSValueImpl(lu, true), false);
assertFalse(prop.equals(null));
}
/**
* Test equals method with different class.
* @throws Exception if any error occurs
*/
@Test
public void equalsWithDifferentClass() throws Exception {
final LexicalUnit lu = LexicalUnitImpl.createPixel(null, 10);
final Property prop = new Property("color", new CSSValueImpl(lu, true), false);
assertFalse(prop.equals("not a property"));
}
/**
* Test hashCode consistency.
* @throws Exception if any error occurs
*/
@Test
public void hashCodeConsistency() throws Exception {
final LexicalUnit lu = LexicalUnitImpl.createPixel(null, 10);
final Property prop = new Property("color", new CSSValueImpl(lu, true), false);
final int hash1 = prop.hashCode();
final int hash2 = prop.hashCode();
assertEquals(hash1, hash2);
}
}