Debian Codegraph @

src/test/java/ezvcard/property/GeoTest.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.util.GeoUri;
14
15 /*
16 Copyright (c) 2012-2023, Michael Angstadt
17 All rights reserved.
18
19 Redistribution and use in source and binary forms, with or without
20 modification, are permitted provided that the following conditions are met:
21
22 1. Redistributions of source code must retain the above copyright notice, this
23 list of conditions and the following disclaimer.
24 2. Redistributions in binary form must reproduce the above copyright notice,
25 this list of conditions and the following disclaimer in the documentation
26 and/or other materials provided with the distribution.
27
28 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
29 ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
30 WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
31 DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
32 ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
33 (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
34 LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
35 ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
36 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
37 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
38
39 The views and conclusions contained in the software and documentation are those
40 of the authors and should not be interpreted as representing official policies,
41 either expressed or implied, of the FreeBSD Project.
42 */
43
44 /**
45 * @author Michael Angstadt
46 */
47 public class GeoTest {
48 @Test
49 public void constructors() throws Exception {
50 Geo property = new Geo(12.34, 56.78);
51 assertEquals(12.34, property.getLatitude(), 0.1);
52 assertEquals(56.78, property.getLongitude(), 0.1);
53 assertEquals(new GeoUri.Builder(12.34, 56.78).build(), property.getGeoUri());
54
55 GeoUri uri = new GeoUri.Builder(12.34, 56.78).build();
56 property = new Geo(uri);
57 assertEquals(12.34, property.getLatitude(), 0.1);
58 assertEquals(56.78, property.getLongitude(), 0.1);
59 assertEquals(uri, property.getGeoUri());
60
61 property = new Geo((GeoUri) null);
62 assertNull(property.getLatitude());
63 assertNull(property.getLongitude());
64 assertNull(property.getGeoUri());
65 }
66
67 @Test
68 public void set_value() {
69 /*
70 * Make sure the GeoUri value does not loose its other properties when
71 * setLatitude or setLongitude is called.
72 */
73
74 Geo property = new Geo(new GeoUri.Builder(12.34, 56.78).coordC(1.0).build());
75
76 property.setLatitude(-12.34);
77 assertEquals(-12.34, property.getLatitude(), 0.1);
78 assertEquals(56.78, property.getLongitude(), 0.1);
79 assertEquals(new GeoUri.Builder(-12.34, 56.78).coordC(1.0).build(), property.getGeoUri());
80
81 property.setLatitude(null);
82 assertEquals(0.0, property.getLatitude(), 0.1);
83 assertEquals(56.78, property.getLongitude(), 0.1);
84 assertEquals(new GeoUri.Builder(null, 56.78).coordC(1.0).build(), property.getGeoUri());
85
86 property.setLongitude(-56.78);
87 assertEquals(0.0, property.getLatitude(), 0.1);
88 assertEquals(-56.78, property.getLongitude(), 0.1);
89 assertEquals(new GeoUri.Builder(null, -56.78).coordC(1.0).build(), property.getGeoUri());
90
91 property.setLongitude(null);
92 assertEquals(0.0, property.getLatitude(), 0.1);
93 assertEquals(0.0, property.getLongitude(), 0.1);
94 assertEquals(new GeoUri.Builder(null, null).coordC(1.0).build(), property.getGeoUri());
95
96 property.setGeoUri(new GeoUri.Builder(12.34, 56.78).coordC(2.0).build());
97 assertEquals(12.34, property.getLatitude(), 0.1);
98 assertEquals(56.78, property.getLongitude(), 0.1);
99 assertEquals(new GeoUri.Builder(12.34, 56.78).coordC(2.0).build(), property.getGeoUri());
100
101 property.setGeoUri(null);
102 property.setLatitude(12.34);
103 assertEquals(12.34, property.getLatitude(), 0.1);
104 assertEquals(0.0, property.getLongitude(), 0.1);
105 assertEquals(new GeoUri.Builder(12.34, null).build(), property.getGeoUri());
106
107 property.setGeoUri(null);
108 property.setLongitude(56.78);
109 assertEquals(0.0, property.getLatitude(), 0.1);
110 assertEquals(56.78, property.getLongitude(), 0.1);
111 assertEquals(new GeoUri.Builder(null, 56.78).build(), property.getGeoUri());
112 }
113
114 @Test
115 public void validate() {
116 Geo empty = new Geo((GeoUri) null);
117 assertValidate(empty).run(13, 14);
118
119 Geo withValue = new Geo(-12.34, 56.78);
120 assertValidate(withValue).run();
121 }
122
123 @Test
124 public void toStringValues() {
125 Geo property = new Geo(12.34, 56.78);
126 assertFalse(property.toStringValues().isEmpty());
127 }
128
129 @Test
130 public void copy() {
131 Geo original = new Geo((GeoUri) null);
132 assertCopy(original);
133
134 GeoUri uri = new GeoUri.Builder(12.34, 56.78).coordC(2.0).build();
135 original = new Geo(uri);
136 assertCopy(original);
137 }
138
139 @Test
140 public void equals() {
141 //@formatter:off
142 assertNothingIsEqual(
143 new Geo((GeoUri) null),
144 new Geo(new GeoUri.Builder(12.34, 56.78).build()),
145 new Geo(new GeoUri.Builder(12.34, -56.78).build())
146 );
147
148 assertEqualsMethod(Geo.class, new GeoUri.Builder(12.34, 56.78).build())
149 .constructor(new Class<?>[]{GeoUri.class}, (GeoUri)null).test()
150 .constructor(new GeoUri.Builder(12.34, 56.78).build()).test();
151 //@formatter:on
152 }
153 }