Debian Codegraph @

src/test/java/ezvcard/io/scribe/OrganizationScribeTest.java

raw symbols SCIP
1 package ezvcard.io.scribe;
2
3 import static ezvcard.VCardVersion.V2_1;
4 import static ezvcard.VCardVersion.V3_0;
5 import static ezvcard.VCardVersion.V4_0;
6
7 import org.junit.Test;
8
9 import ezvcard.io.json.JCardValue;
10 import ezvcard.property.Organization;
11
12 /*
13 Copyright (c) 2012-2023, Michael Angstadt
14 All rights reserved.
15
16 Redistribution and use in source and binary forms, with or without
17 modification, are permitted provided that the following conditions are met:
18
19 1. Redistributions of source code must retain the above copyright notice, this
20 list of conditions and the following disclaimer.
21 2. Redistributions in binary form must reproduce the above copyright notice,
22 this list of conditions and the following disclaimer in the documentation
23 and/or other materials provided with the distribution.
24
25 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
26 ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
27 WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
28 DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
29 ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
30 (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
31 LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
32 ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
33 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
34 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
35
36 The views and conclusions contained in the software and documentation are those
37 of the authors and should not be interpreted as representing official policies,
38 either expressed or implied, of the FreeBSD Project.
39 */
40
41 /**
42 * @author Michael Angstadt
43 */
44 public class OrganizationScribeTest {
45 private final OrganizationScribe scribe = new OrganizationScribe();
46 private final Sensei<Organization> sensei = new Sensei<>(scribe);
47
48 private final Organization withOneValue = new Organization();
49 {
50 withOneValue.getValues().add("one,two;three");
51 }
52
53 private final Organization withMultipleValues = new Organization(withOneValue);
54 {
55 withMultipleValues.getValues().add("four");
56 }
57
58 private final Organization empty = new Organization();
59
60 @Test
61 public void writeText() {
62 sensei.assertWriteText(withOneValue).versions(V2_1).run("one,two\\;three");
63 sensei.assertWriteText(withOneValue).versions(V3_0, V4_0).run("one\\,two\\;three");
64 sensei.assertWriteText(withMultipleValues).versions(V2_1).run("one,two\\;three;four");
65 sensei.assertWriteText(withMultipleValues).versions(V3_0, V4_0).run("one\\,two\\;three;four");
66 sensei.assertWriteText(empty).run("");
67 }
68
69 @Test
70 public void writeXml() {
71 sensei.assertWriteXml(withOneValue).run("<text>one,two;three</text>");
72 sensei.assertWriteXml(withMultipleValues).run("<text>one,two;three</text><text>four</text>");
73 sensei.assertWriteXml(empty).run("<text/>");
74 }
75
76 @Test
77 public void writeJson() {
78 sensei.assertWriteJson(withOneValue).run("one,two;three");
79 sensei.assertWriteJson(withMultipleValues).run(JCardValue.structured("one,two;three", "four"));
80 sensei.assertWriteJson(empty).run("");
81 }
82
83 @Test
84 public void parseText() {
85 sensei.assertParseText("one\\,two\\;three").run(withOneValue);
86 sensei.assertParseText("one\\,two\\;three;four").run(withMultipleValues);
87 sensei.assertParseText("").run(empty);
88 }
89
90 @Test
91 public void parseXml() {
92 sensei.assertParseXml("<text>one,two;three</text>").run(withOneValue);
93 sensei.assertParseXml("<text>one,two;three</text><text>four</text>").run(withMultipleValues);
94 sensei.assertParseXml("").cannotParse(0);
95 }
96
97 @Test
98 public void parseHtml() {
99 //@formatter:off
100 sensei.assertParseHtml(
101 "<div>" +
102 "<span class=\"organization-name\">one,two;three</span>" +
103 "<span class=\"organization-unit\">four</span>" +
104 "</div>"
105 ).run(withMultipleValues);
106
107 sensei.assertParseHtml(
108 "<div>" +
109 "<span class=\"organization-name\">one,two;three</span>" +
110 "</div>"
111 ).run(withOneValue);
112
113 Organization withUnit = new Organization(withMultipleValues);
114 withUnit.getValues().remove(0);
115 sensei.assertParseHtml(
116 "<div>" +
117 "<span class=\"organization-unit\">four</span>" +
118 "</div>"
119 ).run(withUnit);
120
121 Organization withTextContent = new Organization();
122 withTextContent.getValues().add("name");
123 sensei.assertParseHtml(
124 "<div>name</div>"
125 ).run(withTextContent);
126
127 sensei.assertParseHtml(
128 "<div>" +
129 "</div>"
130 ).run(empty);
131 //@formatter:on
132 }
133
134 @Test
135 public void parseJson() {
136 sensei.assertParseJson("one,two;three").run(withOneValue);
137 sensei.assertParseJson(JCardValue.structured("one,two;three")).run(withOneValue);
138 sensei.assertParseJson(JCardValue.structured("one,two;three", "four")).run(withMultipleValues);
139 sensei.assertParseJson("").run(empty);
140 }
141 }