Debian Codegraph @

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