Debian Codegraph @

src/test/java/ezvcard/parameter/PidTest.java

raw symbols SCIP
1 package ezvcard.parameter;
2
3 import static ezvcard.util.TestUtils.assertEqualsAndHash;
4 import static ezvcard.util.TestUtils.assertEqualsMethodEssentials;
5 import static ezvcard.util.TestUtils.assertIntEquals;
6 import static ezvcard.util.TestUtils.assertNothingIsEqual;
7 import static org.junit.Assert.assertEquals;
8 import static org.junit.Assert.assertNull;
9
10 import org.junit.Test;
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
37 /**
38 * @author Michael Angstadt
39 */
40 public class PidTest {
41 @Test(expected = NullPointerException.class)
42 public void null_local_id() {
43 new Pid(null);
44 }
45
46 @Test
47 public void constructor() {
48 Pid pid = new Pid(1);
49 assertIntEquals(1, pid.getLocalId());
50 assertNull(pid.getClientPidMapReference());
51
52 pid = new Pid(1, 2);
53 assertIntEquals(1, pid.getLocalId());
54 assertIntEquals(2, pid.getClientPidMapReference());
55 }
56
57 @Test
58 public void toString_() {
59 Pid pid = new Pid(1, 2);
60 assertEquals("1.2", pid.toString());
61
62 pid = new Pid(1);
63 assertEquals("1", pid.toString());
64 }
65
66 @Test
67 public void valueOf() {
68 Pid expected = new Pid(1, 2);
69 Pid actual = Pid.valueOf("1.2");
70 assertEquals(expected, actual);
71
72 expected = new Pid(1);
73 actual = Pid.valueOf("1.");
74 assertEquals(expected, actual);
75
76 expected = new Pid(1);
77 actual = Pid.valueOf("1");
78 assertEquals(expected, actual);
79 }
80
81 @Test(expected = NumberFormatException.class)
82 public void valueOf_invalid() {
83 Pid.valueOf("1.foo");
84 }
85
86 @Test(expected = NumberFormatException.class)
87 public void valueOf_more_than_one_dot() {
88 Pid.valueOf("1.2.2");
89 }
90
91 @Test
92 public void equals() {
93 Pid pid = new Pid(1, 2);
94 assertEqualsMethodEssentials(pid);
95
96 //@formatter:off
97 assertNothingIsEqual(
98 new Pid(1),
99 new Pid(2),
100 new Pid(1,2),
101 new Pid(2,2),
102 new Pid(2,3)
103 );
104 //@formatter:on
105
106 Pid one = new Pid(1);
107 Pid two = new Pid(1);
108 assertEqualsAndHash(one, two);
109
110 one = new Pid(1, 2);
111 two = new Pid(1, 2);
112 assertEqualsAndHash(one, two);
113 }
114 }