unit tests + mockito
This commit is contained in:
@@ -96,6 +96,7 @@ dependencies {
|
||||
|
||||
// Testing dependencies
|
||||
testCompile 'junit:junit:4.12'
|
||||
testCompile 'org.mockito:mockito-core:1.+'
|
||||
androidTestCompile 'com.android.support.test:runner:0.4'
|
||||
androidTestCompile 'com.android.support.test:rules:0.4'
|
||||
androidTestCompile 'com.android.support.test.espresso:espresso-core:2.2.1'
|
||||
|
||||
@@ -0,0 +1,54 @@
|
||||
import com.mapbox.mapboxgl.geometry.CoordinateRegion;
|
||||
import com.mapbox.mapboxgl.geometry.CoordinateSpan;
|
||||
import com.mapbox.mapboxgl.geometry.LatLng;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
|
||||
public class CoordinateRegionTest {
|
||||
|
||||
@Test
|
||||
public void testSanity() {
|
||||
LatLng center = new LatLng(1.2, 3.4, 5.6);
|
||||
CoordinateSpan span = new CoordinateSpan(9.8, 7.6);
|
||||
CoordinateRegion coordinateRegion = new CoordinateRegion(center, span);
|
||||
assertNotNull("coordinateRegion should not be null", coordinateRegion);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCenterConstructor() {
|
||||
LatLng center = new LatLng(1.2, 3.4, 5.6);
|
||||
CoordinateSpan span = new CoordinateSpan(9.8, 7.6);
|
||||
CoordinateRegion coordinateRegion = new CoordinateRegion(center, span);
|
||||
assertEquals("center should match", coordinateRegion.getCenter(), center);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSpanConstructor() {
|
||||
LatLng center = new LatLng(1.2, 3.4, 5.6);
|
||||
CoordinateSpan span = new CoordinateSpan(9.8, 7.6);
|
||||
CoordinateRegion coordinateRegion = new CoordinateRegion(center, span);
|
||||
assertEquals("span should match", coordinateRegion.getSpan(), span);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCenterMethod() {
|
||||
LatLng center = new LatLng(1.2, 3.4, 5.6);
|
||||
CoordinateSpan span = new CoordinateSpan(9.8, 7.6);
|
||||
CoordinateRegion coordinateRegion = new CoordinateRegion(null, span);
|
||||
coordinateRegion.setCenter(center);
|
||||
assertEquals("center should match", coordinateRegion.getCenter(), center);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSpanMethod() {
|
||||
LatLng center = new LatLng(1.2, 3.4, 5.6);
|
||||
CoordinateSpan span = new CoordinateSpan(9.8, 7.6);
|
||||
CoordinateRegion coordinateRegion = new CoordinateRegion(center, null);
|
||||
coordinateRegion.setSpan(span);
|
||||
assertEquals("span should match", coordinateRegion.getSpan(), span);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -2,14 +2,47 @@ import com.mapbox.mapboxgl.geometry.CoordinateSpan;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
|
||||
public class CoordinateSpanTest {
|
||||
|
||||
private static final double DELTA = 1e-15;
|
||||
|
||||
@Test
|
||||
public void testSanity() {
|
||||
CoordinateSpan coordinateSpan = new CoordinateSpan(0.0, 0.0);
|
||||
assertNotNull("coordinateSpan should not be null", coordinateSpan);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testLatitudeConstructor() {
|
||||
double latitude = 1.23;
|
||||
CoordinateSpan coordinateSpan = new CoordinateSpan(latitude, 0.0);
|
||||
assertEquals("latitude in constructor", coordinateSpan.getLatitudeSpan(), latitude, DELTA);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testLongitudeConstructor() {
|
||||
double longitude = 1.23;
|
||||
CoordinateSpan coordinateSpan = new CoordinateSpan(0.0, longitude);
|
||||
assertEquals("latitude in constructor", coordinateSpan.getLongitudeSpan(), longitude, DELTA);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testLatitudeMethod() {
|
||||
double latitude = 1.23;
|
||||
CoordinateSpan coordinateSpan = new CoordinateSpan(0.0, 0.0);
|
||||
coordinateSpan.setLatitudeSpan(latitude);
|
||||
assertEquals("latitude in constructor", coordinateSpan.getLatitudeSpan(), latitude, DELTA);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testLongitudeMethod() {
|
||||
double longitude = 1.23;
|
||||
CoordinateSpan coordinateSpan = new CoordinateSpan(0.0, 0.0);
|
||||
coordinateSpan.setLongitudeSpan(longitude);
|
||||
assertEquals("latitude in constructor", coordinateSpan.getLongitudeSpan(), longitude, DELTA);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,98 @@
|
||||
import android.location.Location;
|
||||
|
||||
import com.mapbox.mapboxgl.geometry.LatLng;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
public class LatLngTest {
|
||||
|
||||
private static final double DELTA = 1e-15;
|
||||
|
||||
@Test
|
||||
public void testSanity() {
|
||||
LatLng latLng = new LatLng(0.0, 0.0);
|
||||
assertNotNull("latLng should not be null", latLng);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testLatitudeConstructor() {
|
||||
double latitude = 1.2;
|
||||
LatLng latLng = new LatLng(latitude, 3.4);
|
||||
assertEquals("latitude should match", latLng.getLatitude(), latitude, DELTA);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testLongitudeConstructor() {
|
||||
double longitude = 3.4;
|
||||
LatLng latLng = new LatLng(1.2, longitude);
|
||||
assertEquals("longitude should match", latLng.getLongitude(), longitude, DELTA);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAltitudeConstructor() {
|
||||
LatLng latLng1 = new LatLng(1.2, 3.4);
|
||||
assertEquals("altitude default value", latLng1.getAltitude(), 0.0, DELTA);
|
||||
|
||||
double altitude = 5.6;
|
||||
LatLng latLng2 = new LatLng(1.2, 3.4, altitude);
|
||||
assertEquals("altitude default value", latLng2.getAltitude(), altitude, DELTA);
|
||||
}
|
||||
|
||||
/*
|
||||
* A sample test where Mockito is necessary
|
||||
*/
|
||||
|
||||
@Test
|
||||
public void testLocationProvider() {
|
||||
double latitude = 1.2;
|
||||
double longitude = 3.4;
|
||||
double altitude = 5.6;
|
||||
|
||||
// Mock the location class
|
||||
Location locationMocked = mock(Location.class);
|
||||
when(locationMocked.getLatitude()).thenReturn(latitude);
|
||||
when(locationMocked.getLongitude()).thenReturn(longitude);
|
||||
when(locationMocked.getAltitude()).thenReturn(altitude);
|
||||
|
||||
// Test the constructor
|
||||
LatLng latLng = new LatLng(locationMocked);
|
||||
assertEquals("latitude should match", latLng.getLatitude(), latitude, DELTA);
|
||||
assertEquals("longitude should match", latLng.getLongitude(), longitude, DELTA);
|
||||
assertEquals("altitude should match", latLng.getAltitude(), altitude, DELTA);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testHashCode() {
|
||||
double latitude = 1.2;
|
||||
double longitude = 3.4;
|
||||
double altitude = 5.6;
|
||||
LatLng latLng = new LatLng(latitude, longitude, altitude);
|
||||
assertEquals("hash code should match", latLng.hashCode(), -151519232);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testToString() {
|
||||
double latitude = 1.2;
|
||||
double longitude = 3.4;
|
||||
double altitude = 5.6;
|
||||
LatLng latLng = new LatLng(latitude, longitude, altitude);
|
||||
assertEquals("string should match",
|
||||
latLng.toString(),
|
||||
"LatLng [longitude=3.4, latitude=1.2, altitude=5.6]");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDistanceTo() {
|
||||
LatLng latLng1 = new LatLng(0.0, 0.0);
|
||||
LatLng latLng2 = new LatLng(1.0, 1.0);
|
||||
assertEquals("distances should match",
|
||||
latLng1.distanceTo(latLng2),
|
||||
157425.53710839353, DELTA);
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user