Skip to content

Commit aa468ca

Browse files
author
Kate Ivanova
committed
Improve test coverage for StopSvgNodeRenderer class
DEVSIX-4828
1 parent c009330 commit aa468ca

File tree

1 file changed

+303
-0
lines changed

1 file changed

+303
-0
lines changed
Lines changed: 303 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,303 @@
1+
/*
2+
This file is part of the iText (R) project.
3+
Copyright (c) 1998-2020 iText Group NV
4+
Authors: iText Software.
5+
6+
This program is free software; you can redistribute it and/or modify
7+
it under the terms of the GNU Affero General Public License version 3
8+
as published by the Free Software Foundation with the addition of the
9+
following permission added to Section 15 as permitted in Section 7(a):
10+
FOR ANY PART OF THE COVERED WORK IN WHICH THE COPYRIGHT IS OWNED BY
11+
ITEXT GROUP. ITEXT GROUP DISCLAIMS THE WARRANTY OF NON INFRINGEMENT
12+
OF THIRD PARTY RIGHTS
13+
14+
This program is distributed in the hope that it will be useful, but
15+
WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
16+
or FITNESS FOR A PARTICULAR PURPOSE.
17+
See the GNU Affero General Public License for more details.
18+
You should have received a copy of the GNU Affero General Public License
19+
along with this program; if not, see http://www.gnu.org/licenses or write to
20+
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
21+
Boston, MA, 02110-1301 USA, or download the license from the following URL:
22+
http://itextpdf.com/terms-of-use/
23+
24+
The interactive user interfaces in modified source and object code versions
25+
of this program must display Appropriate Legal Notices, as required under
26+
Section 5 of the GNU Affero General Public License.
27+
28+
In accordance with Section 7(b) of the GNU Affero General Public License,
29+
a covered work must retain the producer line in every PDF that is created
30+
or manipulated using iText.
31+
32+
You can be released from the requirements of the license by purchasing
33+
a commercial license. Buying such a license is mandatory as soon as you
34+
develop commercial activities involving the iText software without
35+
disclosing the source code of your own applications.
36+
These activities include: offering paid services to customers as an ASP,
37+
serving PDFs on the fly in a web application, shipping iText with a closed
38+
source product.
39+
40+
For more information, please contact iText Software Corp. at this
41+
42+
*/
43+
package com.itextpdf.svg.renderers.impl;
44+
45+
import com.itextpdf.svg.SvgConstants.Attributes;
46+
import com.itextpdf.svg.SvgConstants.Tags;
47+
import com.itextpdf.svg.renderers.ISvgNodeRenderer;
48+
import com.itextpdf.svg.renderers.SvgDrawContext;
49+
import com.itextpdf.test.ExtendedITextTest;
50+
import com.itextpdf.test.annotations.type.UnitTest;
51+
52+
import java.util.HashMap;
53+
import java.util.Map;
54+
import org.junit.Assert;
55+
import org.junit.Rule;
56+
import org.junit.Test;
57+
import org.junit.experimental.categories.Category;
58+
import org.junit.rules.ExpectedException;
59+
60+
@Category(UnitTest.class)
61+
public class StopSvgNodeRendererUnitTest extends ExtendedITextTest {
62+
private static final float DELTA = 0;
63+
64+
@Rule
65+
public ExpectedException junitExpectedException = ExpectedException.none();
66+
67+
@Test
68+
public void getOffsetPercentageValueTest() {
69+
Map<String, String> styles = new HashMap<>();
70+
styles.put(Attributes.OFFSET, "50%");
71+
72+
StopSvgNodeRenderer renderer = new StopSvgNodeRenderer();
73+
renderer.setAttributesAndStyles(styles);
74+
75+
double expected = 0.5;
76+
77+
Assert.assertEquals(expected, renderer.getOffset(), DELTA);
78+
}
79+
80+
@Test
81+
public void getOffsetNumericValueTest() {
82+
Map<String, String> styles = new HashMap<>();
83+
styles.put(Attributes.OFFSET, "0.5");
84+
85+
StopSvgNodeRenderer renderer = new StopSvgNodeRenderer();
86+
renderer.setAttributesAndStyles(styles);
87+
88+
double expected = 0.5;
89+
90+
Assert.assertEquals(expected, renderer.getOffset(), DELTA);
91+
}
92+
93+
@Test
94+
public void getOffsetMoreThanOneValueTest() {
95+
Map<String, String> styles = new HashMap<>();
96+
styles.put(Attributes.OFFSET, "2");
97+
98+
StopSvgNodeRenderer renderer = new StopSvgNodeRenderer();
99+
renderer.setAttributesAndStyles(styles);
100+
101+
double expected = 1;
102+
103+
Assert.assertEquals(expected, renderer.getOffset(), DELTA);
104+
}
105+
106+
@Test
107+
public void getOffsetLessThanZeroValueTest() {
108+
Map<String, String> styles = new HashMap<>();
109+
styles.put(Attributes.OFFSET, "-2");
110+
111+
StopSvgNodeRenderer renderer = new StopSvgNodeRenderer();
112+
renderer.setAttributesAndStyles(styles);
113+
114+
double expected = 0;
115+
116+
Assert.assertEquals(expected, renderer.getOffset(), DELTA);
117+
}
118+
119+
@Test
120+
public void getOffsetNoneValueTest() {
121+
Map<String, String> styles = new HashMap<>();
122+
styles.put(Attributes.OFFSET, null);
123+
124+
StopSvgNodeRenderer renderer = new StopSvgNodeRenderer();
125+
renderer.setAttributesAndStyles(styles);
126+
127+
double expected = 0;
128+
129+
Assert.assertEquals(expected, renderer.getOffset(), DELTA);
130+
}
131+
132+
@Test
133+
public void getOffsetRandomStringValueTest() {
134+
Map<String, String> styles = new HashMap<>();
135+
styles.put(Attributes.OFFSET, "Hello");
136+
137+
StopSvgNodeRenderer renderer = new StopSvgNodeRenderer();
138+
renderer.setAttributesAndStyles(styles);
139+
140+
double expected = 0;
141+
142+
Assert.assertEquals(expected, renderer.getOffset(), DELTA);
143+
}
144+
145+
@Test
146+
public void getOffsetEmptyStringValueTest() {
147+
Map<String, String> styles = new HashMap<>();
148+
styles.put(Attributes.OFFSET, "");
149+
150+
StopSvgNodeRenderer renderer = new StopSvgNodeRenderer();
151+
renderer.setAttributesAndStyles(styles);
152+
153+
double expected = 0;
154+
155+
Assert.assertEquals(expected, renderer.getOffset(), DELTA);
156+
}
157+
158+
@Test
159+
public void getStopColorTest() {
160+
Map<String, String> styles = new HashMap<>();
161+
styles.put(Tags.STOP_COLOR, "red");
162+
163+
StopSvgNodeRenderer renderer = new StopSvgNodeRenderer();
164+
renderer.setAttributesAndStyles(styles);
165+
166+
float[] expected = {1, 0, 0, 1};
167+
float[] actual = renderer.getStopColor();
168+
169+
Assert.assertArrayEquals(expected, actual, DELTA);
170+
}
171+
172+
@Test
173+
public void getStopColorNoneValueTest() {
174+
Map<String, String> styles = new HashMap<>();
175+
styles.put(Tags.STOP_COLOR, null);
176+
177+
StopSvgNodeRenderer renderer = new StopSvgNodeRenderer();
178+
renderer.setAttributesAndStyles(styles);
179+
180+
float[] expected = {0, 0, 0, 1};
181+
float[] actual = renderer.getStopColor();
182+
183+
Assert.assertArrayEquals(expected, actual, DELTA);
184+
}
185+
186+
@Test
187+
public void getStopColorRandomStringValueTest() {
188+
Map<String, String> styles = new HashMap<>();
189+
styles.put(Tags.STOP_COLOR, "Hello");
190+
191+
StopSvgNodeRenderer renderer = new StopSvgNodeRenderer();
192+
renderer.setAttributesAndStyles(styles);
193+
194+
float[] expected = {0, 0, 0, 1};
195+
float[] actual = renderer.getStopColor();
196+
197+
Assert.assertArrayEquals(expected, actual, DELTA);
198+
}
199+
200+
@Test
201+
public void getStopColorEmptyStringTest() {
202+
Map<String, String> styles = new HashMap<>();
203+
styles.put(Tags.STOP_COLOR, "");
204+
205+
StopSvgNodeRenderer renderer = new StopSvgNodeRenderer();
206+
renderer.setAttributesAndStyles(styles);
207+
208+
float[] expected = {0, 0, 0, 1};
209+
float[] actual = renderer.getStopColor();
210+
211+
Assert.assertArrayEquals(expected, actual, DELTA);
212+
}
213+
214+
@Test
215+
public void getStopColorOpacityTest() {
216+
Map<String, String> styles = new HashMap<>();
217+
styles.put(Tags.STOP_COLOR, "rgba(0.5, 0.5, 0.5, 0.5)");
218+
219+
StopSvgNodeRenderer renderer = new StopSvgNodeRenderer();
220+
renderer.setAttributesAndStyles(styles);
221+
222+
float[] expected = {0, 0, 0, 1};
223+
float[] actual = renderer.getStopColor();
224+
225+
Assert.assertArrayEquals(expected, actual, DELTA);
226+
}
227+
228+
@Test
229+
public void getStopOpacityTest() {
230+
Map<String, String> styles = new HashMap<>();
231+
styles.put(Tags.STOP_OPACITY, "1");
232+
233+
StopSvgNodeRenderer renderer = new StopSvgNodeRenderer();
234+
renderer.setAttributesAndStyles(styles);
235+
236+
float expected = 1;
237+
238+
Assert.assertEquals(expected, renderer.getStopOpacity(), DELTA);
239+
}
240+
241+
@Test
242+
public void getStopOpacityNoneValueTest() {
243+
Map<String, String> styles = new HashMap<>();
244+
styles.put(Tags.STOP_OPACITY, null);
245+
246+
StopSvgNodeRenderer renderer = new StopSvgNodeRenderer();
247+
renderer.setAttributesAndStyles(styles);
248+
249+
float expected = 1;
250+
251+
Assert.assertEquals(expected, renderer.getStopOpacity(), DELTA);
252+
}
253+
254+
@Test
255+
public void getStopOpacityRandomStringValueTest() {
256+
Map<String, String> styles = new HashMap<>();
257+
styles.put(Tags.STOP_OPACITY, "Hello");
258+
259+
StopSvgNodeRenderer renderer = new StopSvgNodeRenderer();
260+
renderer.setAttributesAndStyles(styles);
261+
262+
float expected = 1;
263+
264+
Assert.assertEquals(expected, renderer.getStopOpacity(), DELTA);
265+
}
266+
267+
@Test
268+
public void getStopOpacityEmptyStringTest() {
269+
Map<String, String> styles = new HashMap<>();
270+
styles.put(Tags.STOP_OPACITY, "");
271+
272+
StopSvgNodeRenderer renderer = new StopSvgNodeRenderer();
273+
renderer.setAttributesAndStyles(styles);
274+
275+
float expected = 1;
276+
277+
Assert.assertEquals(expected, renderer.getStopOpacity(), DELTA);
278+
}
279+
280+
@Test
281+
public void createDeepCopyTest() {
282+
Map<String, String> styles = new HashMap<>();
283+
styles.put(Attributes.OFFSET, "0.5");
284+
285+
StopSvgNodeRenderer renderer = new StopSvgNodeRenderer();
286+
renderer.setAttributesAndStyles(styles);
287+
288+
ISvgNodeRenderer copy = renderer.createDeepCopy();
289+
290+
Assert.assertNotSame(renderer, copy);
291+
Assert.assertEquals(renderer.getClass(), copy.getClass());
292+
Assert.assertEquals(renderer.getAttributeMapCopy(), copy.getAttributeMapCopy());
293+
}
294+
295+
@Test
296+
public void doDrawTest() {
297+
StopSvgNodeRenderer renderer = new StopSvgNodeRenderer();
298+
299+
junitExpectedException.expect(UnsupportedOperationException.class);
300+
junitExpectedException.expectMessage("Can't draw current SvgNodeRenderer.");
301+
renderer.doDraw(new SvgDrawContext(null, null));
302+
}
303+
}

0 commit comments

Comments
 (0)