Debian Codegraph @

src/test/java/ezvcard/property/RelatedTest.java

raw symbols SCIP
1 package ezvcard.property;
2
3 import static ezvcard.property.PropertySensei.assertCopy;
4 import static ezvcard.property.PropertySensei.assertEqualsMethod;
5 import static ezvcard.property.PropertySensei.assertNothingIsEqual;
6 import static ezvcard.property.PropertySensei.assertValidate;
7 import static org.junit.Assert.assertEquals;
8 import static org.junit.Assert.assertFalse;
9 import static org.junit.Assert.assertNull;
10
11 import java.util.ArrayList;
12 import java.util.Arrays;
13 import java.util.List;
14
15 import org.junit.Test;
16
17 import ezvcard.VCardVersion;
18 import ezvcard.parameter.RelatedType;
19 import ezvcard.util.TelUri;
20
21 /*
22 Copyright (c) 2012-2023, Michael Angstadt
23 All rights reserved.
24
25 Redistribution and use in source and binary forms, with or without
26 modification, are permitted provided that the following conditions are met:
27
28 1. Redistributions of source code must retain the above copyright notice, this
29 list of conditions and the following disclaimer.
30 2. Redistributions in binary form must reproduce the above copyright notice,
31 this list of conditions and the following disclaimer in the documentation
32 and/or other materials provided with the distribution.
33
34 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
35 ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
36 WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
37 DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
38 ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
39 (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
40 LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
41 ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
42 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
43 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
44
45 The views and conclusions contained in the software and documentation are those
46 of the authors and should not be interpreted as representing official policies,
47 either expressed or implied, of the FreeBSD Project.
48 */
49
50 /**
51 * @author Michael Angstadt
52 */
53 public class RelatedTest {
54 private final String text = "Edna Smith";
55 private final String uri = "urn:uuid:03a0e51f-d1aa-4385-8a53-e29025acd8af";
56
57 @Test
58 public void constructors() throws Exception {
59 Related property = new Related();
60 assertNull(property.getUri());
61 assertNull(property.getText());
62 assertEquals(Arrays.asList(), property.getTypes());
63
64 property = new Related(uri);
65 assertEquals(uri, property.getUri());
66 assertNull(property.getText());
67 assertEquals(Arrays.asList(), property.getTypes());
68 }
69
70 @Test
71 public void set_value() {
72 Related property = new Related(uri);
73
74 property.setText(text);
75 assertNull(property.getUri());
76 assertEquals(text, property.getText());
77 assertEquals(Arrays.asList(), property.getTypes());
78
79 property.setUri(uri);
80 assertEquals(uri, property.getUri());
81 assertNull(property.getText());
82 assertEquals(Arrays.asList(), property.getTypes());
83
84 property.getTypes().add(RelatedType.ACQUAINTANCE);
85 assertEquals(uri, property.getUri());
86 assertNull(property.getText());
87 assertEquals(Arrays.asList(RelatedType.ACQUAINTANCE), property.getTypes());
88
89 property.getTypes().add(RelatedType.AGENT);
90 assertEquals(uri, property.getUri());
91 assertNull(property.getText());
92 assertEquals(Arrays.asList(RelatedType.ACQUAINTANCE, RelatedType.AGENT), property.getTypes());
93
94 property.getTypes().remove(RelatedType.AGENT);
95 assertEquals(uri, property.getUri());
96 assertNull(property.getText());
97 assertEquals(Arrays.asList(RelatedType.ACQUAINTANCE), property.getTypes());
98 }
99
100 @Test
101 public void validate() {
102 Related empty = new Related();
103 assertValidate(empty).versions(VCardVersion.V2_1).run(2, 8);
104 assertValidate(empty).versions(VCardVersion.V3_0).run(2, 8);
105 assertValidate(empty).versions(VCardVersion.V4_0).run(8);
106
107 Related withText = new Related();
108 withText.setText(text);
109 assertValidate(withText).versions(VCardVersion.V2_1).run(2);
110 assertValidate(withText).versions(VCardVersion.V3_0).run(2);
111 assertValidate(withText).versions(VCardVersion.V4_0).run();
112
113 Related withUri = new Related();
114 withUri.setUri(uri);
115 assertValidate(withUri).versions(VCardVersion.V2_1).run(2);
116 assertValidate(withUri).versions(VCardVersion.V3_0).run(2);
117 assertValidate(withUri).versions(VCardVersion.V4_0).run();
118 }
119
120 @Test
121 public void email() {
122 Related property = Related.email("[email protected]");
123 assertNull(property.getText());
124 assertEquals("mailto:[email protected]", property.getUri());
125 }
126
127 @Test
128 public void im() {
129 Related property = Related.im("aim", "john.doe");
130 assertNull(property.getText());
131 assertEquals("aim:john.doe", property.getUri());
132 }
133
134 @Test
135 public void telephone() {
136 Related property = Related.telephone(new TelUri.Builder("+1-555-555-5555").build());
137 assertNull(property.getText());
138 assertEquals("tel:+1-555-555-5555", property.getUri());
139 }
140
141 @Test
142 public void toStringValues() {
143 Related property = new Related(uri);
144 assertFalse(property.toStringValues().isEmpty());
145 }
146
147 @Test
148 public void copy() {
149 Related original = new Related();
150 assertCopy(original);
151
152 original = new Related(uri);
153 assertCopy(original);
154
155 original = new Related(uri);
156 original.getTypes().add(RelatedType.ACQUAINTANCE);
157 assertCopy(original);
158
159 original = new Related(uri);
160 original.setText("text");
161 assertCopy(original);
162 }
163
164 @Test
165 public void equals() {
166 List<VCardProperty> properties = new ArrayList<>();
167
168 Related property = new Related();
169 properties.add(property);
170
171 property = new Related("uri");
172 properties.add(property);
173
174 property = new Related("uri");
175 property.getTypes().add(RelatedType.ACQUAINTANCE);
176 properties.add(property);
177
178 property = new Related("uri2");
179 properties.add(property);
180
181 property = new Related();
182 property.setText("text");
183 properties.add(property);
184
185 property = new Related();
186 property.setText("text");
187 property.getTypes().add(RelatedType.ACQUAINTANCE);
188 properties.add(property);
189
190 property = new Related();
191 property.setText("text2");
192 properties.add(property);
193
194 assertNothingIsEqual(properties);
195
196 //@formatter:off
197 assertEqualsMethod(Related.class)
198 .constructor(new Class<?>[]{String.class}, (String)null).test()
199 .constructor("uri")
200 .test()
201 .method("setText", "text").test();
202 //@formatter:on
203 }
204 }