| 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 |
|
| 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 |
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 |
} |