| 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 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
|
| 41 |
|
| 42 |
|
| 43 |
|
| 44 |
|
| 45 |
|
| 46 |
|
| 47 |
|
| 48 |
|
| 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 |
|
| 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 |
|
| 202 |
} |
| 203 |
} |