|
| 1 | +package io.appium.java_client.android.geolocation; |
| 2 | + |
| 3 | +import org.junit.jupiter.api.Test; |
| 4 | + |
| 5 | +import java.util.Map; |
| 6 | + |
| 7 | +import static org.junit.jupiter.api.Assertions.assertEquals; |
| 8 | +import static org.junit.jupiter.api.Assertions.assertThrows; |
| 9 | + |
| 10 | +class AndroidGeoLocationTest { |
| 11 | + |
| 12 | + @Test |
| 13 | + void shouldThrowExceptionWhenLatitudeIsNotSet() { |
| 14 | + var androidGeoLocation = new AndroidGeoLocation().withLongitude(24.105078); |
| 15 | + |
| 16 | + var exception = assertThrows(IllegalArgumentException.class, androidGeoLocation::build); |
| 17 | + |
| 18 | + assertEquals("A valid 'latitude' must be provided", exception.getMessage()); |
| 19 | + } |
| 20 | + |
| 21 | + @Test |
| 22 | + void shouldThrowExceptionWhenLongitudeIsNotSet() { |
| 23 | + var androidGeoLocation = new AndroidGeoLocation().withLatitude(56.946285); |
| 24 | + |
| 25 | + var exception = assertThrows(IllegalArgumentException.class, androidGeoLocation::build); |
| 26 | + |
| 27 | + assertEquals("A valid 'longitude' must be provided", exception.getMessage()); |
| 28 | + } |
| 29 | + |
| 30 | + @Test |
| 31 | + void shodBuildMinimalParameters() { |
| 32 | + var androidGeoLocation = new AndroidGeoLocation() |
| 33 | + .withLongitude(24.105078) |
| 34 | + .withLatitude(56.946285); |
| 35 | + |
| 36 | + assertParameters(androidGeoLocation.build(), 24.105078, 56.946285, null, null, null); |
| 37 | + } |
| 38 | + |
| 39 | + @Test |
| 40 | + void shodBuildFullParameters() { |
| 41 | + var androidGeoLocation = new AndroidGeoLocation() |
| 42 | + .withLongitude(24.105078) |
| 43 | + .withLatitude(56.946285) |
| 44 | + .withAltitude(7) |
| 45 | + .withSpeed(1.5) |
| 46 | + .withSatellites(12); |
| 47 | + |
| 48 | + assertParameters(androidGeoLocation.build(), 24.105078, 56.946285, 7.0, 1.5, 12); |
| 49 | + } |
| 50 | + |
| 51 | + private static void assertParameters(Map<String, ?> actualParams, double longitude, double latitude, |
| 52 | + Double altitude, Double speed, Integer satellites) { |
| 53 | + assertEquals(longitude, actualParams.get("longitude")); |
| 54 | + assertEquals(latitude, actualParams.get("latitude")); |
| 55 | + assertEquals(altitude, actualParams.get("altitude")); |
| 56 | + assertEquals(speed, actualParams.get("speed")); |
| 57 | + assertEquals(satellites, actualParams.get("satellites")); |
| 58 | + } |
| 59 | +} |
0 commit comments