Debian Codegraph @

src/test/java/ezvcard/io/xml/XCardOutputPropertiesTest.java

raw symbols SCIP
1 package ezvcard.io.xml;
2
3 import static org.junit.Assert.assertEquals;
4 import static org.junit.Assert.assertNull;
5
6 import java.util.HashMap;
7 import java.util.Map;
8
9 import javax.xml.transform.OutputKeys;
10
11 import org.junit.Test;
12
13 /*
14 Copyright (c) 2012-2023, Michael Angstadt
15 All rights reserved.
16
17 Redistribution and use in source and binary forms, with or without
18 modification, are permitted provided that the following conditions are met:
19
20 1. Redistributions of source code must retain the above copyright notice, this
21 list of conditions and the following disclaimer.
22 2. Redistributions in binary form must reproduce the above copyright notice,
23 this list of conditions and the following disclaimer in the documentation
24 and/or other materials provided with the distribution.
25
26 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
27 ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
28 WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
29 DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
30 ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
31 (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
32 LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
33 ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
34 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
35 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
36
37 The views and conclusions contained in the software and documentation are those
38 of the authors and should not be interpreted as representing official policies,
39 either expressed or implied, of the FreeBSD Project.
40 */
41
42 /**
43 * @author Michael Angstadt
44 */
45 public class XCardOutputPropertiesTest {
46 private static final String INDENT_AMT = "{http://xml.apache.org/xslt}indent-amount";
47
48 @Test
49 public void constructor_empty() {
50 XCardOutputProperties properties = new XCardOutputProperties();
51
52 Map<String, String> expected = new HashMap<>();
53 expected.put(OutputKeys.METHOD, "xml");
54
55 assertEquals(expected, properties);
56 }
57
58 @Test
59 public void constructor() {
60 XCardOutputProperties properties = new XCardOutputProperties(1, "1.1");
61
62 Map<String, String> expected = new HashMap<>();
63 expected.put(OutputKeys.METHOD, "xml");
64 expected.put(OutputKeys.INDENT, "yes");
65 expected.put(INDENT_AMT, "1");
66 expected.put(OutputKeys.VERSION, "1.1");
67
68 assertEquals(expected, properties);
69 }
70
71 @Test(expected = IllegalArgumentException.class)
72 public void constructor_negative_indent() {
73 new XCardOutputProperties(-1, "1.1");
74 }
75
76 @Test
77 public void setIndent() {
78 XCardOutputProperties properties = new XCardOutputProperties();
79 properties.setIndent(1);
80
81 Map<String, String> expected = new HashMap<>();
82 expected.put(OutputKeys.METHOD, "xml");
83 expected.put(OutputKeys.INDENT, "yes");
84 expected.put(INDENT_AMT, "1");
85
86 assertEquals(expected, properties);
87 }
88
89 @Test
90 public void setIndent_remove() {
91 XCardOutputProperties properties = new XCardOutputProperties();
92 properties.setIndent(1);
93 properties.setIndent(null);
94
95 Map<String, String> expected = new HashMap<>();
96 expected.put(OutputKeys.METHOD, "xml");
97
98 assertEquals(expected, properties);
99 }
100
101 @Test(expected = IllegalArgumentException.class)
102 public void setIndent_negative() {
103 XCardOutputProperties properties = new XCardOutputProperties();
104 properties.setIndent(-1);
105 }
106
107 @Test
108 public void getIndent() {
109 XCardOutputProperties properties = new XCardOutputProperties();
110
111 assertNull(properties.getIndent());
112
113 properties.put(INDENT_AMT, "1");
114 assertNull(properties.getIndent());
115
116 properties.put(OutputKeys.INDENT, "no");
117 assertNull(properties.getIndent());
118
119 properties.put(OutputKeys.INDENT, "YES");
120 assertNull(properties.getIndent());
121
122 properties.put(OutputKeys.INDENT, "FOO");
123 assertNull(properties.getIndent());
124
125 properties.put(OutputKeys.INDENT, "yes");
126 assertEquals(Integer.valueOf(1), properties.getIndent());
127
128 properties.remove(INDENT_AMT);
129 assertNull(properties.getIndent());
130 }
131
132 @Test(expected = NumberFormatException.class)
133 public void getIndent_not_an_integer() {
134 XCardOutputProperties properties = new XCardOutputProperties();
135 properties.put(OutputKeys.INDENT, "yes");
136 properties.put(INDENT_AMT, "foo");
137 properties.getIndent();
138 }
139
140 @Test
141 public void setXmlVersion() {
142 XCardOutputProperties properties = new XCardOutputProperties();
143 properties.setXmlVersion("1.1");
144
145 Map<String, String> expected = new HashMap<>();
146 expected.put(OutputKeys.METHOD, "xml");
147 expected.put(OutputKeys.VERSION, "1.1");
148
149 assertEquals(expected, properties);
150 }
151
152 @Test
153 public void setXmlVersion_remove() {
154 XCardOutputProperties properties = new XCardOutputProperties();
155 properties.setXmlVersion("1.1");
156 properties.setXmlVersion(null);
157
158 Map<String, String> expected = new HashMap<>();
159 expected.put(OutputKeys.METHOD, "xml");
160
161 assertEquals(expected, properties);
162 }
163
164 @Test
165 public void getXmlVersion() {
166 XCardOutputProperties properties = new XCardOutputProperties();
167 assertNull(properties.getXmlVersion());
168
169 properties.setXmlVersion("1.1");
170 assertEquals("1.1", properties.getXmlVersion());
171 }
172 }