| 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 |
|
| 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 |
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 |
|
| 71 |
|
| 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 |
|
| 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 |
|
| 152 |
} |
| 153 |
} |