Debian Codegraph @

src/test/java/ezvcard/property/PlacePropertyTest.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 java.util.ArrayList;
12 import java.util.List;
13
14 import org.junit.Test;
15
16 import ezvcard.util.GeoUri;
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 PlacePropertyTest {
51 private final String text = "New York, NY";
52 private final String uri = "http://newyork.gov";
53 private final GeoUri geoUriObj = new GeoUri.Builder(40.71448, -74.00598).build();
54
55 @Test
56 public void constructors() throws Exception {
57 PlaceProperty property = new PlaceProperty();
58 assertNull(property.getText());
59 assertNull(property.getUri());
60 assertNull(property.getGeoUri());
61 assertNull(property.getLatitude());
62 assertNull(property.getLongitude());
63
64 property = new PlaceProperty("text");
65 assertEquals("text", property.getText());
66 assertNull(property.getUri());
67 assertNull(property.getGeoUri());
68 assertNull(property.getLatitude());
69 assertNull(property.getLongitude());
70
71 property = new PlaceProperty(12.34, 56.78);
72 assertNull(property.getText());
73 assertNull(property.getUri());
74 assertEquals(new GeoUri.Builder(12.34, 56.78).build(), property.getGeoUri());
75 assertEquals(12.34, property.getLatitude(), 0.1);
76 assertEquals(56.78, property.getLongitude(), 0.1);
77 }
78
79 @Test
80 public void set_value() {
81 PlaceProperty property = new PlaceProperty();
82
83 property.setText("text");
84 assertEquals("text", property.getText());
85 assertNull(property.getUri());
86 assertNull(property.getGeoUri());
87 assertNull(property.getLatitude());
88 assertNull(property.getLongitude());
89
90 property.setCoordinates(12.34, 56.78);
91 assertNull(property.getText());
92 assertNull(property.getUri());
93 assertEquals(new GeoUri.Builder(12.34, 56.78).build(), property.getGeoUri());
94 assertEquals(12.34, property.getLatitude(), 0.1);
95 assertEquals(56.78, property.getLongitude(), 0.1);
96
97 property.setUri("uri");
98 assertNull(property.getText());
99 assertEquals("uri", property.getUri());
100 assertNull(property.getGeoUri());
101 assertNull(property.getLatitude());
102 assertNull(property.getLongitude());
103
104 property.setGeoUri(new GeoUri.Builder(12.34, 56.78).coordC(1.0).build());
105 assertNull(property.getText());
106 assertNull(property.getUri());
107 assertEquals(new GeoUri.Builder(12.34, 56.78).coordC(1.0).build(), property.getGeoUri());
108 assertEquals(12.34, property.getLatitude(), 0.1);
109 assertEquals(56.78, property.getLongitude(), 0.1);
110
111 property.setCoordinates(12.34, 56.78);
112 assertNull(property.getText());
113 assertNull(property.getUri());
114 assertEquals(new GeoUri.Builder(12.34, 56.78).build(), property.getGeoUri());
115 assertEquals(12.34, property.getLatitude(), 0.1);
116 assertEquals(56.78, property.getLongitude(), 0.1);
117
118 property.setText("text");
119 assertEquals("text", property.getText());
120 assertNull(property.getUri());
121 assertNull(property.getGeoUri());
122 assertNull(property.getLatitude());
123 assertNull(property.getLongitude());
124 }
125
126 @Test
127 public void validate() {
128 PlaceProperty empty = new PlaceProperty();
129 assertValidate(empty).run(8);
130
131 PlaceProperty withText = new PlaceProperty();
132 withText.setText(text);
133 assertValidate(withText).run();
134
135 PlaceProperty withUri = new PlaceProperty();
136 withUri.setUri(uri);
137 assertValidate(withUri).run();
138
139 PlaceProperty withGeoUri = new PlaceProperty();
140 withGeoUri.setGeoUri(geoUriObj);
141 assertValidate(withGeoUri).run();
142 }
143
144 @Test
145 public void toStringValues() {
146 PlaceProperty property = new PlaceProperty();
147 assertFalse(property.toStringValues().isEmpty());
148 }
149
150 @Test
151 public void copy() {
152 PlaceProperty original = new PlaceProperty();
153 assertCopy(original);
154
155 original = new PlaceProperty("text");
156 assertCopy(original);
157
158 original = new PlaceProperty(12.34, 56.78);
159 assertCopy(original);
160
161 original = new PlaceProperty();
162 original.setUri("uri");
163 assertCopy(original);
164 }
165
166 @Test
167 public void equals() {
168 List<VCardProperty> properties = new ArrayList<>();
169
170 PlaceProperty property = new PlaceProperty();
171 properties.add(property);
172
173 property = new PlaceProperty("text");
174 properties.add(property);
175
176 property = new PlaceProperty("text2");
177 properties.add(property);
178
179 property = new PlaceProperty(12.34, 56.78);
180 properties.add(property);
181
182 property = new PlaceProperty(-12.34, -56.78);
183 properties.add(property);
184
185 property = new PlaceProperty();
186 property.setUri("uri");
187 properties.add(property);
188
189 property = new PlaceProperty();
190 property.setUri("uri2");
191 properties.add(property);
192
193 assertNothingIsEqual(properties);
194
195 //@formatter:off
196 assertEqualsMethod(PlaceProperty.class)
197 .constructor().test()
198 .constructor("text")
199 .constructor(new Class<?>[]{double.class, double.class}, 12.34, 56.78)
200 .constructor().method("setUri", "uri").test();
201 //@formatter:on
202 }
203 }