Debian Codegraph @

src/test/java/ezvcard/property/ClientPidMapTest.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 ezvcard.util.TestUtils.assertIntEquals;
8 import static org.junit.Assert.assertEquals;
9 import static org.junit.Assert.assertFalse;
10 import static org.junit.Assert.assertNull;
11 import static org.junit.Assert.assertTrue;
12
13 import org.junit.Test;
14
15 import ezvcard.VCardVersion;
16
17 /*
18 Copyright (c) 2012-2023, Michael Angstadt
19 All rights reserved.
20
21 Redistribution and use in source and binary forms, with or without
22 modification, are permitted provided that the following conditions are met:
23
24 1. Redistributions of source code must retain the above copyright notice, this
25 list of conditions and the following disclaimer.
26 2. Redistributions in binary form must reproduce the above copyright notice,
27 this list of conditions and the following disclaimer in the documentation
28 and/or other materials provided with the distribution.
29
30 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
31 ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
32 WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
33 DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
34 ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
35 (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
36 LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
37 ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
38 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
39 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
40
41 The views and conclusions contained in the software and documentation are those
42 of the authors and should not be interpreted as representing official policies,
43 either expressed or implied, of the FreeBSD Project.
44 */
45
46 /**
47 * @author Michael Angstadt
48 */
49 public class ClientPidMapTest {
50 @Test
51 public void constructors() throws Exception {
52 ClientPidMap property = new ClientPidMap(null, null);
53 assertNull(property.getPid());
54 assertNull(property.getUri());
55
56 property = new ClientPidMap(1, "uri");
57 assertIntEquals(1, property.getPid());
58 assertEquals("uri", property.getUri());
59 }
60
61 @Test
62 public void set_value() {
63 ClientPidMap property = new ClientPidMap(1, "uri");
64
65 property.setPid(2);
66 assertIntEquals(2, property.getPid());
67 assertEquals("uri", property.getUri());
68
69 property.setUri("uri2");
70 assertIntEquals(2, property.getPid());
71 assertEquals("uri2", property.getUri());
72
73 property.setPid(null);
74 assertNull(property.getPid());
75 assertEquals("uri2", property.getUri());
76
77 property.setUri(null);
78 assertNull(property.getPid());
79 assertNull(property.getUri());
80 }
81
82 @Test
83 public void random() {
84 ClientPidMap clientpidmap = ClientPidMap.random(2);
85 assertIntEquals(2, clientpidmap.getPid());
86 assertTrue(clientpidmap.getUri().matches("urn:uuid:[-\\da-f]+"));
87 }
88
89 @Test
90 public void validate() {
91 ClientPidMap empty = new ClientPidMap(null, null);
92 assertValidate(empty).versions(VCardVersion.V2_1).run(2, 8);
93 assertValidate(empty).versions(VCardVersion.V3_0).run(2, 8);
94 assertValidate(empty).versions(VCardVersion.V4_0).run(8);
95
96 ClientPidMap withValue = new ClientPidMap(1, "urn:uuid:1234");
97 assertValidate(withValue).versions(VCardVersion.V2_1).run(2);
98 assertValidate(withValue).versions(VCardVersion.V3_0).run(2);
99 assertValidate(withValue).versions(VCardVersion.V4_0).run();
100 }
101
102 @Test
103 public void toStringValues() {
104 ClientPidMap property = new ClientPidMap(1, "uri");
105 assertFalse(property.toStringValues().isEmpty());
106 }
107
108 @Test
109 public void copy() {
110 ClientPidMap original = new ClientPidMap(1, "uri");
111 assertCopy(original);
112 }
113
114 @Test
115 public void equals() {
116 //@formatter:off
117 assertNothingIsEqual(
118 new ClientPidMap(null, null),
119 new ClientPidMap(1, null),
120 new ClientPidMap(2, null),
121 new ClientPidMap(null, "uri"),
122 new ClientPidMap(null, "uri2"),
123 new ClientPidMap(1, "uri"),
124 new ClientPidMap(2, "uri"),
125 new ClientPidMap(1, "uri2")
126 );
127
128 assertEqualsMethod(ClientPidMap.class, 1, "uri")
129 .constructor(new Class<?>[] { Integer.class, String.class }, null, null).test()
130 .constructor(1, "uri").test();
131 //@formatter:on
132 }
133 }