Debian Codegraph @

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