Debian Codegraph @

src/test/java/ezvcard/property/StructuredNameTest.java

raw symbols SCIP
1 package ezvcard.property;
2
3 import static ezvcard.VCardVersion.V2_1;
4 import static ezvcard.VCardVersion.V3_0;
5 import static ezvcard.VCardVersion.V4_0;
6 import static ezvcard.property.PropertySensei.assertCopy;
7 import static ezvcard.property.PropertySensei.assertValidate;
8
9 import java.util.ArrayList;
10 import java.util.Arrays;
11 import java.util.List;
12
13 import org.junit.Test;
14
15 /*
16 Copyright (c) 2012-2023, Michael Angstadt
17 All rights reserved.
18
19 Redistribution and use in source and binary forms, with or without
20 modification, are permitted provided that the following conditions are met:
21
22 1. Redistributions of source code must retain the above copyright notice, this
23 list of conditions and the following disclaimer.
24 2. Redistributions in binary form must reproduce the above copyright notice,
25 this list of conditions and the following disclaimer in the documentation
26 and/or other materials provided with the distribution.
27
28 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
29 ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
30 WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
31 DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
32 ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
33 (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
34 LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
35 ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
36 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
37 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
38
39 The views and conclusions contained in the software and documentation are those
40 of the authors and should not be interpreted as representing official policies,
41 either expressed or implied, of the FreeBSD Project.
42 */
43
44 /**
45 * @author Michael Angstadt
46 */
47 public class StructuredNameTest {
48 @Test
49 public void validate() {
50 //zero values
51 assertValidate(new StructuredName()).versions().run();
52
53 //single values
54 List<StructuredName> properties = new ArrayList<>();
55 {
56 StructuredName property = new StructuredName();
57 property.getAdditionalNames().add("one");
58 properties.add(property);
59
60 property = new StructuredName();
61 property.getPrefixes().add("one");
62 properties.add(property);
63
64 property = new StructuredName();
65 property.getSuffixes().add("one");
66 properties.add(property);
67 }
68 for (StructuredName property : properties) {
69 assertValidate(property).run();
70 }
71
72 //multiple values
73 properties = new ArrayList<>();
74 {
75 StructuredName property = new StructuredName();
76 property.getAdditionalNames().addAll(Arrays.asList("one", "two"));
77 properties.add(property);
78
79 property = new StructuredName();
80 property.getPrefixes().addAll(Arrays.asList("one", "two"));
81 properties.add(property);
82
83 property = new StructuredName();
84 property.getSuffixes().addAll(Arrays.asList("one", "two"));
85 properties.add(property);
86 }
87 for (StructuredName property : properties) {
88 assertValidate(property).versions(V2_1).run(34);
89 assertValidate(property).versions(V3_0, V4_0).run();
90 }
91 }
92
93 @Test
94 public void copy() {
95 StructuredName original = new StructuredName();
96 original.getAdditionalNames().add("one");
97 original.getPrefixes().add("two");
98 original.getSuffixes().add("three");
99
100 //@formatter:off
101 assertCopy(original)
102 .notSame("getAdditionalNames")
103 .notSame("getPrefixes")
104 .notSame("getSuffixes");
105 //@formatter:on
106 }
107 }